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

CMake build environment with Visual Studio support #2684

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
616be6a
parent 464ffca1e1fbb98107593ee60c43a8449e567eed
rkanavath Jun 11, 2017
98cb9a0
revert C related INFINITY/NAN changes (this is taken care of in #2681)
neteler Dec 5, 2022
a1c304b
Sync to PR Cmake build2 #348 (replaces #348)
neteler Dec 5, 2022
2572080
CI fix for pylint in gui/wxpython called with wildcard
neteler Dec 5, 2022
637160d
cmake/find_scripts/FindPROJ.cmake: update to PROJ > 4
neteler Dec 5, 2022
d505352
cmake/find_scripts/FindPostgreSQL.cmake: update to https://github.com…
neteler Dec 5, 2022
0099daa
various path updates (sync to main)
neteler Dec 5, 2022
297f2b3
grass7 -> grass8; msg cosmetics
neteler Dec 5, 2022
77c79a1
CI: cmake compile script
neteler Dec 6, 2022
f590798
fix syntax
neteler Dec 10, 2022
b79ac0e
fix Build step
neteler Dec 10, 2022
a189cb7
Build step debugging
neteler Dec 11, 2022
b957a81
Simplify cmake command call
neteler Jan 2, 2023
0d4e0da
Remove debugging leftover.
neteler Jan 2, 2023
20c00ba
make -> cmake
neteler Jan 2, 2023
c158111
update year
neteler Jan 2, 2023
44acbfa
python_bandref -> python_semantic_label
neteler Jan 2, 2023
4e8ddc7
remove outdated bandref
neteler Jan 2, 2023
ab8a0a3
bandref -> semantic_label
neteler Jan 2, 2023
0834a87
added python/CMakeLists.txt (from https://github.com/OSGeo/grass/pull…
neteler Jan 2, 2023
ec65ecb
add_subdirectory(python)
neteler Jan 2, 2023
e094369
fix path to grass/script/setup.py
neteler Jan 2, 2023
7aeb0b6
remove files deleted in PR #1400
neteler Jan 2, 2023
2838cc9
Fix missing EOL
neteler Jan 2, 2023
74207c5
just peek in the folder (by @echoix)
neteler Jan 3, 2023
ea058ff
sync clang-format changes from main
neteler Jan 4, 2023
5f1dcf0
Merge branch 'main' into cmake_build
neteler Jan 4, 2023
3cb0241
apply clang-format
nilason Jan 4, 2023
2e0e73b
cmake_minimum_required version 3.11
neteler Jan 4, 2023
f258904
update to CMake 3.11.4
neteler Jan 4, 2023
816b835
add VERBATIM
neteler Jan 4, 2023
3eae792
pylint: ignore cmakelists.txt
nilason Jan 5, 2023
c160dd5
homogenize ubuntu image name
neteler Jan 4, 2023
644abd4
Merge branch 'main' into cmake_build
neteler Feb 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# inspired by "build GDAL library and to run test with CMake"
# from https://github.com/OSGeo/gdal/blob/master/.github/workflows/cmake_builds.yml

name: Build and test with CMake

on:
push:
paths-ignore:
- 'doc/**'
branches-ignore:
- 'backport**'
pull_request:
paths-ignore:
- 'doc/**'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

env:
CMAKE_UNITY_BUILD: OFF

permissions:
contents: read # to fetch code (actions/checkout)

jobs:

build-linux-ubuntu-focal:
runs-on: ubuntu-20.04
env:
CMAKE_OPTIONS: -DPython_LOOKUP_VERSION=3.8 -DUSE_CCACHE=ON
cache-name: cmake-ubuntu-focal
steps:
- name: Checkout GRASS
uses: actions/checkout@v3
- name: Setup cache
uses: actions/cache@v3
id: cache
with:
path: ${{ github.workspace }}/.ccache
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.base_ref }}${{ github.ref_name }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-${{ github.base_ref }}
${{ runner.os }}-${{ env.cache-name }}
- name: Install CMake 3.9.1
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason that cmake is installed that way on the runner? I understand that it isn't really for the GitHub runners, since cmake is installed by default (un ubuntu-latest (22.04LTS) it is currently cmake 3.25.1), but for documenting what was used, maybe for local porting. However, GitHub workflow files are already not runnable as is locally (I'm not talking about self-hosted runners here).
If there was no specific reason for using that version of cmake (released August 10, 2017), we could take it out, install one from apt-get (ubuntu), or use a GitHub action step that is integrated, like https://github.com/marketplace/actions/get-cmake#if-you-want-to-use--latest-stable-you-can-use-this-one-liner

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a specific reason that cmake is installed that way on the runner?

This was only my guess-work, maybe totally wrong. Here I took inspiration from the GDAL workflow while having zero knowledge about cmake :-)

run: |
cd ${GITHUB_WORKSPACE}
wget https://github.com/Kitware/CMake/releases/download/v3.9.1/cmake-3.9.1-Linux-x86_64.tar.gz
tar xzf cmake-3.9.1-Linux-x86_64.tar.gz
echo "CMAKE_DIR=$GITHUB_WORKSPACE/cmake-3.9.1-Linux-x86_64/bin" >> $GITHUB_ENV
echo "$GITHUB_WORKSPACE/cmake-3.9.1-Linux-x86_64/bin" >> $GITHUB_PATH
- run: |
cmake --version
- name: Install dependencies
run: |
sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install -y -q build-essential \
flex make bison gcc libgcc1 g++ ccache \
python3 python3-dev \
python3-opengl python3-wxgtk4.0 \
python3-dateutil libgsl-dev python3-numpy \
wx3.0-headers wx-common libwxgtk3.0-gtk3-dev \
libwxbase3.0-dev libbz2-dev zlib1g-dev gettext \
libtiff5-dev libpnglite-dev libcairo2 libcairo2-dev \
sqlite3 libsqlite3-dev \
libpq-dev libreadline6-dev libfreetype6-dev \
libfftw3-3 libfftw3-dev \
libboost-thread-dev libboost-program-options-dev libpdal-dev\
subversion libzstd-dev checkinstall \
neteler marked this conversation as resolved.
Show resolved Hide resolved
libglu1-mesa-dev libxmu-dev \
ghostscript wget -y make ccache g++
sudo apt-get update -y
- name: Configure ccache
run: |
echo CCACHE_BASEDIR=$PWD >> ${GITHUB_ENV}
echo CCACHE_DIR=$PWD/.ccache >> ${GITHUB_ENV}
echo CCACHE_MAXSIZE=250M >> ${GITHUB_ENV}
ccache -z
working-directory: ${{ github.workspace }}
- name: Configure
run: |
mkdir -p $GITHUB_WORKSPACE/build
cd $GITHUB_WORKSPACE/build
cmake ${CMAKE_OPTIONS} ..
neteler marked this conversation as resolved.
Show resolved Hide resolved
ls $GITHUB_WORKSPACE/build
sudo apt-get install -y -q mlocate ; sudo updatedb
locate include/Make/Platform.make
neteler marked this conversation as resolved.
Show resolved Hide resolved
- name: Build
run: |
cd $GITHUB_WORKSPACE/build
make -j$(nproc)
neteler marked this conversation as resolved.
Show resolved Hide resolved
- name: ccache statistics
run: ccache -s

2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
export PYTHONPATH=`grass --config python_path`:$PYTHONPATH
export LD_LIBRARY_PATH=$HOME/install/grass83/lib:$LD_LIBRARY_PATH
cd gui/wxpython
pylint --persistent=no --py-version=${{ matrix.min-python-version }} --jobs=$(nproc) *
pylint --persistent=no --py-version=${{ matrix.min-python-version }} --jobs=$(nproc) --disable=CMakeLists.txt *
neteler marked this conversation as resolved.
Show resolved Hide resolved
nilason marked this conversation as resolved.
Show resolved Hide resolved

- name: Run Pylint on other files using pytest
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ OBJ.*
locale/scriptstrings/*
bin.*/*
dist.*/*
.vs/*
CMakeSettings.json
config.log
config.status*
error.log
Expand Down
225 changes: 225 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# AUTHOR(S): Rashad Kanavath <rashad km gmail>
# PURPOSE: GRASS GIS root that adds options to activate/deactivate 3rd party libraries
# COPYRIGHT: (C) 2020-2022 by the GRASS Development Team
# This program is free software under the GPL (>=v2)
# Read the file COPYING that comes with GRASS for details.

cmake_minimum_required(VERSION 3.3)
neteler marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

#if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
# set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
#endif()

project(GRASSGIS)

set(BUILD_SHARED_LIBS ON)
#message(FATAL_ERROR "VCPKG_TARGET_TRIPLET=${VCPKG_TARGET_TRIPLET}")
if(MSVC)
if(BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/find_scripts;${CMAKE_SOURCE_DIR}/cmake/modules;${CMAKE_MODULE_PATH}")

set(default_option_enabled ON)
if(WIN32)
set(default_option_enabled OFF)
endif()

if(CMAKE_BUILD_TYPE)
set( grass_build_type "${CMAKE_BUILD_TYPE}" )
string( TOLOWER "${grass_build_type}" grass_build_type_lc )
set(find_library_suffix "_RELEASE")
if( grass_build_type_lc STREQUAL "debug" )
set(find_library_suffix "_DEBUG")
endif()
else()
set(find_library_suffix "")
endif()

option(WITH_CAIRO "Build with cairo support ." ON)
option(WITH_X11 "Build with X11 support ." ${default_option_enabled})
option(WITH_OPENGL "Build with opengl support ." ON)
option(WITH_SQLITE "enable sqlite support" ON)
option(WITH_POSTGRES "enable postgres support" ON)
option(WITH_NLS "enable nls support" ${default_option_enabled})
option(WITH_BZLIB "enable bzlib support" ON)
option(WITH_BLAS "enable blas support" ON)
option(WITH_LAPACK "enable lapack support" ON)
option(WITH_LIBLAS "enable libLAS support" OFF)
option(WITH_OPENDWG "enable v.in.dwg" OFF)

option(WITH_PYTHON "Build python bindings" ON)
option(WITH_LARGEFILES "enable largefile support" ${default_option_enabled})
option(WITH_DOCS "Build documentation" ON)
if(APPLE)
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
set(CMAKE_MACOSX_RPATH TRUE)
endif()

set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")

include(get_host_arch)
get_host_arch(BUILD_ARCH)

include(get_versions)
get_versions("include/VERSION"
GRASS_VERSION_MAJOR
GRASS_VERSION_MINOR
GRASS_VERSION_RELEASE
GRASS_VERSION_DATE)

set(GRASS_VERSION_NUMBER ${GRASS_VERSION_MAJOR}.${GRASS_VERSION_MINOR}.${GRASS_VERSION_RELEASE})
message(STATUS "GRASS_VERSION_NUMBER = '${GRASS_VERSION_NUMBER}'")
set(GRASS_VERSION_UPDATE_PKG "0.2")

include(set_compiler_flags)
set_compiler_flags()

include(repo_status)
repo_status("${CMAKE_CURRENT_LIST_DIR}" GRASS_VERSION_GIT)

enable_testing()

# Setup build locations.
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()

include(build_module)
include(build_program)
include(build_program_in_subdir)
include(build_library_in_subdir)
include(copy_python_files_in_subdir)
include(build_script_in_subdir)
include(build_gui_in_subdir)
include(check_target)

add_subdirectory(thirdparty)
set(MKHTML_PY ${CMAKE_BINARY_DIR}/utils/mkhtml.py)

set(GISBASE ${CMAKE_BINARY_DIR}/gisbase)
file(TO_NATIVE_PATH "${GISBASE}" GISBASE_NATIVE)
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/bin" BINARY_DIR)
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/lib" LIB_DIR)
file(TO_NATIVE_PATH "${CMAKE_SOURCE_DIR}" MODULE_TOPDIR)
file(TO_NATIVE_PATH "${GISBASE}/scripts" SCRIPTS_DIR)
file(TO_NATIVE_PATH "${GISBASE}/etc/config/rc" GISRC)
file(TO_NATIVE_PATH "${GISBASE}/etc/python" ETC_PYTHON_DIR)
file(TO_NATIVE_PATH "${GISBASE}/gui/wxpython" GUI_WXPYTHON_DIR)
if(WIN32)
set(sep "\;")
set(env_path "")
else()
set(sep ":")
set(env_path ":$ENV{PATH}")
endif()


set(grass_env_command ${CMAKE_COMMAND} -E env
"PATH=${BINARY_DIR}${sep}${SCRIPTS_DIR}${env_path}"
"PYTHONPATH=${ETC_PYTHON_DIR}${sep}${GUI_WXPYTHON_DIR}${sep}$ENV{PYTHONPATH}"
"LD_LIBRARY_PATH=${LIB_DIR}${sep}$ENV{LD_LIBRARY_PATH}"
"GISBASE=${GISBASE_NATIVE}"
"GISRC=${GISRC}"
"LC_ALL=C"
"LANG=C"
"LANGUAGE=C"
"MODULE_TOPDIR=${MODULE_TOPDIR}"
"VERSION_NUMBER=\"${GRASS_VERSION_NUMBER}\""
"VERSION_DATE=\"${GRASS_VERSION_DATE}\"")



set(NO_HTML_DESCR_TARGETS "g.parser;ximgview;test.raster3d.lib")
add_subdirectory(include)

include_directories("${CMAKE_BINARY_DIR}/include")
if(MSVC)
include_directories("${CMAKE_SOURCE_DIR}/msvc")
endif()

execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "Creating directories in ${GISBASE}"
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/bin/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/scripts/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/demolocation/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/etc/config/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/driver/db/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/utils/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/lib/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/python/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/etc/lister/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/etc/python/grass/lib
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/gui/wxpython/xml/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/gui/icons/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/gui/images/
COMMAND ${CMAKE_COMMAND} -E make_directory ${GISBASE}/docs/html/
)

add_subdirectory(lib)
add_subdirectory(utils)
set(modules_list)


set(ALL_SUBDIRS
general
db
display
imagery
misc
raster
raster3d
scripts
vector
temporal
# ps
)

foreach(d ${ALL_SUBDIRS})
add_subdirectory(${d})
endforeach()
add_custom_target(ALL_MODULES
COMMAND ${CMAKE_COMMAND} -E echo "Building all modules"
DEPENDS ${modules_list})

###message(FATAL_ERROR "modules_list=${modules_list}")

if(WITH_PYTHON)
add_subdirectory(gui)
endif()

neteler marked this conversation as resolved.
Show resolved Hide resolved
if(WITH_DOCS)
add_subdirectory(doc)
add_subdirectory(man)
endif() # WITH_DOCS


####add_subdirectory(locale)

# TODO: To be discussed
# add_subdirectory(testsuite)
# add_subdirectory(macosx)

if(WITH_X11)
build_program_in_subdir(visualization/ximgview DEPENDS grass_gis X11)
endif()
35 changes: 35 additions & 0 deletions cmake/copy_g_gui_module.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# AUTHOR(S): Rashad Kanavath <rashad km gmail>
# PURPOSE: Copy g.gui script plus .bat file if on windows
# COPYRIGHT: (C) 2020 by the GRASS Development Team
# This program is free software under the GPL (>=v2)
# Read the file COPYING that comes with GRASS for details.
# -DSOURCE_DIR
# -DGISBASE
# -DG_NAME
# -DSRC_SCRIPT_FILE
# -DBINARY_DIR

set(SCRIPT_EXT "")
if(WIN32)
set(SCRIPT_EXT ".py")
endif()

if(WIN32)
set(PGM_NAME ${G_NAME})
configure_file(
${SOURCE_DIR}/cmake/windows_launch.bat.in
${GISBASE}/scripts/${G_NAME}.bat @ONLY)
endif(WIN32)

set(TMP_SCRIPT_FILE ${BINARY_DIR}/CMakeFiles/${G_NAME}${SCRIPT_EXT})
configure_file(${SRC_SCRIPT_FILE} ${TMP_SCRIPT_FILE} COPYONLY)
file(
COPY ${TMP_SCRIPT_FILE}
DESTINATION ${GISBASE}/scripts/
FILE_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)


file(REMOVE ${TMP_SCRIPT_FILE})
Loading