fixed Dll copying on windows; copy plugins and fonts into appropiate directories when building.

This commit is contained in:
Mathis Logemann 2021-04-09 15:50:50 +02:00
parent b6d8f54779
commit 02f78e4ce5
7 changed files with 113 additions and 32 deletions

View file

@ -16,8 +16,9 @@ message(STATUS "mapnik version: ${PROJECT_VERSION}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(MapnikFindPackage)
include(MapnikCopyDependencies)
set(ADDITIONAL_LIBARIES_PATHS "" CACHE STRING "currently only used on windows. Pass directories containing the dlls that are missing. You can ignore this, if the build (verify_app step) runs successfully" "")
set(ADDITIONAL_LIBARIES_PATHS "" CACHE STRING "currently only used on windows. Pass directories containing the dlls that are missing. You can ignore this, if the build (verify_app step) runs successfully")
option(COPY_LIBRARIES_FOR_EXECUTABLES "copies required shared libaries (currently only windows) to the executable directory" ON)
option(BUILD_SHARED_LIBS "build mapnik dynamic(ON) or static(OFF)" ON)

View file

@ -26,18 +26,26 @@ set(BENCHMARK_SRCS
src/test_to_string2.cpp
src/test_utf_encoding.cpp
)
macro(mapnik_create_benchmark)
function(mapnik_create_benchmark)
get_filename_component(BENCHNAME ${ARGV0} NAME_WE)
add_executable(mapnik-benchmark-${BENCHNAME} ${ARGV0})
target_include_directories(mapnik-benchmark-${BENCHNAME} PRIVATE include)
target_link_libraries(mapnik-benchmark-${BENCHNAME} PRIVATE mapnik::core mapnik::agg mapnik::mapnik)
set(TARGET_NAME "mapnik-benchmark-${BENCHNAME}")
add_executable(${TARGET_NAME} ${ARGV0})
target_include_directories(${TARGET_NAME} PRIVATE include)
target_link_libraries(${TARGET_NAME} PRIVATE mapnik::core mapnik::agg mapnik::mapnik)
# it might be possible that some buildsystems generate different directories. So invoke the scripts for all benchmarks
mapnik_copy_plugins(TARGET ${TARGET_NAME}
DESTINATION plugins/input
PLUGINS
input-csv input-gdal input-geobuf input-geojson input-ogr input-pgraster input-postgis input-raster input-shape input-sqlite input-topojson
)
mapnik_require_fonts(TARGET ${TARGET_NAME} mapnik-test-unit DESTINATION fonts)
if(COPY_LIBRARIES_FOR_EXECUTABLES AND WIN32)
include(CopyDllsForDebug)
add_custom_command(TARGET mapnik-benchmark-${BENCHNAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:mapnik::mapnik>" ${CMAKE_CURRENT_BINARY_DIR})
copy_dlls_for_debug(mapnik-benchmark-${BENCHNAME} \"\" \"${ADDITIONAL_LIBARIES_PATHS}\")
endif()
endmacro()
mapnik_copy_dependencies(TARGETS ${TARGET_NAME}
PLUGINS
input-csv input-gdal input-geobuf input-geojson input-ogr input-pgraster input-postgis input-raster input-shape input-sqlite input-topojson
)
endfunction()
foreach(benchmark ${BENCHMARK_SRCS})
mapnik_create_benchmark(${benchmark})

View file

@ -11,19 +11,25 @@ if(RUN_IT)
# Script ran by the add_custom_command
include(BundleUtilities)
include(InstallRequiredSystemLibraries)
string (REPLACE " " ";" TO_FIXUP_LIBS "${TO_FIXUP_LIBS}")
string (REPLACE " " ";" TO_FIXUP_DIRS "${TO_FIXUP_DIRS}")
#message(STATUS "${TO_FIXUP_FILE} ${TO_FIXUP_LIBS} ${TO_FIXUP_DIRS}")
fixup_bundle("${TO_FIXUP_FILE}" "${TO_FIXUP_LIBS}" "${TO_FIXUP_DIRS}")
# End of script ran by the add_custom_command
else()
set(THIS_FILE ${CMAKE_CURRENT_LIST_FILE})
function(copy_dlls_for_debug _targets _libs _dirs)
function(copy_dlls_for_debug)
set(options)
set(oneValueArgs)
set(multiValueArgs TARGETS LIBS DIRS)
cmake_parse_arguments(MAPNIK_COPY_DLLS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(WIN32)
foreach(_target ${_targets})
foreach(_target IN LISTS MAPNIK_COPY_DLLS_TARGETS)
add_custom_command(
TARGET ${_target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -DRUN_IT:BOOL=ON -DTO_FIXUP_FILE=$<TARGET_FILE:${_target}> -DTO_FIXUP_LIBS=${_libs} -DTO_FIXUP_DIRS=${_dirs} -P ${THIS_FILE}
COMMAND ${CMAKE_COMMAND} ARGS -DRUN_IT:BOOL=ON -DTO_FIXUP_FILE="$<TARGET_FILE:${_target}>" -DTO_FIXUP_LIBS:STRING="${MAPNIK_COPY_DLLS_LIBS}" -DTO_FIXUP_DIRS="${MAPNIK_COPY_DLLS_DIRS}" -P "${THIS_FILE}"
COMMENT "Fixing up dependencies for ${_target}"
VERBATIM
)
endforeach()
endif(WIN32)

View file

@ -0,0 +1,58 @@
function(mapnik_find_target_location)
set(options)
set(multiValueArgs TARGETS)
cmake_parse_arguments( WIG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
endfunction()
function(mapnik_copy_dependencies)
if(COPY_LIBRARIES_FOR_EXECUTABLES AND WIN32)
set(options)
set(oneValueArgs)
set(multiValueArgs TARGETS PLUGINS)
cmake_parse_arguments(MAPNIK_CP_DEPS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
include(CopyDllsForDebug)
foreach(TARGET IN LISTS MAPNIK_CP_DEPS_TARGETS)
add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:mapnik::mapnik>" ${CMAKE_CURRENT_BINARY_DIR})
endforeach()
set(LIBS "")
foreach(PLUGIN IN LISTS MAPNIK_CP_DEPS_PLUGINS)
if(TARGET ${PLUGIN}) # only copy plugins that are be build
list(APPEND LIBS "$<TARGET_FILE:${PLUGIN}>")
endif()
endforeach()
copy_dlls_for_debug(TARGETS ${MAPNIK_CP_DEPS_TARGETS} LIBS ${LIBS} DIRS ${ADDITIONAL_LIBARIES_PATHS})
endif()
endfunction()
function(mapnik_copy_plugins)
set(options)
set(oneValueArgs TARGET DESTINATION)
set(multiValueArgs PLUGINS)
cmake_parse_arguments(MAPNIK_CP_PLG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# copy_if_different requires a existing directory.
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${MAPNIK_CP_PLG_DESTINATION})
foreach(PLUGIN IN LISTS MAPNIK_CP_PLG_PLUGINS)
#message(STATUS "copying plugin ${PLUGIN} to path: ${CMAKE_CURRENT_BINARY_DIR}/${MAPNIK_CP_PLG_DESTINATION}")
if(TARGET ${PLUGIN})
add_custom_command(TARGET ${MAPNIK_CP_PLG_TARGET} POST_BUILD COMMAND
${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:${PLUGIN}>" ${CMAKE_CURRENT_BINARY_DIR}/${MAPNIK_CP_PLG_DESTINATION}/)
else()
message(NOTICE "${MAPNIK_CP_PLG_TARGET} requires plugin ${PLUGIN} but it isn't build. Check USE_PLUGIN_INPUT_ options to enable the plugin.")
endif()
endforeach()
endfunction()
function(mapnik_require_fonts)
set(options)
set(oneValueArgs TARGET DESTINATION)
set(multiValueArgs)
cmake_parse_arguments(MAPNIK_REQUIRE_FONTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
add_custom_command(TARGET ${MAPNIK_REQUIRE_FONTS_TARGET} POST_BUILD COMMAND
${CMAKE_COMMAND} -E copy_directory ${mapnik_SOURCE_DIR}/fonts ${CMAKE_CURRENT_BINARY_DIR}/${MAPNIK_REQUIRE_FONTS_DESTINATION}/)
endfunction()

View file

@ -10,8 +10,6 @@ install(TARGETS mapnik-demo
RUNTIME DESTINATION ${MAPNIK_BIN_DIR}
)
if(COPY_LIBRARIES_FOR_EXECUTABLES AND WIN32)
include(CopyDllsForDebug)
add_custom_command(TARGET mapnik-demo POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:mapnik::mapnik>" ${CMAKE_CURRENT_BINARY_DIR})
copy_dlls_for_debug(mapnik-demo \"\" \"${ADDITIONAL_LIBARIES_PATHS}\")
endif()
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)

View file

@ -45,9 +45,9 @@ install(TARGETS mapnik-viewer
RUNTIME DESTINATION ${MAPNIK_BIN_DIR}
)
if(COPY_LIBRARIES_FOR_EXECUTABLES AND WIN32)
include(CopyDllsForDebug)
add_custom_command(TARGET mapnik-viewer POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:mapnik::mapnik>" ${CMAKE_CURRENT_BINARY_DIR})
copy_dlls_for_debug(mapnik-viewer \"\" \"${ADDITIONAL_LIBARIES_PATHS}\")
endif()
mapnik_copy_dependencies(
TARGETS
mapnik-viewer
PLUGINS
input-csv input-gdal input-geobuf input-geojson input-ogr input-pgraster input-postgis input-raster input-shape input-sqlite input-topojson
)

View file

@ -173,12 +173,22 @@ include(CTest)
include(${catch2_SOURCE_DIR}/contrib/Catch.cmake)
include(${catch2_SOURCE_DIR}/contrib/ParseAndAddCatchTests.cmake)
if(COPY_LIBRARIES_FOR_EXECUTABLES AND WIN32)
include(CopyDllsForDebug)
add_custom_command(TARGET mapnik-test-unit POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:mapnik::mapnik>" ${CMAKE_CURRENT_BINARY_DIR})
set(APPS mapnik-test-unit agg_rasterizer_integer_overflow_test datasource_registration_test font_registration_test map_xml_test mapnik-test-visual)
copy_dlls_for_debug(${APPS} \"\" \"${ADDITIONAL_LIBARIES_PATHS}\")
endif()
# use only mapnik-test-unit since it has the same build path
mapnik_copy_plugins(
TARGET mapnik-test-unit
DESTINATION plugins/input
PLUGINS
input-csv input-gdal input-geobuf input-geojson input-ogr input-pgraster input-postgis input-raster input-shape input-sqlite input-topojson
)
mapnik_require_fonts(TARGET mapnik-test-unit DESTINATION fonts)
mapnik_copy_dependencies(
TARGETS
mapnik-test-unit agg_rasterizer_integer_overflow_test datasource_registration_test font_registration_test map_xml_test mapnik-test-visual
PLUGINS
input-csv input-gdal input-geobuf input-geojson input-ogr input-pgraster input-postgis input-raster input-shape input-sqlite input-topojson
)
file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test)
file(COPY data-visual DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test)