From f1ed49edec8ab50d0263f5dfd4a3f77190c5f0d4 Mon Sep 17 00:00:00 2001 From: Mathis Logemann Date: Wed, 22 Sep 2021 20:49:44 +0200 Subject: [PATCH] install utilities --- CMakeLists.txt | 39 +-------------- cmake/MapnikExport.cmake | 38 +++++++++++++++ cmake/MapnikInstall.cmake | 71 ++++++++++++++++++++-------- cmake/mapnikConfig.cmake.in | 10 +++- demo/c++/CMakeLists.txt | 1 - demo/viewer/CMakeLists.txt | 2 +- utils/geometry_to_wkb/CMakeLists.txt | 2 +- utils/mapnik-index/CMakeLists.txt | 2 +- utils/mapnik-render/CMakeLists.txt | 2 +- utils/ogrindex/CMakeLists.txt | 2 +- utils/pgsql2sqlite/CMakeLists.txt | 2 +- utils/shapeindex/CMakeLists.txt | 2 +- utils/svg2png/CMakeLists.txt | 2 +- 13 files changed, 108 insertions(+), 67 deletions(-) create mode 100644 cmake/MapnikExport.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bcaf2963..01af5c4b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,6 +218,7 @@ endif() # (used by MapnikInstall.cmake. properties are needed since "set(...)" will be out of scope set_property(GLOBAL PROPERTY TARGETS "") set_property(GLOBAL PROPERTY PLUGINS "") +set_property(GLOBAL PROPERTY MAPNIK_UTILITIES "") if(USE_GLIBC_WORKAROUND) message("using glibc workaround") @@ -372,43 +373,7 @@ if(BUILD_TEST) endif() # start package mapnik -include(CMakePackageConfigHelpers) - -# set the cmake targets install location -set(INCLUDE_INSTALL_DIR include/) -write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/mapnikConfigVersion.cmake" - VERSION ${PROJECT_VERSION} - COMPATIBILITY SameMajorVersion -) - -list(JOIN MAPNIK_DEPENDENCIES "\n" MAPNIK_DEPENDENCIES) -configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mapnikConfig.cmake.in - "${CMAKE_CURRENT_BINARY_DIR}/mapnikConfig.cmake" - INSTALL_DESTINATION ${MAPNIK_CMAKE_DIR} - PATH_VARS INCLUDE_INSTALL_DIR PLUGINS_INSTALL_DIR FONTS_INSTALL_DIR MAPNIK_DEPENDENCIES -) - -install( - FILES - "${CMAKE_CURRENT_BINARY_DIR}/mapnikConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/mapnikConfigVersion.cmake" - DESTINATION ${MAPNIK_CMAKE_DIR} -) - -install( - FILES - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindCairo.cmake" - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindWebP.cmake" - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindHarfBuzz.cmake" - DESTINATION ${MAPNIK_CMAKE_DIR}/Modules -) - -install(EXPORT MapnikTargets - DESTINATION ${MAPNIK_CMAKE_DIR} - FILE mapnikTargets.cmake - NAMESPACE mapnik:: -) +include(MapnikExport) install(DIRECTORY include/ DESTINATION ${MAPNIK_INCLUDE_DIR}) install(DIRECTORY deps/agg/include/ DESTINATION ${MAPNIK_INCLUDE_DIR}) diff --git a/cmake/MapnikExport.cmake b/cmake/MapnikExport.cmake new file mode 100644 index 000000000..89cba1391 --- /dev/null +++ b/cmake/MapnikExport.cmake @@ -0,0 +1,38 @@ +include(CMakePackageConfigHelpers) + +# set the cmake targets install location +set(INCLUDE_INSTALL_DIR include/) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/mapnikConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) +get_property(MAPNIK_UTILITIES GLOBAL PROPERTY MAPNIK_UTILITIES) +list(JOIN MAPNIK_DEPENDENCIES "\n" MAPNIK_DEPENDENCIES) +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mapnikConfig.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/mapnikConfig.cmake" + INSTALL_DESTINATION ${MAPNIK_CMAKE_DIR} + PATH_VARS INCLUDE_INSTALL_DIR PLUGINS_INSTALL_DIR FONTS_INSTALL_DIR MAPNIK_DEPENDENCIES MAPNIK_UTILITIES + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) + +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/mapnikConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/mapnikConfigVersion.cmake" + DESTINATION ${MAPNIK_CMAKE_DIR} +) + +install( + FILES + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindCairo.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindWebP.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindHarfBuzz.cmake" + DESTINATION ${MAPNIK_CMAKE_DIR}/Modules +) + +install(EXPORT MapnikTargets + DESTINATION ${MAPNIK_CMAKE_DIR} + FILE mapnikTargets.cmake + NAMESPACE mapnik:: +) diff --git a/cmake/MapnikInstall.cmake b/cmake/MapnikInstall.cmake index fc5c4350e..a62a87aa1 100644 --- a/cmake/MapnikInstall.cmake +++ b/cmake/MapnikInstall.cmake @@ -1,3 +1,6 @@ +# +# Install library targets that consuming users need. +# function(mapnik_install _target) install(TARGETS ${_target} EXPORT MapnikTargets @@ -11,13 +14,14 @@ function(mapnik_install _target) COMPONENT MapnikDevelopment ) get_target_property(TARGET_TYPE "${_target}" TYPE) - if (TARGET_TYPE STREQUAL "EXECUTABLE") - get_property(MAPNIK_INSTALLED_TARGETS GLOBAL PROPERTY TARGETS) - list(APPEND MAPNIK_INSTALLED_TARGETS ${_target}) - set_property(GLOBAL PROPERTY TARGETS ${MAPNIK_INSTALLED_TARGETS}) + if (TARGET_TYPE STREQUAL "SHARED_LIBRARY") + set_property(GLOBAL APPEND PROPERTY TARGETS ${_target}) endif() endfunction() +# +# Install plugins +# function(mapnik_install_plugin _target) install(TARGETS ${_target} RUNTIME DESTINATION ${PLUGINS_INSTALL_DIR} @@ -28,36 +32,65 @@ function(mapnik_install_plugin _target) ARCHIVE DESTINATION ${PLUGINS_INSTALL_DIR} COMPONENT MapnikPluginDevelopment ) - get_property(MAPNIK_INSTALLED_PLUGINS GLOBAL PROPERTY PLUGINS) - list(APPEND MAPNIK_INSTALLED_PLUGINS ${_target}) - set_property(GLOBAL PROPERTY PLUGINS ${MAPNIK_INSTALLED_PLUGINS}) + set_property(GLOBAL APPEND PROPERTY PLUGINS ${_target}) endfunction() +# +# Install executables. These are available via COMPONENTS in find_package +# +function(mapnik_install_utility _target) + set(_target_name "MapnikUtility_${_target}_Targets") + install(TARGETS ${_target} + EXPORT ${_target_name} + INCLUDES DESTINATION ${MAPNIK_INCLUDE_DIR} + RUNTIME DESTINATION ${MAPNIK_BIN_DIR} + COMPONENT MapnikRuntime + LIBRARY DESTINATION ${MAPNIK_LIB_DIR} + COMPONENT MapnikRuntime + NAMELINK_COMPONENT MapnikDevelopment + ARCHIVE DESTINATION ${MAPNIK_ARCHIVE_DIR} + COMPONENT MapnikDevelopment + ) + install(EXPORT ${_target_name} + FILE ${_target_name}.cmake + NAMESPACE mapnik:: + DESTINATION ${MAPNIK_CMAKE_DIR} + ) + set_property(GLOBAL APPEND PROPERTY MAPNIK_UTILITIES ${_target}) +endfunction() + + function(mapnik_install_targets) if(INSTALL_DEPENDENCIES AND WIN32) # https://cmake.org/cmake/help/latest/policy/CMP0087.html cmake_policy(SET CMP0087 NEW) - get_property(MAPNIK_INSTALLED_TARGETS GLOBAL PROPERTY TARGETS) - get_property(MAPNIK_INSTALLED_PLUGINS GLOBAL PROPERTY PLUGINS) - set(INTERNAL_TARGETS "") - set(INTERNAL_PLUGINS "") + get_property(_installed_utilities GLOBAL PROPERTY MAPNIK_UTILITIES) + get_property(_installed_targets GLOBAL PROPERTY TARGETS) + get_property(_installed_plugins GLOBAL PROPERTY PLUGINS) + set(_internal_executables "") + set(_internal_libraries "") - foreach(_target IN LISTS MAPNIK_INSTALLED_TARGETS) - list(APPEND INTERNAL_TARGETS "${CMAKE_INSTALL_PREFIX}/${MAPNIK_BIN_DIR}/$") + foreach(_target IN LISTS _installed_utilities) + list(APPEND _internal_executables "${CMAKE_INSTALL_PREFIX}/${MAPNIK_BIN_DIR}/$") endforeach() - foreach(_target IN LISTS MAPNIK_INSTALLED_PLUGINS) - list(APPEND INTERNAL_PLUGINS "${CMAKE_INSTALL_PREFIX}/${PLUGINS_INSTALL_DIR}/$") + foreach(_target IN LISTS _installed_targets) + list(APPEND _internal_libraries "${CMAKE_INSTALL_PREFIX}/${MAPNIK_BIN_DIR}/$") + endforeach() + foreach(_target IN LISTS _installed_plugins) + list(APPEND _internal_libraries "${CMAKE_INSTALL_PREFIX}/${PLUGINS_INSTALL_DIR}/$") endforeach() # all other executables get auto detected and fixed. - list(GET INTERNAL_TARGETS 0 INTERNAL_TARGETS) + if(_internal_executables) + list(GET _internal_executables 0 _internal_executables) + endif() INSTALL(CODE " - message(STATUS \"${INTERNAL_TARGETS}\") - message(STATUS \"${INTERNAL_PLUGINS}\") + message(STATUS \"${_internal_executables}\") + message(STATUS \"${_internal_libraries}\") include(BundleUtilities) - fixup_bundle(\"${INTERNAL_TARGETS}\" \"${INTERNAL_PLUGINS}\" \"${ADDITIONAL_LIBARIES_PATHS}\") + fixup_bundle(\"${_internal_executables}\" \"${_internal_libraries}\" \"${ADDITIONAL_LIBARIES_PATHS}\") " COMPONENT MapnikRuntime) endif() diff --git a/cmake/mapnikConfig.cmake.in b/cmake/mapnikConfig.cmake.in index 8e724e9ff..b202abf28 100644 --- a/cmake/mapnikConfig.cmake.in +++ b/cmake/mapnikConfig.cmake.in @@ -9,7 +9,13 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/Modules/") include(CMakeFindDependencyMacro) @MAPNIK_DEPENDENCIES@ - include("${CMAKE_CURRENT_LIST_DIR}/mapnikTargets.cmake") -check_required_components(mapnik) +set(_supported_components @MAPNIK_UTILITIES@) +foreach(_comp ${mapnik_FIND_COMPONENTS}) + if (NOT _comp IN_LIST _supported_components) + set(mapnik_FOUND False) + set(mapnik_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}") + endif() + include("${CMAKE_CURRENT_LIST_DIR}/MapnikUtility_${_comp}_Targets.cmake") +endforeach() diff --git a/demo/c++/CMakeLists.txt b/demo/c++/CMakeLists.txt index a50cd71c2..ffa2cb1a8 100644 --- a/demo/c++/CMakeLists.txt +++ b/demo/c++/CMakeLists.txt @@ -4,7 +4,6 @@ add_executable(mapnik-demo rundemo.cpp) target_link_libraries(mapnik-demo PRIVATE mapnik::agg mapnik::mapnik) -mapnik_install(mapnik-demo) mapnik_copy_plugins(TARGET mapnik-demo DESTINATION plugins/input PLUGINS input-shape) mapnik_require_fonts(TARGET mapnik-demo DESTINATION fonts) mapnik_copy_dependencies(TARGETS mapnik-demo PLUGINS input-shape) diff --git a/demo/viewer/CMakeLists.txt b/demo/viewer/CMakeLists.txt index 9f64da28a..445d5fa78 100644 --- a/demo/viewer/CMakeLists.txt +++ b/demo/viewer/CMakeLists.txt @@ -61,7 +61,7 @@ if(QT_VERSION_MAJOR EQUAL 6) endif() install(FILES ${CMAKE_CURRENT_BINARY_DIR}/viewer.ini DESTINATION bin) -mapnik_install(mapnik-viewer) +mapnik_install_utility(mapnik-viewer) mapnik_copy_dependencies( TARGETS diff --git a/utils/geometry_to_wkb/CMakeLists.txt b/utils/geometry_to_wkb/CMakeLists.txt index 365bb89f7..7266f72c6 100644 --- a/utils/geometry_to_wkb/CMakeLists.txt +++ b/utils/geometry_to_wkb/CMakeLists.txt @@ -4,4 +4,4 @@ add_executable(geometry_to_wkb main.cpp) target_link_libraries(geometry_to_wkb PRIVATE mapnik::mapnik) -mapnik_install(geometry_to_wkb) +mapnik_install_utility(geometry_to_wkb) diff --git a/utils/mapnik-index/CMakeLists.txt b/utils/mapnik-index/CMakeLists.txt index de5dc7d68..22925e1b5 100644 --- a/utils/mapnik-index/CMakeLists.txt +++ b/utils/mapnik-index/CMakeLists.txt @@ -15,4 +15,4 @@ target_link_libraries(mapnik-index PRIVATE Boost::program_options ) -mapnik_install(mapnik-index) +mapnik_install_utility(mapnik-index) diff --git a/utils/mapnik-render/CMakeLists.txt b/utils/mapnik-render/CMakeLists.txt index f655a6fd3..b5e8fa1a5 100644 --- a/utils/mapnik-render/CMakeLists.txt +++ b/utils/mapnik-render/CMakeLists.txt @@ -9,4 +9,4 @@ target_link_libraries(mapnik-render PRIVATE Boost::program_options ) -mapnik_install(mapnik-render) +mapnik_install_utility(mapnik-render) diff --git a/utils/ogrindex/CMakeLists.txt b/utils/ogrindex/CMakeLists.txt index 9b2b4df2a..20ee5cf4e 100644 --- a/utils/ogrindex/CMakeLists.txt +++ b/utils/ogrindex/CMakeLists.txt @@ -4,4 +4,4 @@ add_executable(ogrindex ogrindex.cpp) target_link_libraries(ogrindex PRIVATE mapnik::mapnik) -mapnik_install(ogrindex) +mapnik_install_utility(ogrindex) diff --git a/utils/pgsql2sqlite/CMakeLists.txt b/utils/pgsql2sqlite/CMakeLists.txt index c60e5d597..7d7679987 100644 --- a/utils/pgsql2sqlite/CMakeLists.txt +++ b/utils/pgsql2sqlite/CMakeLists.txt @@ -16,4 +16,4 @@ target_link_libraries(pgsql2sqlite PRIVATE mapnik::mapnik ) -mapnik_install(pgsql2sqlite) +mapnik_install_utility(pgsql2sqlite) diff --git a/utils/shapeindex/CMakeLists.txt b/utils/shapeindex/CMakeLists.txt index e7d2bd9ad..3a8febb16 100644 --- a/utils/shapeindex/CMakeLists.txt +++ b/utils/shapeindex/CMakeLists.txt @@ -12,4 +12,4 @@ target_link_libraries(shapeindex PRIVATE mapnik::mapnik ) -mapnik_install(shapeindex) +mapnik_install_utility(shapeindex) diff --git a/utils/svg2png/CMakeLists.txt b/utils/svg2png/CMakeLists.txt index 76bc72d77..ba2e9c89b 100644 --- a/utils/svg2png/CMakeLists.txt +++ b/utils/svg2png/CMakeLists.txt @@ -12,4 +12,4 @@ target_link_libraries(svg2png PRIVATE mapnik::agg ) -mapnik_install(svg2png) +mapnik_install_utility(svg2png)