From ce8bd250dd9c959142d381d86d8fa592a6f7f76d Mon Sep 17 00:00:00 2001 From: Mathis Logemann Date: Thu, 25 Aug 2022 19:59:29 +0200 Subject: [PATCH] better export [wip] --- CMakeLists.txt | 10 +++---- cmake/MapnikExport.cmake | 19 ++++++++++-- cmake/MapnikFindPackage.cmake | 54 ++++++++++++++++++++++++----------- cmake/mapnikConfig.cmake.in | 2 +- 4 files changed, 61 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc09aa516..f21e36748 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,7 +148,7 @@ else() endif() -find_package(PkgConfig) +mapnik_find_package(PkgConfig REQUIRED) mapnik_find_threads() mapnik_find_package(ICU REQUIRED COMPONENTS uc i18n data) @@ -177,7 +177,7 @@ else() # It might be possible that in future version harfbuzz could only be found via pkg-config. # harfbuzz related discussion: https://github.com/harfbuzz/harfbuzz/issues/2653 message(STATUS "harfbuzz not found via cmake. Searching via pkg-config...") - pkg_check_modules(harfbuzz REQUIRED IMPORTED_TARGET harfbuzz>=${HARFBUZZ_MIN_VERSION}) + mapnik_pkg_check_modules(harfbuzz REQUIRED IMPORTED_TARGET harfbuzz>=${HARFBUZZ_MIN_VERSION}) list(APPEND MAPNIK_OPTIONAL_LIBS PkgConfig::harfbuzz) endif() @@ -304,13 +304,13 @@ if(USE_TIFF) endif() if(USE_WEBP) - pkg_check_modules(WebP REQUIRED IMPORTED_TARGET libwebp) + mapnik_pkg_check_modules(WebP REQUIRED IMPORTED_TARGET libwebp) list(APPEND MAPNIK_COMPILE_DEFS HAVE_WEBP) list(APPEND MAPNIK_OPTIONAL_LIBS PkgConfig::WebP) endif() if(USE_CAIRO) - pkg_check_modules(Cairo REQUIRED IMPORTED_TARGET cairo) + mapnik_pkg_check_modules(Cairo REQUIRED IMPORTED_TARGET cairo) list(APPEND MAPNIK_COMPILE_DEFS HAVE_CAIRO) list(APPEND MAPNIK_OPTIONAL_LIBS PkgConfig::Cairo) endif() @@ -321,7 +321,7 @@ if(USE_PROJ) # currently the cmake files are not installed, when installing proj via apt-get. So search via pkg-config if(NOT PROJ_FOUND) message(STATUS "PROJ not found via FindPROJ. Searching via pkg-config...") - pkg_check_modules(PROJ REQUIRED IMPORTED_TARGET proj>=${PROJ_MIN_VERSION}) + mapnik_pkg_check_modules(PROJ REQUIRED IMPORTED_TARGET proj>=${PROJ_MIN_VERSION}) string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" _dummy "${PROJ_VERSION}") set(PROJ_VERSION_MAJOR "${CMAKE_MATCH_1}") set(PROJ_VERSION_MINOR "${CMAKE_MATCH_2}") diff --git a/cmake/MapnikExport.cmake b/cmake/MapnikExport.cmake index 267c64f9f..34c5573b7 100644 --- a/cmake/MapnikExport.cmake +++ b/cmake/MapnikExport.cmake @@ -9,11 +9,26 @@ function(mapnik_export_cmake_config) COMPATIBILITY ExactVersion ) get_property(MAPNIK_UTILITIES GLOBAL PROPERTY MAPNIK_UTILITIES) - list(JOIN MAPNIK_DEPENDENCIES "\n" MAPNIK_DEPENDENCIES) + + # generate all find_dependency and pkg_config calls + set(mapnik_find_deps) + foreach(dep IN LISTS mapnik_deps) + set(ver_comment "# ${dep} used with version ${mapnik_${dep}_version}") + set(mapnik_find_deps "${mapnik_find_deps}\n${ver_comment}\n") + if(mapnik_${dep}_find_args) + list(REMOVE_DUPLICATES mapnik_${dep}_find_args) + list(JOIN mapnik_${dep}_find_args " " m_args_joined) + set(mapnik_find_deps "${mapnik_find_deps}find_dependency(${dep} ${m_args_joined})") + else() + list(JOIN mapnik_${dep}_pkg_args " " m_args_joined) + set(mapnik_find_deps "${mapnik_find_deps}pkg_check_modules(${dep} ${m_args_joined})") + endif() + endforeach() + 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 MAPNIK_INCLUDE_DIR PLUGINS_INSTALL_DIR FONTS_INSTALL_DIR MAPNIK_DEPENDENCIES MAPNIK_UTILITIES + PATH_VARS MAPNIK_INCLUDE_DIR PLUGINS_INSTALL_DIR FONTS_INSTALL_DIR mapnik_find_deps MAPNIK_UTILITIES NO_CHECK_REQUIRED_COMPONENTS_MACRO ) install( diff --git a/cmake/MapnikFindPackage.cmake b/cmake/MapnikFindPackage.cmake index ed2997f23..e80ad44c1 100644 --- a/cmake/MapnikFindPackage.cmake +++ b/cmake/MapnikFindPackage.cmake @@ -1,28 +1,50 @@ -macro(mapnik_print_version) - string(TOUPPER ${ARGV0} m_package_name_upc) - set(m_package_name ${ARGV0}) +function(mapnik_set_dep_version dep var) + string(TOUPPER ${dep} m_package_name_upc) + set(m_package_name ${dep}) if(${m_package_name}_VERSION_STRING) - message(STATUS "Using ${m_package_name} version: ${${m_package_name}_VERSION_STRING}") + set(${var} ${${m_package_name}_VERSION_STRING} PARENT_SCOPE) elseif(${m_package_name}_VERSION) - message(STATUS "Using ${m_package_name} version: ${${m_package_name}_VERSION}") + set(${var} ${${m_package_name}_VERSION} PARENT_SCOPE) elseif(${m_package_name_upc}_VERSION_STRING) - message(STATUS "Using ${m_package_name} version: ${${m_package_name_upc}_VERSION_STRING}") + set(${var} ${${m_package_name_upc}_VERSION_STRING} PARENT_SCOPE) elseif(${m_package_name_upc}_VERSION) - message(STATUS "Using ${m_package_name} version: ${${m_package_name_upc}_VERSION}") + set(${var} ${${m_package_name_upc}_VERSION} PARENT_SCOPE) + endif() +endfunction() + +function(mapnik_print_package_info dep) + message(STATUS "Using ${dep} version: ${mapnik_${dep}_version}") +endfunction() + +macro(mapnik_find_package dep) + find_package(${dep} ${ARGN}) + if(${dep}_FOUND) + list(APPEND mapnik_deps ${dep}) + + if(mapnik_${dep}_find_args) + list(APPEND mapnik_${dep}_find_args ${ARGN}) + else() + set(mapnik_${dep}_find_args ${ARGN}) + endif() + mapnik_set_dep_version(${dep} mapnik_${dep}_version) + + mapnik_print_package_info(${dep}) else() - message(STATUS "Using ${m_package_name}") + message(STATUS "not found: ${dep}") endif() endmacro() -macro(mapnik_find_package) - find_package(${ARGN}) - if(${ARGV0}_FOUND) - set(MAPNIK_TMP_DEP ${ARGN}) - list(JOIN MAPNIK_TMP_DEP " " MAPNIK_TMP_DEP) - list(APPEND MAPNIK_DEPENDENCIES "find_dependency(${MAPNIK_TMP_DEP})") - mapnik_print_version(${ARGV0}) +macro(mapnik_pkg_check_modules dep) + pkg_check_modules(${dep} ${ARGN}) + if(${dep}_FOUND) + list(APPEND mapnik_deps ${dep}) + + set(mapnik_${dep}_pkg_args ${ARGN}) + mapnik_set_dep_version(${dep} mapnik_${dep}_version) + + mapnik_print_package_info(${dep}) else() - message(STATUS "not found: ${ARGV0}") + message(STATUS "not found: ${dep}") endif() endmacro() diff --git a/cmake/mapnikConfig.cmake.in b/cmake/mapnikConfig.cmake.in index e5553f964..5ec8e38a3 100644 --- a/cmake/mapnikConfig.cmake.in +++ b/cmake/mapnikConfig.cmake.in @@ -8,7 +8,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/Modules/") include(CMakeFindDependencyMacro) find_dependency(Threads REQUIRED) -@MAPNIK_DEPENDENCIES@ +@mapnik_find_deps@ include("${CMAKE_CURRENT_LIST_DIR}/mapnikTargets.cmake")