diff --git a/.gitignore b/.gitignore index bf3bf93e0..9f55b20da 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,5 @@ test/visual/run # cmake build .vs + +CMakeUserPresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 456dc4be9..b718b25b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -266,9 +266,9 @@ endif() if(USE_PROJ) #https://proj.org/development/cmake.html - mapnik_find_package(PROJ QUIET) + mapnik_find_package(PROJ4 QUIET) # currently the cmake files are not installed, when installing proj via apt-get. So search via pkg-config - if(NOT PROJ_FOUND) + if(NOT PROJ4_FOUND) message(STATUS "PROJ not found via FindPROJ. Searching via pkg-config...") pkg_check_modules(PROJ REQUIRED IMPORTED_TARGET proj) string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" _dummy "${PROJ_VERSION}") @@ -276,11 +276,11 @@ if(USE_PROJ) set(PROJ_VERSION_MINOR "${CMAKE_MATCH_2}") set(PROJ_VERSION_PATCH "${CMAKE_MATCH_3}") endif() - math(EXPR MAPNIK_PROJ_VERSION "${PROJ_VERSION_MAJOR}*10000 + ${PROJ_VERSION_MINOR}*100 + ${PROJ_VERSION_PATCH}" OUTPUT_FORMAT DECIMAL) + math(EXPR MAPNIK_PROJ_VERSION "${PROJ4_VERSION_MAJOR}*10000 + ${PROJ4_VERSION_MINOR}*100 + ${PROJ4_VERSION_PATCH}" OUTPUT_FORMAT DECIMAL) message(STATUS "Using mapnik PROJ version: ${MAPNIK_PROJ_VERSION}") list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_USE_PROJ MAPNIK_PROJ_VERSION=${MAPNIK_PROJ_VERSION}) - list(APPEND MAPNIK_OPTIONAL_LIBS ${PROJ_LIBRARIES}) - list(APPEND MAPNIK_OPTIONAL_LIBS_INCLUDE ${PROJ_INCLUDE_DIRS}) + list(APPEND MAPNIK_OPTIONAL_LIBS ${PROJ4_LIBRARIES}) + list(APPEND MAPNIK_OPTIONAL_LIBS_INCLUDE ${PROJ4_INCLUDE_DIRS}) endif() if(USE_GRID_RENDERER) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..5477c3989 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,105 @@ +{ + "version": 2, + "cmakeMinimumRequired": { + "major": 3, + "minor": 20, + "patch": 0 + }, + "configurePresets": [ + { + "name": "linux-clang", + "displayName": "Linux clang", + "hidden": true, + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_CXX_FLAGS": "-stdlib=libstdc++", + "CMAKE_EXE_LINKER_FLAGS": "-stdlib=libstdc++", + "CMAKE_SHARED_LINKER_FLAGS": "-stdlib=libstdc++" + } + }, + { + "name": "linux-clang-debug", + "displayName": "Linux clang debug", + "inherits": "linux-clang", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "linux-clang-release", + "displayName": "Linux clang release", + "inherits": "linux-clang", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "linux-gcc", + "displayName": "Linux gcc", + "hidden": true, + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + } + }, + { + "name": "linux-gcc-debug", + "displayName": "Linux gcc debug", + "inherits": "linux-gcc", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "linux-gcc-release", + "displayName": "Linux gcc release", + "inherits": "linux-gcc", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "windows-default", + "displayName": "Windows x64 Debug", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "toolset": { + "value": "host=x64", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl" + }, + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { + "hostOS": [ + "Windows" + ] + } + } + }, + { + "name": "windows-default-release", + "displayName": "Windows x64 Release", + "inherits": "windows-default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default" + } + ] +} diff --git a/docs/cmake-usage.md b/docs/cmake-usage.md index c1dc5b647..cd99ff2fd 100644 --- a/docs/cmake-usage.md +++ b/docs/cmake-usage.md @@ -36,4 +36,61 @@ The font path is is available in the variable `MAPNIK_FONTS_DIR`. ## Recommendations If you target a specific platform, it is recommended to create a toolchain file and set all the options and library path that you would normally set via cmd line options. -If you are using a recent cmake version (>=3.19?), it is recommended to use a CMakePreset instead. https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html +If you are using a recent cmake version (>=3.20), it is recommended to use a CMakePreset instead. https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html + + +## CMakePreset example + +If you are using CMakePresets and need to add vcpkg integration, just create a `CMakeUserPresets.json` file beside `CMakePresets.json. +This could look like this: +```json +{ + "version": 2, + "cmakeMinimumRequired": { + "major": 3, + "minor": 20, + "patch": 0 + }, + "configurePresets": [ + { + "name": "vcpkg-x64-win-debug", + "inherits": "windows-default", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "D:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake" + } + }, + { + "name": "vcpkg-x64-win-release", + "inherits": "windows-default-release", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "D:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake" + } + } + ] +} +``` + + +If your libraries are not in the global search paths, you could add a own `CMakeUserPresets.json` with + +```json +{ + "version": 2, + "cmakeMinimumRequired": { + "major": 3, + "minor": 20, + "patch": 0 + }, + "configurePresets": [ + { + "name": "linux-clang-debug-own", + "inherits": "linux-clang-debug", + "cacheVariables": { + "WebP_DIR": "/home/myuser/webp/cmake", + "USE_CAIRO": "OFF", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/install" + } + } + ] +} +```