diff --git a/cmake/MapnikExport.cmake b/cmake/MapnikExport.cmake index 28d5eef6f..6f69fb7c9 100644 --- a/cmake/MapnikExport.cmake +++ b/cmake/MapnikExport.cmake @@ -1,6 +1,6 @@ include(CMakePackageConfigHelpers) -# set the cmake targets install location +# export mapnik configuration write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/mapnikConfigVersion.cmake" VERSION ${PROJECT_VERSION} @@ -22,6 +22,7 @@ install( DESTINATION ${MAPNIK_CMAKE_DIR} ) +# install our modules, so that the expected target names are found. install( FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindCairo.cmake" @@ -35,3 +36,21 @@ install(EXPORT MapnikTargets FILE mapnikTargets.cmake NAMESPACE mapnik:: ) + + +# Create configuration dependend files for the plugin install dirs. +# some package managers are using different paths per configuration. +string(TOLOWER "${CMAKE_BUILD_TYPE}" _build_type) +string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type_l) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/mapnikPlugins-${_build_type}.cmake.in "set(MAPNIK_PLUGINS_DIR_${_build_type_l} \"@PACKAGE_PLUGINS_INSTALL_DIR@\" CACHE STRING \"\")\n") +include(CMakePackageConfigHelpers) +configure_package_config_file( + ${CMAKE_CURRENT_BINARY_DIR}/mapnikPlugins-${_build_type}.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/mapnikPlugins-${_build_type}.cmake + PATH_VARS PLUGINS_INSTALL_DIR + INSTALL_DESTINATION ${MAPNIK_CMAKE_DIR} +) +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/MapnikPlugins-${_build_type}.cmake + DESTINATION ${MAPNIK_CMAKE_DIR} +) diff --git a/cmake/MapnikInstall.cmake b/cmake/MapnikInstall.cmake index a62a87aa1..4d1d0bb4d 100644 --- a/cmake/MapnikInstall.cmake +++ b/cmake/MapnikInstall.cmake @@ -39,7 +39,7 @@ endfunction() # Install executables. These are available via COMPONENTS in find_package # function(mapnik_install_utility _target) - set(_target_name "MapnikUtility_${_target}_Targets") + set(_target_name "mapnikUtilityTargets_${_target}") install(TARGETS ${_target} EXPORT ${_target_name} INCLUDES DESTINATION ${MAPNIK_INCLUDE_DIR} diff --git a/cmake/mapnikConfig.cmake.in b/cmake/mapnikConfig.cmake.in index 7c4887109..ef5e07c23 100644 --- a/cmake/mapnikConfig.cmake.in +++ b/cmake/mapnikConfig.cmake.in @@ -2,7 +2,6 @@ set_and_check(MAPNIK_INCLUDE_DIR "@PACKAGE_MAPNIK_INCLUDE_DIR@" CACHE STRING "") set_and_check(MAPNIK_FONTS_DIR "@PACKAGE_FONTS_INSTALL_DIR@" CACHE STRING "") -set(MAPNIK_PLUGINS_DIR "@PACKAGE_PLUGINS_INSTALL_DIR@" CACHE STRING "") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/Modules/") @@ -17,5 +16,35 @@ foreach(_comp ${mapnik_FIND_COMPONENTS}) set(mapnik_FOUND False) set(mapnik_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}") endif() - include("${CMAKE_CURRENT_LIST_DIR}/MapnikUtility_${_comp}_Targets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/mapnikUtilityTargets_${_comp}.cmake") endforeach() + + +get_filename_component(_plugin_dir "${CMAKE_CURRENT_LIST_FILE}" PATH) +file(GLOB CONFIG_FILES "${_plugin_dir}/mapnikPlugins-*.cmake") +foreach(f ${CONFIG_FILES}) + include(${f}) +endforeach() + +function(mapnik_find_plugin_dir PLUGIN_DIR) + string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type_l) + set(_plugin_dir "${MAPNIK_PLUGINS_DIR_${_build_config}}") + # only release has more then one configuration + if(NOT _plugin_dir) + set(_all_rel_cfgs RELEASE RELWITHDEBINFO MINSIZEREL) + list(FIND _all_rel_cfgs ${_build_config} _is_rel_cfg) + # check if the current configuration is a known release configuration + if(${_is_rel_cfg} GREATER_EQUAL 0) + foreach(_rel_cfg IN LISTS _all_rel_cfgs) + set(_plugin_dir "${MAPNIK_PLUGINS_DIR_${_rel_cfg}}") + if(_plugin_dir) + break() + endif() + endforeach() + endif() + endif() + if(NOT _plugin_dir) + message(WARNING "Could not find a plugin install dir for configuration ${_build_type_l}") + endif() + set(${PLUGIN_DIR} ${_plugin_dir} PARENT_SCOPE) +endfunction() diff --git a/docs/cmake-usage.md b/docs/cmake-usage.md index 32088992c..2c646b2d3 100644 --- a/docs/cmake-usage.md +++ b/docs/cmake-usage.md @@ -34,10 +34,16 @@ All targets: * `mapnik::wkt`: wkt support for libmapnik. All mapnik executables and targets are exported within `mapnikTargets.cmake`. - -The plugin dir is available in the variable `MAPNIK_PLUGINS_DIR`. The font path is is available in the variable `MAPNIK_FONTS_DIR`. +The install location of the plugins might be configuration dependent. +For each configuration there exists a variable `MAPNIK_PLUGINS_DIR_` where `` is one of `CMAKE_BUILD_TYPE` as upper case. +There is a function exported which you can use to query the plugin dir for known typical configurations: +``` +mapnik_find_plugin_dir(MAPNIK_PLUGINS_DIR) +``` +`MAPNIK_PLUGINS_DIR` will contain then the plugin dir. If a path could not be found, a warning is printed. + ## 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.