Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] CMake HOW-TOs and Known Issues #5192

Open
HuidaeCho opened this issue Feb 23, 2025 · 17 comments
Open

[WIP] CMake HOW-TOs and Known Issues #5192

HuidaeCho opened this issue Feb 23, 2025 · 17 comments
Labels
Milestone

Comments

@HuidaeCho
Copy link
Member

HuidaeCho commented Feb 23, 2025

Building on Windows

  1. Install Visual Studio Community Edition. Select these two components:
    • MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest)
    • Windows 11 SDK (10.0.26100.0)
  2. Install Git for Windows
  3. Install Miniconda
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe
Miniconda3-latest-Windows-x86_64.exe /S /D=C:\opt\miniconda
C:\opt\miniconda\condabin\conda.bat init
  1. Start Developer Command Prompt for VS 2022
  2. Setup Conda for GRASS build
conda config --add channels conda-forge
conda config --set channel_priority strict
conda create -n grass cmake pkg-config winflexbison proj libgdal pcre fftw openblas pdal wxpython pywin32
  1. Download the source code
cd \opt
git clone git@github.com:OSGeo/grass.git
cd grass
  1. Build GRASS
conda activate grass

mkdir build
cd build
cmake .. -DWITH_OPENGL=OFF > cmake.log 2>&1
msbuild grass.sln > msbuild.log 2>&1
  1. Run GRASS
set GRASS_BUILD=C:\opt\grass\build
set GISBASE=%GRASS_BUILD%\output\lib\grass85
set PATH=%GISBASE%\bin;%GISBASE%\lib;%PATH%
set GISRC=%GISBASE%\demolocation\.grassrc85

g.proj -p

Yes, g.gui doesn't work yet...

Alternatively, rename grass.py to grass85.py just once to avoid a problem with import grass:

ren output\bin\grass.py grass85.py

and

python output\bin\grass85.py output\lib\grass85\demolocation\PERMANENT

Building on Linux

  1. Install Miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod a+x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh -b -u -p ~/opt/miniconda
~/opt/miniconda/bin/conda init
. ~/.bashrc
  1. Setup Conda for GRASS build
conda config --add channels conda-forge
conda config --set channel_priority strict
# TODO: identify more system-independent Conda libraries
conda create -n grass proj libgdal fftw blas libpdal wxpython
  1. Download the source code
cd ~/opt
git clone [email protected]:OSGeo/grass.git
cd grass
  1. Build GRASS
conda activate grass

mkdir build
cd build
# ignore warnings about runtime path (Conda libraries will be picked over system libraries)
# TODO: -DCMAKE_PREFIX_PATH may not be needed with Conda CMake; need to test this
cmake .. -DCMAKE_PREFIX_PATH=$HOME/opt/miniconda/envs/grass &> cmake.log
make -j`nproc` &> make.log
  1. Run GRASS
./output/bin/grass
@HuidaeCho
Copy link
Member Author

HuidaeCho commented Feb 23, 2025

Known Issues for Windows

  • Doesn't build -DWITH_OPENGL=ON (default)
  • Getting many of these CMake warnings
CMake Warning (dev) at gui/wxpython/docs/CMakeLists.txt:14 (add_custom_command):
  The following keywords are not supported when using
  add_custom_command(TARGET): DEPENDS.

  Policy CMP0175 is not set: add_custom_command() rejects invalid arguments.    
  Run "cmake --help-policy CMP0175" for policy details.  Use the cmake_policy   
  command to set the policy and suppress this warning.
This warning is for project developers.  Use -Wno-dev to suppress it.
  • SQLite driver not working
v.db.select country_boundaries
dbmi: db_open_database() not implemented
dbmi: db_open_database() not implemented
WARNING: Unable to open database
         <C:\Users\hcho\Documents\grassdata/world_latlong_wgs84/PERMANENT/sqlite/sqlite.db>
         by driver <sqlite>
ERROR: Unable to open database
       <C:\Users\hcho\Documents\grassdata/world_latlong_wgs84/PERMANENT/sqlite/sqlite.db>
       by driver <sqlite>

@echoix
Copy link
Member

echoix commented Feb 23, 2025

On CI, I think there's a problem of building the ctypes grass.lib.vector: Multiple tests fail when trying to use "Vect_get_num_areas"

AttributeError: module 'grass.lib.vector' has no attribute 'Vect_get_num_areas'

(see for example https://github.com/OSGeo/grass/actions/runs/13475973886/job/37657021926#step:15:3753)
Maybe that's why all the long temporal tests end up failing and get skipped, thus taking 22 min total

@echoix
Copy link
Member

echoix commented Feb 23, 2025

Locally, on a ubuntu 22.04 container (my dev environment for vscode, works well), I end up not being able to build, as there's a linking error for 4 bz_.... symbols.
=> I was reproducing it non stop even when cleaning+deleting the build folder before supper, but now I can't recreate it. And I restarted my IDE so I can't copy the output. The only thing different now is that when creating one of the PRs, I ran git clean -d -f -x so it might have removed some files not cleaned with make libsclean clean distclean from previous autotools-based builds..

When building with Unix makefiles, not using multiple jobs, I get an error for "#include <ogr_api.h>". How can I make sure I have that enabled too when building with autotools version? (As that dev environment worked for a while even when cleaning and all, and I never saw that yet)
cmake cache file: CMakeCache.txt

[ 43%] Building C object misc/CMakeFiles/m.nviz.image.dir/m.nviz.image/main.c.o
cd /home/vscode/grass/build/misc && /usr/bin/cc -DGRASS_VERSION_DATE=\"2025\" -DPACKAGE=\"grassmods\" -I/home/vscode/grass/build/output/lib/grass85/include -I/opt/local/include -I/home/vscode/grass/misc/m.nviz.image -I/home/vscode/grass/lib/gis -I/home/vscode/grass/lib/ogsf -I/home/vscode/grass/lib/nviz -I/home/vscode/grass/lib/vector/Vlib -I/home/vscode/grass/lib/db/dbmi_base -I/home/vscode/grass/lib/db/dbmi_client -I/home/vscode/grass/lib/db/./dbmi_base -I/home/vscode/grass/lib/db/dbmi_driver -DGRASS_CMAKE_BUILD=1  -std=gnu11 -MD -MT misc/CMakeFiles/m.nviz.image.dir/m.nviz.image/main.c.o -MF CMakeFiles/m.nviz.image.dir/m.nviz.image/main.c.o.d -o CMakeFiles/m.nviz.image.dir/m.nviz.image/main.c.o -c /home/vscode/grass/misc/m.nviz.image/main.c
[ 43%] Building C object misc/CMakeFiles/m.nviz.image.dir/m.nviz.image/surface.c.o
cd /home/vscode/grass/build/misc && /usr/bin/cc -DGRASS_VERSION_DATE=\"2025\" -DPACKAGE=\"grassmods\" -I/home/vscode/grass/build/output/lib/grass85/include -I/opt/local/include -I/home/vscode/grass/misc/m.nviz.image -I/home/vscode/grass/lib/gis -I/home/vscode/grass/lib/ogsf -I/home/vscode/grass/lib/nviz -I/home/vscode/grass/lib/vector/Vlib -I/home/vscode/grass/lib/db/dbmi_base -I/home/vscode/grass/lib/db/dbmi_client -I/home/vscode/grass/lib/db/./dbmi_base -I/home/vscode/grass/lib/db/dbmi_driver -DGRASS_CMAKE_BUILD=1  -std=gnu11 -MD -MT misc/CMakeFiles/m.nviz.image.dir/m.nviz.image/surface.c.o -MF CMakeFiles/m.nviz.image.dir/m.nviz.image/surface.c.o.d -o CMakeFiles/m.nviz.image.dir/m.nviz.image/surface.c.o -c /home/vscode/grass/misc/m.nviz.image/surface.c
[ 43%] Building C object misc/CMakeFiles/m.nviz.image.dir/m.nviz.image/vector.c.o
cd /home/vscode/grass/build/misc && /usr/bin/cc -DGRASS_VERSION_DATE=\"2025\" -DPACKAGE=\"grassmods\" -I/home/vscode/grass/build/output/lib/grass85/include -I/opt/local/include -I/home/vscode/grass/misc/m.nviz.image -I/home/vscode/grass/lib/gis -I/home/vscode/grass/lib/ogsf -I/home/vscode/grass/lib/nviz -I/home/vscode/grass/lib/vector/Vlib -I/home/vscode/grass/lib/db/dbmi_base -I/home/vscode/grass/lib/db/dbmi_client -I/home/vscode/grass/lib/db/./dbmi_base -I/home/vscode/grass/lib/db/dbmi_driver -DGRASS_CMAKE_BUILD=1  -std=gnu11 -MD -MT misc/CMakeFiles/m.nviz.image.dir/m.nviz.image/vector.c.o -MF CMakeFiles/m.nviz.image.dir/m.nviz.image/vector.c.o.d -o CMakeFiles/m.nviz.image.dir/m.nviz.image/vector.c.o -c /home/vscode/grass/misc/m.nviz.image/vector.c
In file included from /home/vscode/grass/build/output/lib/grass85/include/grass/vect/digit.h:3,
                 from /home/vscode/grass/build/output/lib/grass85/include/grass/vector.h:4,
                 from /home/vscode/grass/misc/m.nviz.image/vector.c:18:
/home/vscode/grass/build/output/lib/grass85/include/grass/vect/dig_structs.h:27:10: fatal error: ogr_api.h: No such file or directory
   27 | #include <ogr_api.h>
      |          ^~~~~~~~~~~
compilation terminated.
gmake[2]: *** [misc/CMakeFiles/m.nviz.image.dir/build.make:135: misc/CMakeFiles/m.nviz.image.dir/m.nviz.image/vector.c.o] Error 1
gmake[2]: Leaving directory '/home/vscode/grass/build'
gmake[1]: *** [CMakeFiles/Makefile2:12501: misc/CMakeFiles/m.nviz.image.dir/all] Error 2
gmake[1]: Leaving directory '/home/vscode/grass/build'
gmake: *** [Makefile:146: all] Error 2

With -j$(nproc), it happens at the very end.

Edit: is that because I absolutely need the extra -D arguments like the CI to specify includes? The find_packages don't work enough? -> Seems like it

@echoix
Copy link
Member

echoix commented Feb 23, 2025

With the following commands on cmake 3.31.4:

cmake  -B build -S .  --fresh  ${CMAKE_OPTIONS} -G Ninja \
                   -DCMAKE_C_FLAGS="-I/usr/include -I/usr/include/gdal" \
                   -DCMAKE_CXX_FLAGS="-I/usr/include -I/usr/include/gdal" \
                   -DCMAKE_INSTALL_PREFIX=$HOME/install -DWITH_NLS=OFF -DWITH_GUI=OFF -DWITH_DOCS=OFF
cmake --build build --verbose -- -t missingdeps

We see what Ninja considers missing dependencies:

vscode ➜ ~/grass (cmake-gitignore) $ cmake --build build --verbose -- -t missingdeps
Change Dir: '/home/vscode/grass/build'

Run Build Command(s): /usr/local/python/current/bin/ninja -v -t missingdeps
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/chouse.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/chousv.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/cmattr.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/cmcpy.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/cminv.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/cmmul.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/cmmult.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/cmprt.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/csolv.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/cvmul.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/eigen.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/eigval.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/evmax.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/hconj.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/heigval.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/heigvec.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/hevmax.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/hmgen.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/house.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/housev.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/minv.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/mmul.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/ortho.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/psinv.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/qrbdi.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/qrbdu1.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/qrbdv.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/qrecvc.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/qreval.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/solv.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/solvps.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/sv2u1v.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/sv2uv.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/sv2val.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/svdu1v.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/svduv.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/svdval.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/trncm.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/unitary.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/utrncm.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Missing dep: lib/CMakeFiles/grass_ccmath.dir/external/ccmath/utrnhm.c.o uses /home/vscode/grass/lib/external/ccmath/ccmath.h (generated by phony)
Processed 4212 nodes.
Error: There are 41 missing dependency paths.
41 targets had depfile dependencies on 1 distinct generated inputs (from 1 rules)  without a non-depfile dep path to the generator.
There might be build flakiness if any of the targets listed above are built alone, or not late enough, in a clean output directory.

@echoix
Copy link
Member

echoix commented Feb 23, 2025

With CMake 3.31.4 and the following command (deleting the build directory beforehand):

cmake  -B build -S .  ${CMAKE_OPTIONS} -G Ninja    --fresh
cmake --build build --verbose -- -t missingdeps

I get:

$ cmake --build build --verbose -- -t missingdeps
Change Dir: '/home/vscode/grass/build'

Run Build Command(s): /usr/local/python/current/bin/ninja -v -t missingdeps
ninja: error: build.ninja:53457: multiple rules generate output/lib/grass85/locale/ar/LC_MESSAGES

Does not happen when adding -DWITH_NLS=OFF

@echoix
Copy link
Member

echoix commented Feb 23, 2025

  • Getting many of these CMake warnings
CMake Warning (dev) at gui/wxpython/docs/CMakeLists.txt:14 (add_custom_command):
  The following keywords are not supported when using
  add_custom_command(TARGET): DEPENDS.

  Policy CMP0175 is not set: add_custom_command() rejects invalid arguments.    
  Run "cmake --help-policy CMP0175" for policy details.  Use the cmake_policy   
  command to set the policy and suppress this warning.
This warning is for project developers.  Use -Wno-dev to suppress it.

I see them on non-Windows, I suppose it is related to the arguments passed.

For example:

Shows multiple warnings:

cmake  -B build -S .  ${CMAKE_OPTIONS} -G Ninja                   -DCMAKE_C_FLAGS="-I/usr/include -I/usr/include/gdal"                   -DCMAKE_CXX_FLAGS="-I/usr/include -I/usr/include/gdal"                   -DCMAKE_INSTALL_PREFIX=$HOME/install 

Doesn't show these warnings: (git clean -d -f -x in between each):

cmake  -B build -S .  ${CMAKE_OPTIONS} -G Ninja \
                  -DCMAKE_C_FLAGS="-I/usr/include -I/usr/include/gdal" \
                  -DCMAKE_CXX_FLAGS="-I/usr/include -I/usr/include/gdal" \
                  -DCMAKE_INSTALL_PREFIX=$HOME/install \
                  -DWITH_GUI=OFF 
cmake  -B build -S .  ${CMAKE_OPTIONS} -G Ninja \
                  -DCMAKE_C_FLAGS="-I/usr/include -I/usr/include/gdal" \
                  -DCMAKE_CXX_FLAGS="-I/usr/include -I/usr/include/gdal" \
                  -DCMAKE_INSTALL_PREFIX=$HOME/install \
                  -DWITH_NLS=OFF -DWITH_GUI=OFF
cmake  -B build -S .  ${CMAKE_OPTIONS} -G Ninja \
                  -DCMAKE_C_FLAGS="-I/usr/include -I/usr/include/gdal" \
                  -DCMAKE_CXX_FLAGS="-I/usr/include -I/usr/include/gdal" \
                  -DCMAKE_INSTALL_PREFIX=$HOME/install \
                  -DWITH_NLS=OFF  -DWITH_DOCS=OFF
cmake  -B build -S .  ${CMAKE_OPTIONS} -G Ninja \
                  -DCMAKE_C_FLAGS="-I/usr/include -I/usr/include/gdal" \
                  -DCMAKE_CXX_FLAGS="-I/usr/include -I/usr/include/gdal" \
                  -DCMAKE_INSTALL_PREFIX=$HOME/install \
                  -DWITH_GUI=OFF -DWITH_DOCS=OFF 
cmake  -B build -S .  ${CMAKE_OPTIONS} -G Ninja \
                  -DCMAKE_C_FLAGS="-I/usr/include -I/usr/include/gdal" \
                  -DCMAKE_CXX_FLAGS="-I/usr/include -I/usr/include/gdal" \
                  -DCMAKE_INSTALL_PREFIX=$HOME/install \
                  -DWITH_NLS=OFF -DWITH_GUI=OFF -DWITH_DOCS=OFF 

So, I must not have the three arguments for it to show (tried multiple times with same results)

@neteler neteler added this to the 8.5.0 milestone Feb 23, 2025
@neteler neteler added the docs label Feb 23, 2025
@hellik
Copy link
Member

hellik commented Feb 23, 2025

now tested the how-to locally on windows.

some minor comments to the how-to:

while at Start Developer Command Prompt for VS 2022 :

git clone [email protected]:OSGeo/grass.git doesn't work because the Developer Command Prompt starts in C:\Program Files\Microsoft Visual Studio\2022\Community and there is no write permission on this protected folder. you have to change to a writeable folder e.g. C:\opt to proceed.

but then, winGRASS builds. :-)

anything I should look at in the build logs?

@hellik
Copy link
Member

hellik commented Feb 23, 2025

getting many warnings in a windows test build, like, e.g.

CMake Warning (dev) at cmake/modules/build_gui_in_subdir.cmake:90 (add_custom_command):
  COMMENT requires exactly one argument, but multiple values or COMMENT
  keywords have been given.

  Policy CMP0175 is not set: add_custom_command() rejects invalid arguments.
  Run "cmake --help-policy CMP0175" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.
Call Stack (most recent call first):
  gui/wxpython/CMakeLists.txt:50 (build_gui_in_subdir)
This warning is for project developers.  Use -Wno-dev to suppress it.

@hellik
Copy link
Member

hellik commented Feb 23, 2025

find attached warnings and errors mentioned in msbuild.log; build in a win 11 box

error_list_windows11.txt

warning_windows11.txt

@HuidaeCho
Copy link
Member Author

now tested the how-to locally on windows.

some minor comments to the how-to:

while at Start Developer Command Prompt for VS 2022 :

git clone [email protected]:OSGeo/grass.git doesn't work because the Developer Command Prompt starts in C:\Program Files\Microsoft Visual Studio\2022\Community and there is no write permission on this protected folder. you have to change to a writeable folder e.g. C:\opt to proceed.

but then, winGRASS builds. :-)

anything I should look at in the build logs?

Thanks for testing! Good catch! I'll update the HOW-TO. Please test binaries. Do they work properly?

@HuidaeCho
Copy link
Member Author

getting many warnings in a windows test build, like, e.g.

CMake Warning (dev) at cmake/modules/build_gui_in_subdir.cmake:90 (add_custom_command):
  COMMENT requires exactly one argument, but multiple values or COMMENT
  keywords have been given.

  Policy CMP0175 is not set: add_custom_command() rejects invalid arguments.
  Run "cmake --help-policy CMP0175" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.
Call Stack (most recent call first):
  gui/wxpython/CMakeLists.txt:50 (build_gui_in_subdir)
This warning is for project developers.  Use -Wno-dev to suppress it.

Yes, that's known and documented above.

@hellik
Copy link
Member

hellik commented Feb 23, 2025

Please test binaries. Do they work properly?

how can I test the binaries?

@HuidaeCho
Copy link
Member Author

HuidaeCho commented Feb 24, 2025

Please test binaries. Do they work properly?

how can I test the binaries?

For now, g.gui doesn't work, but you can still run binaries from cmd using this grass.bat:

set GRASS_BUILD=C:\opt\grass\build
set GISBASE=%GRASS_BUILD%\output\lib\grass85
set PATH=%GISBASE%\bin;%GISBASE%\lib;%PATH%
set GISRC=%GISBASE%\demolocation\.grassrc85

Run this grass.bat and you'll be in the demo location.

Another way is

ren output\bin\grass.py grass85.py

only once and

python output\bin\grass85.py output\lib\grass85\demolocation\PERMANENT

@echoix
Copy link
Member

echoix commented Feb 25, 2025

Yesterday I tried building with CMake on my install of Visual Studio 2022, my first time directly with Windows.

I didn't want to use Conda, I wanted to see if it was possible to use the dependencies and dev dependencies from OSGeo4W, to see how close it was to have OSGeo4W change the packaging method. TLDR: not all of our dependencies are available or have dev-dependencies downloadable from OSGeo4W.

First of all, I have a PR (still to create) with some .gitignore changes for the default build directories used by Visual Studio with CMake projects.

I didn't manage to successfully complete a whole build yet, but got close to having a complete build. Obviously I was able to end up with a successful configuration step, but it took a while. Since Visual Studio now suggests to use CMakePresets.json, directly supported by CMake 3.19+, instead of their custom solution, I directly edited the base windows preset with extra config needed. I was then able to not enter any arguments on the command line and only use the IDE.
https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html

Most of the config to use OSGeo4W deps was to port the equivalent of the what is done in the "cmakeenv" function, in regards to the paths added: https://github.com/jef-n/OSGeo4W/blob/e5c6a01be8abfa6265e85de7cfbe04eb1cfb23b9/scripts/build-helpers#L311-L350
As I note below, it was missing the apps folder, because gdal's CMake config files (.cmake) are there instead of with the other ones.

I struggled quite a bit with Cairo, and the FindCairo.cmake in our repo. It always failed whilst I had all the files and paths there, and even added more variables doing the job of the FindCairo, but it still unset them in order to fail. I replaced that file with a more recent version on upstream WebKit, rewritten in 2020 https://github.com/WebKit/WebKit/blob/bc82205e7ef89756a44ccf963003c2cb439efe06/Source/cmake/FindCairo.cmake. With this, I had more luck and was able to continue. I had to change places to use the imported target Cairo::Cairo instead of a plain normal CAIRO target though, which is not a bad thing.

I had to remove/rename the FindGDAL and use the method written in https://gdal.org/en/stable/development/cmake.html

find_package(GDAL CONFIG REQUIRED)

And also had to change to use the imported target GDAL::GDAL like explained in GDAL's doc. But today I wonder if all that was really needed for GDAL, as what I think made it work, was to add the $env{OSGEO4W_ROOT}\apps\gdal or $env{OSGEO4W_ROOT}\apps (I don't remember exactly) to the CMAKE_PREFIX_PATH, so maybe only that was enough. But anyways, that apps folder is also there that the gdal_share_dir is (inside the gdal subdirectory).

I also had to remove/rename the FindSqlite.cmake, to use https://cmake.org/cmake/help/latest/module/FindSQLite3.html. So that means to use plain find_package(SQLite3 REQUIRED), and it creates the imported target SQLite::SQLite3. This means to change the SQLITE targets with the imported target. It's also different because the cmake cache variables are upper and lower case + 3 as opposed to only uppercase.

For flex + bison, I started from the solution for bison noted here
https://discourse.cmake.org/t/how-i-get-bison-flex-on-windows/13505 and here https://stackoverflow.com/a/79394803

if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
    include(FetchContent)
    FetchContent_Declare(download_bison
        URL "https://github.com/lexxmark/winflexbison/releases/download/v2.5.25/win_flex_bison-2.5.25.zip"
        URL_MD5 "720226b1befe7033fb3ecc98f5ffd425"
        DOWNLOAD_EXTRACT_TIMESTAMP FALSE)
    FetchContent_MakeAvailable(download_bison)
    set(BISON_ROOT "${download_bison_SOURCE_DIR}")
    message(STATUS "BISON_ROOT=${BISON_ROOT}")
endif()
find_package(BISON REQUIRED)

but had to add FLEX_ROOT to the same value as BISON_ROOT (they are downloaded at the same place).
I also saw a similar and improved version used for ports in vcpkg, based on https://learn.microsoft.com/en-us/vcpkg/maintainers/functions/vcpkg_find_acquire_program.
It is here: https://github.com/microsoft/vcpkg/blob/9a7a33fee37f3cbd9332fc2f83593335b1196057/scripts/cmake/vcpkg_find_acquire_program(BISON).cmake and https://github.com/microsoft/vcpkg/blob/9a7a33fee37f3cbd9332fc2f83593335b1196057/scripts/cmake/vcpkg_find_acquire_program(FLEX).cmake

Finally, I wasn't able to completely use only OSGeo4W deps. I had to use vcpkg for fftw, pcre, and for the fun pkgconf to allow the configure step to use package config (it seemed to work without). These were built once when configuring (or after deleting the build folder) and it takes less than a minute for all of it.

When building, I tried "Ninja" and "Visual Studio 2022" generators. Both I had some errors of "file or directory not found" of some steps using a bat file for multiple commands. I also saw some weird linking errors with ninja where it was trying to link x86 system libs with a x64 build, and didn't work, but didn't find the cause. With Visual Studio generator, it seemed to have less errors (build more), but was slower

@hellik
Copy link
Member

hellik commented Feb 25, 2025

I didn't want to use Conda, I wanted to see if it was possible to use the dependencies and dev dependencies from OSGeo4W, to see how close it was to have OSGeo4W change the packaging method.

Thanks for the effort!

Maybe we should drop a message in the osgeo4w mailing list to keep them updated.

@wenzeslaus
Copy link
Member

I'm getting many test failing on PR #2392 in the CMake workflow, but I don't see any relation to the PR (PR is raster mask, failing tests are vector-related). Please, let me know if you have any suggestions. https://github.com/OSGeo/grass/actions/runs/13507678405/job/37740965302?pr=2392

@echoix
Copy link
Member

echoix commented Feb 25, 2025

I'm getting many test failing on PR #2392 in the CMake workflow, but I don't see any relation to the PR (PR is raster mask, failing tests are vector-related). Please, let me know if you have any suggestions. https://github.com/OSGeo/grass/actions/runs/13507678405/job/37740965302?pr=2392

They were failing since the initial CMake PR was merged. I noted it in #5192 (comment), and that's probably why the tests take 1/3 of the expected time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants