mapnik/CMakeLists.txt

283 lines
10 KiB
Text
Raw Normal View History

2020-11-20 18:20:43 +01:00
cmake_minimum_required(VERSION 3.15.0)
project(mapnik
VERSION 3.0.24
HOMEPAGE_URL "https://mapnik.org/"
DESCRIPTION "Mapnik is an open source toolkit for developing mapping applications"
LANGUAGES CXX
2020-11-20 20:20:28 +01:00
)
2020-11-20 21:15:27 +01:00
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
option(BUILD_SHARED_LIBS "build mapnik dynamic(ON) or static(OFF)" ON)
2020-11-21 13:20:04 +01:00
option(BUILD_TEST "builds the tests" ON)
2020-11-21 10:09:29 +01:00
option(USE_EXTERNAL_MAPBOX_GEOMETRY "Use a external mapnik/geometry.hpp. If off, use the submodule" OFF)
option(USE_EXTERNAL_MAPBOX_POLYLABEL "Use a external mapnik/polylabel. If off, use the submodule" OFF)
option(USE_EXTERNAL_MAPBOX_PROTOZERO "Use a external mapnik/protozero. If off, use the submodule" OFF)
option(USE_EXTERNAL_MAPBOX_VARIANT "Use a external mapnik/variant. If off, use the submodule" OFF)
2020-11-21 17:03:30 +01:00
option(USE_JPEG "adds jpeg support" ON)
option(USE_PNG "adds png support" ON)
option(USE_TIFF "adds tiff support" ON)
option(USE_WEBP "adds webp support" ON)
option(USE_LIBXML2 "adds libxml2 support" ON)
option(USE_CAIRO "adds the cairo renderer" ON)
2020-11-21 12:38:29 +01:00
option(USE_PROJ4 "adds proj4 support" ON)
2020-11-21 17:03:30 +01:00
option(USE_GRID_RENDERER "adds grid renderer" ON)
option(USE_SVG_RENDERER "adds grid renderer" ON)
2020-11-20 20:20:28 +01:00
2020-11-21 11:34:45 +01:00
option(USE_PLUGIN_INPUT_CSV "adds plugin input csv" ON)
option(USE_PLUGIN_INPUT_GDAL "adds plugin input gdal" ON)
option(USE_PLUGIN_INPUT_GEOBUF "adds plugin input geobuf" ON)
option(USE_PLUGIN_INPUT_GEOJSON "adds plugin input geojson" ON)
option(USE_PLUGIN_INPUT_OGR "adds plugin input ogr" ON)
option(USE_PLUGIN_INPUT_PGRASTER "adds plugin input pgraster" ON)
option(USE_PLUGIN_INPUT_POSTGIS "adds plugin input postgis" ON)
option(USE_PLUGIN_INPUT_RASTER "adds plugin input raster" ON)
option(USE_PLUGIN_INPUT_SHAPE "adds plugin input shape" ON)
option(USE_PLUGIN_INPUT_SQLITE "adds plugin input sqlite" ON)
option(USE_PLUGIN_INPUT_TOPOJSON "adds plugin input topojson" ON)
2020-11-21 12:24:34 +01:00
option(BUILD_DEMO_VIEWER "builds the demo viewer" ON)
option(BUILD_DEMO_CPP "builds the demo c++ application" ON)
2020-11-21 12:30:34 +01:00
option(BUILD_UTILITY_GEOMETRY_TO_WKB "builds the utility program geometry_to_wkb" ON)
option(BUILD_UTILITY_MAPNIK_INDEX "builds the utility program mapnik_index" ON)
option(BUILD_UTILITY_MAPNIK_RENDER "builds the utility program mapnik_render" ON)
option(BUILD_UTILITY_OGRINDEX "builds the utility program ogrindex" OFF)
option(BUILD_UTILITY_PGSQL2SQLITE "builds the utility program pgsql2sqlite" ON)
option(BUILD_UTILITY_SHAPEINDEX "builds the utility program shapeindex" ON)
option(BUILD_UTILITY_SVG2PNG "builds the utility program svg2png" ON)
2020-11-21 12:24:34 +01:00
2020-11-22 22:11:27 +01:00
set(CMAKE_CXX_STANDARD 14 CACHE STRING "Sets the c++ standard. c++11 is minimum.")
2020-11-25 15:42:33 +01:00
message(STATUS "Using c++${CMAKE_CXX_STANDARD}")
2020-11-20 20:20:28 +01:00
if(WIN32)
set(DEFAULT_BIN_DIR bin)
set(DEFAULT_LIB_DIR lib)
set(DEFAULT_ARCHIVE_DIR lib)
else()
include(GNUInstallDirs)
set(DEFAULT_BIN_DIR ${CMAKE_INSTALL_BINDIR})
set(DEFAULT_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
set(DEFAULT_ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR})
endif()
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#runtime-output-artifacts
set(MAPNIK_BIN_DIR ${DEFAULT_BIN_DIR} CACHE STRING "Install directory for binaries")
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#library-output-artifacts
set(MAPNIK_LIB_DIR ${DEFAULT_LIB_DIR} CACHE STRING "Install directory for libraries")
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#archive-output-artifacts
set(MAPNIK_ARCHIVE_DIR ${DEFAULT_ARCHIVE_DIR} CACHE STRING "Install directory for archives")
set(INSTALL_CMAKE_DIR ${MAPNIK_LIB_DIR}/mapnik/cmake CACHE STRING "Install directory of the cmake targets")
if(WIN32)
set(DEFAULT_PLUGINS_INSTALL_DIR ${MAPNIK_BIN_DIR}/mapnik/input)
else()
set(DEFAULT_PLUGINS_INSTALL_DIR ${MAPNIK_LIB_DIR}/mapnik/input)
endif()
set(PLUGINS_INSTALL_DIR ${DEFAULT_PLUGINS_INSTALL_DIR} CACHE STRING "installs the plugins in the specified directory")
2020-11-25 15:42:33 +01:00
message(STATUS "Installing plugins to ${PLUGINS_INSTALL_DIR}")
set(FONTS_INSTALL_DIR ${MAPNIK_BIN_DIR}/fonts CACHE STRING "installs the fonts in the specified directory")
2020-11-25 15:42:33 +01:00
message(STATUS "Installing fonts to ${FONTS_INSTALL_DIR}")
2020-11-22 22:01:33 +01:00
find_package(Boost 1.74 REQUIRED COMPONENTS filesystem system regex)
2020-11-20 20:20:28 +01:00
find_package(ICU REQUIRED COMPONENTS uc)
2020-11-20 21:15:27 +01:00
find_package(Freetype REQUIRED)
2020-11-21 09:46:54 +01:00
find_package(harfbuzz CONFIG REQUIRED)
2020-11-20 20:20:28 +01:00
if(USE_EXTERNAL_MAPBOX_GEOMETRY)
2020-11-22 22:01:33 +01:00
# this is used to provide a way to specify include dirs with CACHE VARIABLES
2020-11-21 11:34:45 +01:00
if(NOT MAPBOX_GEOMETRY_INCLUDE_DIRS)
message(STATUS "Searching for the include dir of mapbox/geometry.hpp")
find_path(MAPBOX_GEOMETRY_INCLUDE_DIRS "mapbox/geometry.hpp" REQUIRED)
endif()
2020-11-20 20:20:28 +01:00
else()
2020-11-21 11:34:45 +01:00
set(MAPBOX_GEOMETRY_INCLUDE_DIRS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/geometry/include>
)
2020-11-20 20:20:28 +01:00
endif()
if(NOT MAPBOX_GEOMETRY_INCLUDE_DIRS)
2020-11-21 11:34:45 +01:00
message(FATAL_ERROR "Set -DMAPBOX_GEOMETRY_INCLUDE_DIRS to the mapbox/geometry.hpp include dir")
2020-11-20 20:20:28 +01:00
endif()
if(USE_EXTERNAL_MAPBOX_POLYLABEL)
2020-11-21 11:34:45 +01:00
if(NOT MAPBOX_POLYLABEL_INCLUDE_DIRS)
message(STATUS "Searching for the include dir of mapbox/polylabel")
find_path(MAPBOX_POLYLABEL_INCLUDE_DIRS "mapbox/polylabel.hpp")
endif()
2020-11-20 20:20:28 +01:00
else()
2020-11-21 11:34:45 +01:00
set(MAPBOX_POLYLABEL_INCLUDE_DIRS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/polylabel/include>
)
2020-11-20 20:20:28 +01:00
endif()
if(NOT MAPBOX_POLYLABEL_INCLUDE_DIRS)
message(FATAL_ERROR "Set MAPBOX_POLYLABEL_INCLUDE_DIRS to the mapbox/geometry include dir")
endif()
if(USE_EXTERNAL_MAPBOX_PROTOZERO)
2020-11-21 11:34:45 +01:00
if(NOT MAPBOX_PROTOZERO_INCLUDE_DIRS)
message(STATUS "Searching for the include dir of mapbox/protozero")
find_path(MAPBOX_PROTOZERO_INCLUDE_DIRS "protozero/pbf_message.hpp")
endif()
2020-11-20 20:20:28 +01:00
else()
2020-11-21 11:34:45 +01:00
set(MAPBOX_PROTOZERO_INCLUDE_DIRS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/protozero/include>
)
2020-11-20 20:20:28 +01:00
endif()
if(NOT MAPBOX_PROTOZERO_INCLUDE_DIRS)
message(FATAL_ERROR "Set MAPBOX_PROTOZERO_INCLUDE_DIRS to the mapbox/protozero include dir")
endif()
if(USE_EXTERNAL_MAPBOX_VARIANT)
2020-11-21 11:34:45 +01:00
if(NOT MAPBOX_VARIANT_INCLUDE_DIRS)
message(STATUS "Searching for the include dir of mapbox/variant")
find_path(MAPBOX_VARIANT_INCLUDE_DIRS "mapbox/variant.hpp")
endif()
2020-11-20 20:20:28 +01:00
else()
2020-11-21 11:34:45 +01:00
set(MAPBOX_VARIANT_INCLUDE_DIRS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/variant/include>
)
2020-11-20 20:20:28 +01:00
endif()
if(NOT MAPBOX_VARIANT_INCLUDE_DIRS)
message(FATAL_ERROR "Set MAPBOX_VARIANT_INCLUDE_DIRS to the mapbox/variant include dir")
endif()
2020-11-20 21:15:27 +01:00
set(MAPNIK_COMPILE_DEFS "")
set(MAPNIK_OPTIONAL_LIBS "")
2021-01-24 19:34:51 +01:00
set(MAPNIK_OPTIONAL_LIBS_INCLUDE "")
2020-11-20 21:15:27 +01:00
2020-11-21 10:09:29 +01:00
if(USE_LIBXML2)
message(STATUS "Using LibXml2")
find_package(LibXml2 REQUIRED)
2020-11-21 11:34:45 +01:00
list(APPEND MAPNIK_COMPILE_DEFS HAVE_LIBXML2)
list(APPEND MAPNIK_OPTIONAL_LIBS LibXml2::LibXml2)
2020-11-20 21:15:27 +01:00
endif()
2020-11-21 10:09:29 +01:00
if(USE_PNG)
message(STATUS "Using PNG")
find_package(PNG REQUIRED)
2020-11-21 11:34:45 +01:00
list(APPEND MAPNIK_COMPILE_DEFS HAVE_PNG)
list(APPEND MAPNIK_OPTIONAL_LIBS PNG::PNG)
2020-11-20 21:15:27 +01:00
endif()
2020-11-21 10:09:29 +01:00
if(USE_JPEG)
message(STATUS "Using JPEG")
find_package(JPEG REQUIRED)
2020-11-21 11:34:45 +01:00
list(APPEND MAPNIK_COMPILE_DEFS HAVE_JPEG)
list(APPEND MAPNIK_OPTIONAL_LIBS JPEG::JPEG)
2020-11-20 21:15:27 +01:00
endif()
2020-11-21 10:09:29 +01:00
if(USE_TIFF)
find_package(TIFF REQUIRED)
message(STATUS "Using TIFF")
2020-11-21 11:34:45 +01:00
list(APPEND MAPNIK_COMPILE_DEFS HAVE_TIFF)
list(APPEND MAPNIK_OPTIONAL_LIBS TIFF::TIFF)
2020-11-20 21:15:27 +01:00
endif()
2020-11-21 10:09:29 +01:00
if(USE_WEBP)
message(STATUS "Using WEBP")
find_package(WebP CONFIG REQUIRED)
2020-11-21 11:34:45 +01:00
list(APPEND MAPNIK_COMPILE_DEFS HAVE_WEBP)
list(APPEND MAPNIK_OPTIONAL_LIBS WebP::webp)
2020-11-20 21:15:27 +01:00
endif()
2020-11-21 10:09:29 +01:00
if(USE_CAIRO)
message(STATUS "Using Cairo renderer")
find_package(Cairo REQUIRED)
2020-11-21 11:34:45 +01:00
list(APPEND MAPNIK_COMPILE_DEFS HAVE_CAIRO)
list(APPEND MAPNIK_OPTIONAL_LIBS Cairo::Cairo)
2020-11-20 21:15:27 +01:00
endif()
2020-11-21 12:38:29 +01:00
if(USE_PROJ4)
2021-01-24 19:34:51 +01:00
#https://proj.org/development/cmake.html
2020-11-21 12:38:29 +01:00
message(STATUS "Using PROJ4")
find_package(PROJ4 CONFIG REQUIRED)
2020-11-21 12:50:11 +01:00
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_USE_PROJ4 ACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1)
2021-01-24 19:34:51 +01:00
list(APPEND MAPNIK_OPTIONAL_LIBS ${PROJ4_LIBRARIES})
list(APPEND MAPNIK_OPTIONAL_LIBS_INCLUDE ${PROJ4_INCLUDE_DIRS})
2020-11-21 12:38:29 +01:00
endif()
2020-11-21 17:03:30 +01:00
if(USE_GRID_RENDERER)
message(STATUS "Using grid renderer")
list(APPEND MAPNIK_COMPILE_DEFS GRID_RENDERER)
endif()
if(USE_SVG_RENDERER)
message(STATUS "Using svg renderer")
list(APPEND MAPNIK_COMPILE_DEFS SVG_RENDERER)
endif()
add_library(headers INTERFACE)
add_library(mapnik::headers ALIAS headers)
2020-11-20 20:20:28 +01:00
target_include_directories(headers INTERFACE
2020-11-20 20:20:28 +01:00
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
2020-11-22 22:01:33 +01:00
$<BUILD_INTERFACE:${MAPBOX_GEOMETRY_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${MAPBOX_POLYLABEL_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${MAPBOX_VARIANT_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${MAPBOX_PROTOZERO_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps>
2020-11-20 20:20:28 +01:00
$<INSTALL_INTERFACE:include>
2021-01-24 19:34:51 +01:00
${MAPNIK_OPTIONAL_LIBS_INCLUDE}
2020-11-20 20:20:28 +01:00
)
target_link_libraries(headers INTERFACE
2020-11-20 20:20:28 +01:00
Boost::boost
2020-11-20 21:15:27 +01:00
Boost::regex
Boost::filesystem
2020-11-20 20:20:28 +01:00
ICU::uc
2020-11-20 21:15:27 +01:00
Freetype::Freetype
2020-11-21 09:46:54 +01:00
harfbuzz::harfbuzz
2020-11-20 21:15:27 +01:00
${MAPNIK_OPTIONAL_LIBS}
2020-11-20 20:20:28 +01:00
)
target_compile_definitions(headers INTERFACE ${MAPNIK_COMPILE_DEFS})
2020-11-20 20:20:28 +01:00
install(TARGETS headers
2020-11-20 20:20:28 +01:00
EXPORT MapnikTargets
LIBRARY DESTINATION ${MAPNIK_LIB_DIR}
ARCHIVE DESTINATION ${MAPNIK_ARCHIVE_DIR}
RUNTIME DESTINATION ${MAPNIK_BIN_DIR}
2020-11-20 20:20:28 +01:00
INCLUDES DESTINATION include/
PUBLIC_HEADER DESTINATION include/
)
2020-11-20 21:15:27 +01:00
2020-11-20 20:20:28 +01:00
add_subdirectory(deps)
add_subdirectory(src)
2020-11-21 11:34:45 +01:00
add_subdirectory(plugins)
2020-11-21 12:24:34 +01:00
add_subdirectory(utils)
add_subdirectory(demo)
2020-11-21 13:20:04 +01:00
if(BUILD_TEST)
enable_testing()
add_subdirectory(test)
endif()
2020-11-21 11:34:45 +01:00
2020-11-22 22:01:33 +01:00
# start package mapnik
2020-11-21 11:34:45 +01:00
include(CMakePackageConfigHelpers)
2020-11-22 22:01:33 +01:00
# set the cmake targets install location
set(INCLUDE_INSTALL_DIR include/)
2020-11-21 11:34:45 +01:00
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/MapnikConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/MapnikConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/MapnikConfig.cmake"
2020-11-22 22:01:33 +01:00
INSTALL_DESTINATION ${INSTALL_CMAKE_DIR}
PATH_VARS INCLUDE_INSTALL_DIR PLUGINS_INSTALL_DIR FONTS_INSTALL_DIR
2020-11-21 11:34:45 +01:00
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/MapnikConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/MapnikConfigVersion.cmake"
2020-11-22 22:01:33 +01:00
DESTINATION ${INSTALL_CMAKE_DIR}
2020-11-21 11:34:45 +01:00
)
install(EXPORT MapnikTargets
FILE MapnikTargets.cmake
NAMESPACE mapnik::
2020-11-22 22:01:33 +01:00
DESTINATION ${INSTALL_CMAKE_DIR}
2020-11-21 11:34:45 +01:00
)
2020-11-21 12:24:34 +01:00
install(DIRECTORY include/ TYPE INCLUDE)
install(DIRECTORY deps/agg/include/ TYPE INCLUDE)
2020-11-22 22:01:33 +01:00
install(DIRECTORY fonts/ DESTINATION ${FONTS_INSTALL_DIR} FILES_MATCHING PATTERN "*.py" EXCLUDE PATTERN "*")