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

build: Add CMake build #3621

Draft
wants to merge 158 commits into
base: main
Choose a base branch
from
Draft

build: Add CMake build #3621

wants to merge 158 commits into from

Conversation

HuidaeCho
Copy link
Member

@HuidaeCho HuidaeCho commented Apr 18, 2024

This PR replaces #3021. Branched from https://github.com/nilason/grass/tree/cmake_build_work. Thanks @nilason!

Current status: I can compile the entire gisbase using CMake 3.29.1 and GCC 13.2.0. Running grass directly from build/gisbase works fine.

For my records, message from message(WIN32=${WIN32}, MSVC=${MSVC}, MSYS=${MSYS}, MINGW=${MINGW}) on Windows (all from cmd in ssh):

CMake variables:

TODOs:

  • Windows
  • macOS
  • locale
  • addon support
  • ...

rkanavath and others added 30 commits June 6, 2023 09:40
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669989265 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669989193 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669989189 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669989180 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669988019 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669987997 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669987899 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669986420 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669986410 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669985337 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669984062 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669984050 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669984037 +0100

parent 464ffca
author Rashad Kanavath <mohammedrashadkm@gmail.com> 1497210739 +0200
committer Markus Neteler <neteler@gmail.com> 1669984013 +0100

inital work on grass cmake build

wip: cmake fixes

add find iconv script

fix blas error wrong target added

link with dl lib on linux

disable some modules (wip)

search whatever is fftw's inlcude dir

driver lib depends on iconv

fftw in required package

build fftw modules

add python libs

test with py3

install sqlfiles to etc/sql

install lock, clean_temp, echo to ./etc/

install libs

link with dl lib

cleanup cmake code

fix python script & lib install dirs

fixed gisbase for grass startup script

install modules to bin

add PNG as dependency to r.out.png

install __init__.py

wrong install dir for python api

install with rpath to avoid LD_LIBRARY_PATH

whitespace fixes

MSVC: check for _WIN32 to use msvc and mingw32

MSVC: disable some programs temporarily

update cmake scripts to manage thirdparty libs

disable X11 on windows

update generation of config.h

fix list of cmake depends

msvc compile fixes

use INIFINITY rather than gcc only division by zero

ignore visual studio, cmake files

use INFINITY rather than divide by zero

use _WIN32 for mingw32 and msvc

add ssize_t for msvc

msvc add _USE_MATH_DEFINES an d export dll

keep check for long long int in cache

include driver/init.c when building display drivers

use _WIN32 to build msvc and mingw32

update cmake for lib/db

link with libm only on unix

msvc: skip chmod on windows msvc

use INFINITY rather than diivide by zero

add msvc specific headers: unistd.h, dirent.h

grass moved to git... So follow that in cmake.

fix check for HAVE_LONG_LONG

include math.h only on msvc. To be discussed

void* arithmetic (GCC extension) is not allowed in msvc

disable d.mon, d.font on msvc. TBD

missing O_ACCMODE on msvc

Add unistd.h on windows

Source copied from http://stackoverflow.com/a/826027

dbmi_base: add dirent.h and dirent.c for msvc

use macro INFINITY rather than GCC divide by zero

MSVC: fix missing strings.h

use math defines on msvc

update find package of fftw

added required defines into parent scope

update setting of HAVE_* defines. 1/n

use cmake target check if possible

add odbc target on windows

update values in generated config.h

reorganize cmake option defaults, cmake flags, macros

cmake c and cxx flags include _CRT_SECURE_NO_WARNINGS to avoid a lot msdn warnings
check_target macro is a helper to reduce number of lines in include/CMakeLists.txt

simlib: min, max are already available

Find which C standard library does not provide them
And if there is one, see if grass support that compiler/platform combination
To be discussed

CMake: reorganize cmake functions, macros, find_scripts (Like a Pro)

make_script_in_dir is renamed to build_script_in_subdir

I still don't the naming of macro is clear.
One without knowledge of CMake, AutoMake or any
other build scripting  experience must be able to deduct
what is the macro/functions.

Even if there will be a header comment with 'PURPOSE' field.

fix define used in lib/rst/interp_float

fix tools/timer build

add gettimeofday windowss implemenation from postgresql

CMake: reorganize cmake functions (2)

MSVC: copy UINT64CONST(x) from postgresql

WIP: disable pyc generation with g.parser on msvc

fix ccmath complex struct for msvc

take out GCC'sim and stick to C standard

copy external/ccmath/ccmath.h to include/grass/ccmath_grass.h

CMake: enable cmake export all symbols on for shared libs

CMake: build lib/python on MSVC

fix ctypesgen.cmake
reorg cmake functions used by python
add new cmake function to copy_python_files and compile

MSVC: include sys/time.h if available or time.h

CMake: remove debug trace

CMake: minor cleanup

CMake: make gui/images

CMake: fix run_grass of locale_strings and ctypesgen

CMake: link with postgres is optional

gid_t, uid_t, pid_t exists on *nix

use find_library_suffix to switch between debug and rest

avoid touch  .stamp files and depend on generated pyc file

CMake: update definiition of HAVE_PROJ_H

include winsock.h only on msvc

CMake: remove annoying logs

for fix TODO for g.version

CMake: depend on pyc file not on a new .stamp file

CMake: fix syntax error

CMake: fix sqlite include dir variable

CMake: detect version of proj4 before activating defines

MSVC: avoid pulling min max on windows

CMake: update list of enabled modules

TODO r.watershed, fix cmake proj4 library varname

Revert "simlib: min, max are already available"

This reverts commit ab2b961.

CMake: update proj library variables (remove suffix 4)

use macro INFINITY

MSVC: fix gisinit initialized flag

export initialized using dllexport when building.
export macros has been generated by CMake's GenerateExportHeader.
cmake calls this for all libraries in build_module function.

There is a change in initialized variable decl on msvc and rest of compilers.
This point has to be discussed with other devs

MSVC: fix min, max macro stuff

update TODO, list of modules not built by cmake

CMake: update find scripts to find debug then release

update list of options.
WITH_PYTHON addded to build python bindings (default is OFF)

CMake: zlib is check with cmake target

demolocation is configured in lib/init/CMakeLists.txt

CMake: generate grass.py and grass.sh scripts (build tree)

CMake: fix startup script generation (install tree)

fix generation of startup scripts

fix g.list building 1/2

MSVC: missing regex, use PCRE (wip)

lib/init: fix startup script on linux

fix input configure_file

activate building g.remove on msvc

add cmake messages for lib/init/

include sys/time.h if not on msvc.

As we don't include grass/config.h we cannot simply check against
HAVE_SYS_TIME_H

install proj data files

geotiff_csv only required in windows

check this with devs

wip: add compile defs via interface library

fix g.version, grass_gproj with proj6

create startup shell scripts in bin

fix startup script

MSVC: configure run_grass.bat, run_python.bat

generate html docs

fix copy_python_file (used in gui/wxpython, lib/python)

build all gui/wxpython modules

wrapper scripts to build html docs

skip html-description for g.parser

update msvc target properties

fix install directory for running from binary tree

install tools for buildtree and installtree

fix build docs using cmake POST_BUILD

update mkhtml.py for cmake

copy header to binary directory using add_custom_command

install extra files in lib/gis using post_build

add copy_header as depdendency to grass_datetime

first install tools directory

find cairo debug and then release libs

add POST_BUILD target for documentation only if WITH_DOCS

build gui/wxpython, fix html description generation

MSVC: uninitialized variable

CMake: update to work with autoconf and cmake

CMake: install et copy gui/images gui/icons

CMake: fix grass version date

CMake: fix building gui (python files, docs, html)

fix dist include dir name

build docs only if requested

fix typo

fix cmake syntax errors

cmake linux fixes

check for _WIN32 define to work with msvc

fix newline at end of file

WIP: update helper cmake scripts

update copy_header target

use gisbase as dist directory for build tree

cmake: fix build for db/drivers

ignore __pycache__ directory when scanning for .py files

wip: use a gisbase as dist directory

WIP: temporary fix for find_library output variable

CMake: move wxpython cmake codes to gui/wxpython

raise ScriptError

wip wip build docs

minor cleanup

install html docs for driver db

update building html docs (wip)

add missing dependencies for v.lrs

update building python modules (wip)

use target property to check if running python script (docs)

cleanup cmake helper functions (exe, libs, python, docs)

copy strings.h and unistd.h on msvc

python files (target) depend only grass.script if building docs

fix build docs for windows and linux (wip)

seperate list of g.gui.* modules

try to make generic build docs (wip)

build docs html for not win32 (wip)

fix cmake syntax error

update pgm extension for running html description

remove temp files after docs are finished

CMake: fix IN_LIST syntax

ficx cmake syntax error

fix again linux html description for python with a main script

wip: include from config build is breaking msvc

msvc: disable db drivers (wip)

add test.raster3d.lib into NO_HTML_DESCR_TARGETS

CMake: missing endif()

x extension on running html descr

copy r.in.wms directory to etc/

fix building py modules

add grass dll directory to path windows grass.bat

debug linux build failures

cmake missing endif

set main script file only for those selected modules

cmake: fix python docs for linux and windows

create scripts directory in gisbase

cmake debug message

add missing include

add cmake find scripts for liblas, netcdf, postgresql

update proj4 detection to support 4.x, 5.x , 6.x versions

update cmake functions to build grass modules

add proj4 version defines (support 5.x+)

add options for v.in.dwg and liblas modules

activate build of modules deactivated

detecting of new 3rdd party libraries

fix i.landsat.acca on msvc

add dll export macro for iostream, dspf, calc

fix r.terraflow on msvc

use _WIN32 rather than __MINGW32__ for msvc

use infinity macro to build on msvc

missing include on msvc

copy VERSIONUMBER and license to gisbase/etc

support for multiple proj4 version

update building lib/python (except ctypes)

use INFINITY macro to work with msvc

fix building gui/wxpython/xml

use approach with cmake env command for cross platform build

void* arithmetic is not allowed in msvc

To be discussed

copy __init__.py for python/grass/

fix wrong cmake varible used

copy init py to etc/python/grass/

db/drviers: odbc, sqlite, dbf,  ogr, postgresql

check for PQCmdTuples in postgresql

add defines to be posix conformat on msvc

bring in testing using ctest (wip)

improve proj4 detection

Signed-off-by: Rashad Kanavath <mohammedrashadkm@gmail.com>

keep proj4 version string in cache (very useful later)

find optional packages quietly

use PRIMARY_DEPENDS option in build_module

generate wxpython menu xml stuff after building all executables

ogsf and nviz depends on grass_raster

update gui/wxpython build

add missing modules to build

missing v.clip

install html file is exists

cmake cleanup

reorder dependencies of gui/wxpython modules

avoid breakage in autconf build

missing file copy

fix mkhtml doc building, exe, lib, python, gui

fix find scripts on windows

fix always out of date for custom targets

fix missing optional dependds to grass gis library

fix missing math.h include

wrong path used under cmake binary directory

keep autoconf build  conflict with cmake

.bat files must be in scripts/

fix installation of gui/images, gui/icons

Revert "install html file is exists"

This reverts commit 9e83f6f.

Apply suggestions from code review

trivial changes (comment style) applied

moved tools/ -> utils/

sync to main

sync to main

fix indentation

remove trailing white space

remove trailing white space

revert C related INFINITY/NAN changes (taken care of in OSGeo#2681)
Attempt to add a CI workflow
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
@nilason
Copy link
Contributor

nilason commented Apr 23, 2024

Now I expect the cmake runner to succeed...

@HuidaeCho
Copy link
Member Author

Now I expect the cmake runner to succeed...

Yeah! Finally!

CMake / build-cmake (pull_request) Successful in 4m

@echoix
Copy link
Member

echoix commented Apr 23, 2024

Oh yeah, 2min52 build time. Is it with a cache hit or without cache?

@nilason
Copy link
Contributor

nilason commented Apr 23, 2024

Now only a "small" detail remains, I believe, before bringing this into review mode. Installation.

Traditionally, the Autotools installation looks like:

└── usr
    └── local
        ├── bin
        │   └── grass
        └── grass84
            ├── AUTHORS
            ├── CHANGES
            ├── CITING
            ├── COPYING
            ├── GPL.TXT
            ├── INSTALL.md
            ├── REQUIREMENTS.md
            ├── bin
            ├── contributors.csv
            ├── contributors_extra.csv
            ├── demolocation
            ├── docs
            ├── driver
            ├── etc
            ├── fonts
            ├── gui
            ├── include
            ├── lib
            ├── locale
            ├── scripts
            ├── share
            ├── translation_status.json
            ├── translators.csv
            └── utils

To make a smooth transition, I'd suggest we initially replicate that installation structure, but with possibility to easily change to a FHS compliant structure (see also discussion on grass-dev ML thread). Even better would be to be able to switch between the "traditional" and the new FHS with a configuration flag.

Installation file structure as of now with CMake, looks like:

└── usr
    └── local
        ├── bin
        │   ├── d.barscale
        │   ├── d.colorlist
        │   ├── d.colortable
        │   ├── d.erase
        │   ├── ...
        │   ├── v.what
        │   ├── v.what.rast
        │   └── v.what.rast3
        ├── docs
        │   └── html
        ├── driver
        │   └── db
        ├── etc
        │   ├── VERSIONNUMBER
        │   ├── clean_temp
        │   ├── ...
        │   ├── python
        │   ├── renamed_options
        │   ├── run
        │   └── sql
        ├── gui
        │   ├── icons
        │   ├── images
        │   ├── wxpython
        │   └── xml
        ├── lib
        │   ├── libgrass_cairodriver.8.4.0dev.dylib
        │   ├── libgrass_cairodriver.8.dylib -> libgrass_cairodriver.8.4.0dev.dylib
        │   ├── libgrass_cairodriver.dylib -> libgrass_cairodriver.8.dylib
        │   ├── ...
        │   ├── libgrass_rli.8.dylib -> libgrass_rli.8.4.0dev.dylib
        │   └── libgrass_rli.dylib -> libgrass_rli.8.dylib
        ├── scripts
        │   ├── d.background
        │   ├── d.correlate
        │   ├── d.frame
        │   ├── ...
        │   ├── v.what.strds
        │   ├── v.what.vect
        │   └── wxpyimgview
        └── share
            ├── appdata
            ├── applications
            └── icons

... which with some changes will probably conform to FHS. But we should also/primarily enable the "traditional" structure, which could be realised with clever use of variables.

@echoix
Copy link
Member

echoix commented Apr 23, 2024

Is there a way to already deprecate the "traditional" layout and make it clear when you choose to make cmake create the traditional layout instead of fhs?

When talking about fhs, I don't really stick to FHS, but anything that should be standard on that platform, like with the GNUInstallDirs module
https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html. Is there an equivalent for other platforms?

@nilason
Copy link
Contributor

nilason commented Apr 24, 2024

Started discussion #3661 on the new FHS complying structure.

@nilason
Copy link
Contributor

nilason commented Apr 24, 2024

Is there a way to already deprecate the "traditional" layout and make it clear when you choose to make cmake create the traditional layout instead of fhs?

We can only deprecate it when the new structure is tested well enough. Such changes are bound to lead to unexpected issues of every kind. I think the definite step to the new structure may be done only with a mayor version bump (e.g. GRASS 9).
Our adoption of CMake is important in particular for Windows, which is why -- in my opinion -- it is necessary to initially keep the "traditional" structure also for CMake builds. Otherwise it would certainly be easier to let the CMake adoption bring the new structure alone.

@wenzeslaus wenzeslaus added this to the Future milestone Apr 26, 2024
@nilason
Copy link
Contributor

nilason commented May 8, 2024

@HuidaeCho I hope you haven't worked on this any further, as I have done so. I have some made some extensive changes for enabling both current and FHS compliant install structure, which I will hopefully be able to commit soon.

@echoix
Copy link
Member

echoix commented May 8, 2024

@HuidaeCho I hope you haven't worked on this any further, as I have done so. I have some made some extensive changes for enabling both current and FHS compliant install structure, which I will hopefully be able to commit soon.

There's always the possibility to create a PR to his branch if you fear a force push/rebase

@nilason
Copy link
Contributor

nilason commented May 8, 2024

@HuidaeCho I hope you haven't worked on this any further, as I have done so. I have some made some extensive changes for enabling both current and FHS compliant install structure, which I will hopefully be able to commit soon.

There's always the possibility to create a PR to his branch if you fear a force push/rebase

I’m more worried about double work.

@HuidaeCho
Copy link
Member Author

@nilason No worries. I haven't had a chance to work on it, but I'll resume very soon. So please make your commit when it's ready and let me know.

@HuidaeCho
Copy link
Member Author

@nilason I was wondering about the status of your FHS work. Are you ready to commit it?

@nilason
Copy link
Contributor

nilason commented May 15, 2024

@nilason I was wondering about the status of your FHS work. Are you ready to commit it?

The framework is in place. It will certainly be necessary to fine-tune, at least for the FHS install, but it broadly works. At this moment, I'm working to produce an identical install package (file tree) as the present autoconfig build produces. For this is manual/doc generation and locale not implemented (independently of this FHS adaptation). I'm currently working on manual generation (indexing remains to be fixed).
I can push current stand if you will.

(Tip: testing installation is best made with make DESTDIR="path/to/install/dir" install from build directory. This avoids messing up the file system. Comparing the autoconfig installation with the cmake installation can be made with diff "dir1" "dir2").

@HuidaeCho
Copy link
Member Author

@nilason I was wondering about the status of your FHS work. Are you ready to commit it?

The framework is in place. It will certainly be necessary to fine-tune, at least for the FHS install, but it broadly works. At this moment, I'm working to produce an identical install package (file tree) as the present autoconfig build produces. For this is manual/doc generation and locale not implemented (independently of this FHS adaptation). I'm currently working on manual generation (indexing remains to be fixed). I can push current stand if you will.

(Tip: testing installation is best made with make DESTDIR="path/to/install/dir" install from build directory. This avoids messing up the file system. Comparing the autoconfig installation with the cmake installation can be made with diff "dir1" "dir2").

Thanks for the update! Have we agreed on a specific FHS structure?

@nilason
Copy link
Contributor

nilason commented May 15, 2024

Thanks for the update! Have we agreed on a specific FHS structure?

What I have now, at the moment it, is what I proposed in #3661 (comment). But that is relatively easy to change if needed, only setting the variables.

@github-actions github-actions bot added Python Related code is in Python translation Message translation related labels May 24, 2024
@nilason
Copy link
Contributor

nilason commented May 24, 2024

Soo, I finally pushed a major commit! The base for FHS is in place. Build and install works for traditional file structure. I added test, which do not yet pass completely. There is still a lot to do, I cheated on CI with -DCMAKE_C_FLAGS="-I/usr/include -I/usr/include/gdal", which must be addressed properly. FHS will not really work properly without source changes (because of breaking up of GISBASE), I cheated with symlinks for build for the time being.
I will in the following weeks not be able to work on this, so please continue if you will.

DESTINATION ${GRASS_INSTALL_ETCDIR})

execute_process(
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/version.sed "${GRASS_VERSION_NUMBER}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is COMMAND sh the cmake portable way of doing operations? In other words, does this tie compiling on windows to a msys2/cygwin environment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP, Windows will be a challenge…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. Do you think having the CI ready for windows earlier would help or harm? Like seeing more failures than needed, but also tracking up to where the build can reach.

@echoix
Copy link
Member

echoix commented May 24, 2024

When the time will come I'll help out on the CI part, adding Mac and windows (if it is close) together. But probably not now

@nilason
Copy link
Contributor

nilason commented May 24, 2024

Looks like the failing tests are caused by (only) ctypesgen not finding libs.

@wenzeslaus
Copy link
Member

...FHS will not really work properly without source changes (because of breaking up of GISBASE)...

Not the necessary changes, but the prep for that for grass.script and for the main executable is here: #3694. I'm not working on it right now, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C C++ Related code is in C++ CI Continuous integration database Related to database management display docs general GUI wxGUI related imagery libraries misc module Python Related code is in Python raster Related to raster data processing raster3d temporal Related to temporal data processing translation Message translation related vector Related to vector data processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants