Skip to content

Commit

Permalink
Merge pull request mapnik#4191 from mathisloge/cmake-support
Browse files Browse the repository at this point in the history
CMake build support
  • Loading branch information
artemp authored Aug 30, 2021
2 parents f5bac0b + dde791c commit ed03ca8
Show file tree
Hide file tree
Showing 57 changed files with 2,578 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.vscode
*.gcov
*.gcda
*.gcno
Expand Down Expand Up @@ -56,3 +57,8 @@ demo/viewer/ui_layer_info.h
test/standalone/*-bin
test/unit/run
test/visual/run
# cmake
build
.vs

CMakeUserPresets.json
452 changes: 452 additions & 0 deletions CMakeLists.txt

Large diffs are not rendered by default.

176 changes: 176 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"version": 2,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "use-ninja",
"hidden": true,
"generator": "Ninja"
},
{
"name": "default-build-dir",
"hidden": true,
"binaryDir": "${sourceDir}/build/${presetName}"
},
{
"name": "debug-build",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"USE_DEBUG_OUTPUT": "ON",
"USE_LOG": "ON",
"USE_LOG_SEVERITY": "0"
}
},
{
"name": "release-build",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"USE_DEBUG_OUTPUT": "OFF",
"USE_LOG": "OFF"
}
},
{
"name": "use-clang",
"hidden": true,
"inherits": [
"default-build-dir",
"use-ninja"
],
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_CXX_FLAGS": "-stdlib=libc++",
"CMAKE_EXE_LINKER_FLAGS": "-stdlib=libc++",
"CMAKE_SHARED_LINKER_FLAGS": "-stdlib=libc++"
}
},
{
"name": "use-gcc",
"hidden": true,
"inherits": [
"default-build-dir",
"use-ninja"
],
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++"
}
},
{
"name": "use-msvc-cl",
"hidden": true,
"inherits": [
"default-build-dir",
"use-ninja"
],
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl"
}
},
{
"name": "use-msvc-clang-cl",
"hidden": true,
"inherits": [
"default-build-dir",
"use-ninja"
],
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl"
}
},
{
"name": "linux-clang-debug",
"displayName": "Linux clang debug",
"inherits": [
"use-clang",
"debug-build"
]
},
{
"name": "linux-clang-release",
"displayName": "Linux clang release",
"inherits": [
"use-clang",
"release-build"
]
},
{
"name": "linux-gcc-debug",
"displayName": "Linux gcc debug",
"inherits": [
"use-gcc",
"debug-build"
]
},
{
"name": "linux-gcc-release",
"displayName": "Linux gcc release",
"inherits": [
"use-gcc",
"release-build"
]
},
{
"name": "windows-arch-x64",
"hidden": true,
"architecture": {
"value": "x64",
"strategy": "external"
},
"toolset": {
"value": "host=x64",
"strategy": "external"
}
},
{
"name": "windows-default",
"displayName": "Windows x64 Debug",
"hidden": true,
"inherits": [
"use-msvc-cl",
"windows-arch-x64"
],
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [
"Windows"
]
}
}
},
{
"name": "windows-default-debug",
"displayName": "Windows x64 Debug",
"inherits": [
"windows-default",
"debug-build"
]
},
{
"name": "windows-default-release",
"displayName": "Windows x64 Release",
"inherits": [
"windows-default",
"release-build"
]
}
],
"buildPresets": [
{
"name": "windows-default",
"configurePreset": "windows-default-debug"
},
{
"name": "linux-default",
"configurePreset": "linux-clang-debug"
}
]
}
7 changes: 7 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Mapnik runs on Linux, OS X, Windows, and BSD systems.

## Package managers
### vcpkg
To install mapnik with vcpkg type `vcpkg install mapnik`. It will install a minimal version of mapnik and all the needed dependencies.
To install more features, type `vcpkg search mapnik` to see all available features.

## Source build

First clone mapnik from github and initialize submodules

```bash
Expand Down
55 changes: 55 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
project(mapnik-benchmark)

set(BENCHMARK_SRCS
src/normalize_angle.cpp
src/test_array_allocation.cpp
src/test_expression_parse.cpp
src/test_face_ptr_creation.cpp
src/test_font_registration.cpp
src/test_getline.cpp
src/test_marker_cache.cpp
src/test_noop_rendering.cpp
src/test_numeric_cast_vs_static_cast.cpp
src/test_offset_converter.cpp
src/test_png_encoding1.cpp
src/test_png_encoding2.cpp
src/test_polygon_clipping_rendering.cpp
src/test_polygon_clipping.cpp
src/test_proj_transform1.cpp
src/test_quad_tree.cpp
src/test_rendering_shared_map.cpp
src/test_rendering.cpp
src/test_to_bool.cpp
src/test_to_double.cpp
src/test_to_int.cpp
src/test_to_string1.cpp
src/test_to_string2.cpp
src/test_utf_encoding.cpp
)
function(mapnik_create_benchmark)
get_filename_component(BENCHNAME ${ARGV0} NAME_WE)
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)

mapnik_copy_dependencies(TARGETS ${TARGET_NAME})
endfunction()

foreach(benchmark ${BENCHMARK_SRCS})
mapnik_create_benchmark(${benchmark})
endforeach()

# we just need one target to reference the directory correctly. mapnik-benchmark-normalize_angle is just the first in BENCHMARK_SRCS
mapnik_require_fonts(TARGET mapnik-benchmark-normalize_angle DESTINATION fonts)
# copy all plugins
mapnik_copy_plugins(TARGET mapnik-benchmark-normalize_angle
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
)
# copy all plugin dlls.
mapnik_copy_dependencies(TARGETS mapnik-benchmark-normalize_angle
PLUGINS
input-csv input-gdal input-geobuf input-geojson input-ogr input-pgraster input-postgis input-raster input-shape input-sqlite input-topojson
)
1 change: 1 addition & 0 deletions benchmark/include/bench_framework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <set>
#include <sstream>
#include <thread>
#include <mutex>
#include <vector>

namespace benchmark {
Expand Down
38 changes: 38 additions & 0 deletions cmake/CopyDllsForDebug.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This is a helper script to run BundleUtilities fixup_bundle as postbuild
# for a target. The primary use case is to copy .DLLs to the build directory for
# the Windows platform. It allows generator expressions to be used to determine
# the binary location
#
# Usage : copy_dlls_for_debug TARGET LIBS DIRS
# - TARGET : A cmake target
# - See fixup_bundle for LIBS and DIRS arguments

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)
set(options)
set(oneValueArgs)
set(multiValueArgs TARGETS LIBS DIRS)
cmake_parse_arguments(MAPNIK_COPY_DLLS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(WIN32)
foreach(_target IN LISTS MAPNIK_COPY_DLLS_TARGETS)
add_custom_command(
TARGET ${_target} POST_BUILD
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}"
)
endforeach()
endif(WIN32)
endfunction()

endif()
Loading

0 comments on commit ed03ca8

Please sign in to comment.