diff --git a/.github/actions/run_tests/action.yml b/.github/actions/run_tests/action.yml index 44db0d99b..14b7fe91e 100644 --- a/.github/actions/run_tests/action.yml +++ b/.github/actions/run_tests/action.yml @@ -27,14 +27,14 @@ runs: - name: Test visuals (windows) continue-on-error: true - working-directory: build/${{ inputs.cmake-preset }}/out + working-directory: build/out shell: "pwsh" if: runner.os == 'Windows' run: OpenCppCoverage --modules *libmapnik* --modules mapnik*.exe --modules *.input --sources ${{ github.workspace }} --export_type binary --input_coverage=${{ github.workspace }}/ctest.cov --cover_children -- .\mapnik-test-visual.exe -j (Get-CimInstance -ClassName Win32_ComputerSystem).NumberOfLogicalProcessors --output-dir ./visual-test-result - name: Test visuals (linux & mac) continue-on-error: true - working-directory: build/${{ inputs.cmake-preset }}/out + working-directory: build/out shell: "bash" if: runner.os != 'Windows' run: | @@ -45,7 +45,7 @@ runs: fi - name: Pack visual test results - working-directory: build/${{ inputs.cmake-preset }}/out + working-directory: build/out shell: "pwsh" run: tar cfvz visual-test-results.tar.gz ./visual-test-result @@ -60,16 +60,16 @@ runs: uses: actions/upload-artifact@v3 with: name: ${{ inputs.cmake-preset }}-visual-tests-${{ steps.run-guid.outputs.GUID }} - path: build/${{ inputs.cmake-preset }}/out/visual-test-results.tar.gz + path: build/out/visual-test-results.tar.gz - name: Run Benchmarks - working-directory: build/${{ inputs.cmake-preset }}/out + working-directory: build/out if: runner.os != 'Windows' shell: "pwsh" run: ./run_benchmarks - name: Collect coverage (linux & macos) - working-directory: build/${{ inputs.cmake-preset }} + working-directory: build if: runner.os != 'Windows' shell: "bash" run: | @@ -81,10 +81,10 @@ runs: if: runner.os != 'Windows' uses: codecov/codecov-action@v3 with: - files: build/${{ inputs.cmake-preset }}/coverage.info + files: build/coverage.info - name: Upload coverage to Codecov (windows) if: runner.os == 'Windows' uses: codecov/codecov-action@v3 with: - files: build/${{ inputs.cmake-preset }}/out/mapnik-test-visual.cov + files: build/out/mapnik-test-visual.cov diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 8fda668c2..8186fbfbb 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -32,6 +32,7 @@ jobs: matrix: os: [macos-latest, windows-latest, ubuntu-latest] memory-mapped: ["OFF", "ON"] + static-build: ["OFF", "ON"] include: - os: ubuntu-latest mono: mono @@ -82,7 +83,7 @@ jobs: echo "PRESET=${{ steps.lc_platform.outputs.lowercase }}-ci" >>${GITHUB_ENV} - name: Configure CMake - run: cmake -DUSE_MEMORY_MAPPED_FILE=${{ matrix.memory-mapped }} --preset ${{ env.PRESET }} + run: cmake -DUSE_MEMORY_MAPPED_FILE=${{ matrix.memory-mapped }} -DBUILD_SHARED_LIBS=${{ matrix.static-build }} --preset ${{ env.PRESET }} - name: Build run: cmake --build --preset ${{ env.PRESET }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 57ebfda65..5e3ec9b22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,12 @@ For a complete change history, see the git log. #### Notice - Mapnik now requires C++14 compliant compiler (`-std=c++14`) +- Mapnik now supports CMake as a build system. See [#4191](https://github.com/mapnik/mapnik/pull/4191) and the [docs](https://github.com/mapnik/mapnik/blob/master/docs/cmake-usage.md) for more info. + +#### Breaking Changes + +- Reworked datasource plugin system. Plugins now need to implement a class with the macros in `datasource_plugin.hpp` ([#4291](https://github.com/mapnik/mapnik/pull/4291)) +- mapnik now has a global `mapnik::setup()` method which have to be called before any other functions of mapnik. Defined in `mapnik.hpp`. Currently there is a auto setup functionality. It can be disabled using the cmake option `DISABLE_MAPNIK_AUTOSETUP=ON`. Note: In order not to insert this change into every code base, it is currently still called during the dynamic initialisation time. However, if mapnik is compiled statically, this function must be called. ([#4291](https://github.com/mapnik/mapnik/pull/4291)) #### Core @@ -27,6 +33,8 @@ For a complete change history, see the git log. - Slightly improved `sql_utils::table_from_sql` ([2587bb3](https://github.com/mapnik/mapnik/commit/2587bb3a1d8db397acfa8dcc2d332da3a8a9399f)) - Added wrappers for proper quoting in SQL query construction: `sql_utils::identifier`, `sql_utils::literal` ([7b21713](https://github.com/mapnik/mapnik/commit/7b217133e2749b82c2638551045c4edbece15086)) - Added two-argument `sql_utils::unquote`, `sql_utils::unquote_copy` that also collapse inner quotes ([a4e8ea2](https://github.com/mapnik/mapnik/commit/a4e8ea21be297d89bbf36ba594d6c661a7a9ac81)) +- Fixed mapnik static build with static plugins ([#4291](https://github.com/mapnik/mapnik/pull/4291)) +- Reworked mapnik::enumeration<...> ([#4372](https://github.com/mapnik/mapnik/pull/4372)) #### Plugins diff --git a/CMakeLists.txt b/CMakeLists.txt index d87a7052d..31510c913 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ message(STATUS "mapnik version: ${PROJECT_VERSION}") # https://cliutils.gitlab.io/modern-cmake/chapters/features/ides.html set_property(GLOBAL PROPERTY USE_FOLDERS ON) +set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL ON) # with newer cmake versions put all find_package in global scope set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(FeatureSummary) include(MapnikOption) @@ -27,8 +28,13 @@ include(CTest) add_feature_info(BUILD_TESTING BUILD_TESTING "Adds tests") mapnik_option(INSTALL_DEPENDENCIES "if ON, all dependencies (eg. required dlls) will be copied into CMAKE_INSTALL_PREFIX/MAPNIK_BIN_DIR." ON) - mapnik_option(BUILD_SHARED_LIBS "build mapnik dynamic(ON) or static(OFF)" ON) +mapnik_option(BUILD_SHARED_PLUGINS "build dynamic plugins" ${BUILD_SHARED_LIBS}) # use BUILD_SHARED_LIBS as default option +mapnik_option(BUILD_SHARED_CRT "(only windows with msvc) use msvc shared crt" ON) +if(WIN32 AND BUILD_SHARED_PLUGINS AND NOT BUILD_SHARED_LIBS) + message(FATAL_ERROR "static libmapnik and dynamic plugins won't work correctly") +endif() + mapnik_option(USE_EXTERNAL_MAPBOX_GEOMETRY "Use a external mapnik/geometry.hpp. If off, use the submodule" OFF) mapnik_option(USE_EXTERNAL_MAPBOX_POLYLABEL "Use a external mapnik/polylabel. If off, use the submodule" OFF) mapnik_option(USE_EXTERNAL_MAPBOX_PROTOZERO "Use a external mapnik/protozero. If off, use the submodule" OFF) @@ -56,6 +62,8 @@ mapnik_option(USE_LOG "enables logging output. See log severity level." OFF) set(USE_LOG_SEVERITY "1" CACHE STRING "sets the logging severity (only applies when USE_LOG is ON") mapnik_option(USE_STATS "Enable statistics reporting" OFF) +mapnik_option(DISABLE_MAPNIK_AUTOSETUP "disables the autosetup. Need to call mapnik::setup() then" OFF) + mapnik_option(USE_PLUGIN_INPUT_CSV "adds plugin input csv" ON) mapnik_option(USE_PLUGIN_INPUT_GDAL "adds plugin input gdal" ON) mapnik_option(USE_PLUGIN_INPUT_GEOBUF "adds plugin input geobuf" ON) @@ -87,18 +95,6 @@ mapnik_option(USE_GLIBC_WORKAROUND "see https://github.com/mapnik/mapnik/pull/37 feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES) feature_summary(FILENAME "${CMAKE_CURRENT_BINARY_DIR}/features.log" WHAT ENABLED_FEATURES DISABLED_FEATURES) -set(CMAKE_CXX_STANDARD 14 CACHE STRING "Sets the c++ standard. c++14 is minimum.") -message(STATUS "Using c++${CMAKE_CXX_STANDARD}") -# https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html -set(CXX_EXTENSIONS OFF CACHE STRING "Enables the compiler specific extensions.") # Fallsback to -std=c++ if off -message(STATUS "Using c++ extensions: ${CXX_EXTENSIONS}") -# https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD_REQUIRED.html#prop_tgt:CXX_STANDARD_REQUIRED -set(CXX_STANDARD_REQUIRED ON) # require the specified CMAKE_CXX_STANDARD - -# add debug postfix to the libraries -set(MAPNIK_DEBUG_POSTFIX "d" CACHE STRING "sets the debug library postfix on mapnik, wkt and json") -message(STATUS "postfix for debug libraries: ${MAPNIK_DEBUG_POSTFIX}") - include(GNUInstallDirs) # See for more details: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html set(MAPNIK_BIN_DIR ${CMAKE_INSTALL_BINDIR} CACHE STRING "Install directory for binaries") @@ -123,9 +119,29 @@ set(MAPNIK_COMPILE_DEFS "") set(MAPNIK_OPTIONAL_LIBS "") set(MAPNIK_OPTIONAL_LIBS_INCLUDE "") +############################# +############################# # Begin project configuration +############################# +############################# + +set(CMAKE_CXX_STANDARD 14 CACHE STRING "Sets the c++ standard. c++14 is minimum.") +set(CMAKE_CXX_STANDARD_REQUIRED ON) # require the specified CMAKE_CXX_STANDARD +set(CMAKE_CXX_EXTENSIONS OFF CACHE STRING "Enables the compiler specific extensions.") # Fallsback to -std=c++ if off +message(STATUS "Using c++${CMAKE_CXX_STANDARD}") +message(STATUS "Using c++ extensions: ${CXX_EXTENSIONS}") + +# add debug postfix to the libraries +set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "sets the debug library postfix on mapnik, wkt and json") +message(STATUS "postfix for debug libraries: ${CMAKE_DEBUG_POSTFIX}") + +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>$<$:DLL>") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib") # needs to be before the first call of find_boost. +list(APPEND MAPNIK_COMPILE_DEFS BOOST_SPIRIT_X3_HIDE_CXX17_WARNING) if(USE_MULTITHREADED) set(Boost_USE_MULTITHREADED ON) list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_THREADSAFE) @@ -134,7 +150,7 @@ else() endif() -find_package(PkgConfig) +mapnik_find_package(PkgConfig REQUIRED) mapnik_find_threads() mapnik_find_package(ICU REQUIRED COMPONENTS uc i18n data) @@ -163,7 +179,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() @@ -290,20 +306,15 @@ if(USE_TIFF) endif() if(USE_WEBP) - mapnik_find_package(WebP REQUIRED) + mapnik_pkg_check_modules(WebP REQUIRED IMPORTED_TARGET libwebp) list(APPEND MAPNIK_COMPILE_DEFS HAVE_WEBP) - list(APPEND MAPNIK_OPTIONAL_LIBS WebP::WebP) + list(APPEND MAPNIK_OPTIONAL_LIBS PkgConfig::WebP) endif() if(USE_CAIRO) - if(WIN32) - mapnik_find_package(Cairo REQUIRED) - list(APPEND MAPNIK_OPTIONAL_LIBS Cairo::Cairo) - else() - pkg_check_modules(Cairo REQUIRED IMPORTED_TARGET cairo) - list(APPEND MAPNIK_OPTIONAL_LIBS PkgConfig::Cairo) - endif() + mapnik_pkg_check_modules(Cairo REQUIRED IMPORTED_TARGET cairo) list(APPEND MAPNIK_COMPILE_DEFS HAVE_CAIRO) + list(APPEND MAPNIK_OPTIONAL_LIBS PkgConfig::Cairo) endif() if(USE_PROJ) @@ -312,7 +323,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}") @@ -344,10 +355,24 @@ if(NOT WIN32) list(APPEND MAPNIK_OPTIONAL_LIBS ${CMAKE_DL_LIBS}) endif() +if(NOT BUILD_SHARED_PLUGINS) + list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_STATIC_PLUGINS) +endif() +# when building static, this have to be public so that all depending libs know about +if(NOT BUILD_SHARED_LIBS) + list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_STATIC_DEFINE) +endif() + +if(DISABLE_MAPNIK_AUTOSETUP) + list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_DISABLE_AUTOSETUP) +endif() + # force utf-8 source code processing # see https://docs.microsoft.com/de-de/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170 -add_compile_options("$<$:/utf-8>") -add_compile_options("$<$:/utf-8>") +add_compile_options( + "$<$:/utf-8>" + "$<$:/EHsc>" +) add_library(core INTERFACE) add_library(mapnik::core ALIAS core) @@ -377,9 +402,20 @@ target_compile_definitions(core INTERFACE ${MAPNIK_COMPILE_DEFS}) mapnik_install(core) +### +# forward declaring libraries to consume them when building static plugins (circle deps between mapnik <-> plugin_target) +add_library(mapnik "") +add_library(mapnik::mapnik ALIAS mapnik) +add_library(wkt STATIC "") +add_library(mapnik::wkt ALIAS wkt) +add_library(json STATIC "") +add_library(mapnik::json ALIAS json) +# end forward declaration +### + add_subdirectory(deps) -add_subdirectory(src) add_subdirectory(plugins) +add_subdirectory(src) add_subdirectory(utils) add_subdirectory(demo) if(BUILD_BENCHMARK) @@ -396,23 +432,23 @@ feature_summary(FILENAME "${CMAKE_CURRENT_BINARY_DIR}/packages.log" WHAT PACKAGE include(MapnikExport) include(MapnikExportPkgConfig) -install(DIRECTORY include/ DESTINATION ${MAPNIK_INCLUDE_DIR}) -install(DIRECTORY deps/agg/include/ DESTINATION ${MAPNIK_INCLUDE_DIR}) -install(DIRECTORY deps/mapnik DESTINATION ${MAPNIK_INCLUDE_DIR}) +install(DIRECTORY include/ DESTINATION "${MAPNIK_INCLUDE_DIR}") +install(DIRECTORY deps/agg/include/ DESTINATION "${MAPNIK_INCLUDE_DIR}") +install(DIRECTORY deps/mapnik DESTINATION "${MAPNIK_INCLUDE_DIR}") file(GLOB TTF_FONT_FILES "fonts/*/*/*.ttf") -install(FILES ${TTF_FONT_FILES} DESTINATION ${FONTS_INSTALL_DIR}) +install(FILES ${TTF_FONT_FILES} DESTINATION "${FONTS_INSTALL_DIR}") if(NOT USE_EXTERNAL_MAPBOX_GEOMETRY) - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/geometry/include/ DESTINATION ${MAPNIK_INCLUDE_DIR}) + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/geometry/include/" DESTINATION "${MAPNIK_INCLUDE_DIR}") endif() if(NOT USE_EXTERNAL_MAPBOX_POLYLABEL) - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/polylabel/include/ DESTINATION ${MAPNIK_INCLUDE_DIR}) + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/polylabel/include/" DESTINATION "${MAPNIK_INCLUDE_DIR}") endif() if(NOT USE_EXTERNAL_MAPBOX_PROTOZERO) - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/protozero/include/ DESTINATION ${MAPNIK_INCLUDE_DIR}) + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/protozero/include/" DESTINATION "${MAPNIK_INCLUDE_DIR}") endif() if(NOT USE_EXTERNAL_MAPBOX_VARIANT) - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/variant/include/ DESTINATION ${MAPNIK_INCLUDE_DIR}) + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/variant/include/" DESTINATION "${MAPNIK_INCLUDE_DIR}") endif() mapnik_install_targets() diff --git a/CMakePresets.json b/CMakePresets.json index f0bbb21a6..bc5a7c995 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -17,7 +17,7 @@ { "name": "default-build-dir", "hidden": true, - "binaryDir": "${sourceDir}/build/${presetName}" + "binaryDir": "${sourceDir}/build" }, { "name": "debug-build", @@ -180,8 +180,9 @@ "cacheVariables": { "BUILD_TESTING": "ON", "BUILD_DEMO_VIEWER": "OFF", - "CMAKE_TOOLCHAIN_FILE": "vcpkg/scripts/buildsystems/vcpkg.cmake" - } + "DISABLE_MAPNIK_AUTOSETUP": "ON" + }, + "toolchainFile": "vcpkg/scripts/buildsystems/vcpkg.cmake" }, { "name": "windows-ci", @@ -192,10 +193,10 @@ ], "cacheVariables": { "INSTALL_DEPENDENCIES": "ON", - "ADDITIONAL_LIBARIES_PATHS": "${sourceDir}/build/${presetName}/vcpkg_installed/x64-windows/bin" + "ADDITIONAL_LIBARIES_PATHS": "${sourceDir}/build/vcpkg_installed/x64-windows/bin" }, "environment": { - "PROJ_LIB": "${sourceDir}/build/${presetName}/vcpkg_installed/x64-windows/share/proj" + "PROJ_LIB": "${sourceDir}/build/vcpkg_installed/x64-windows/share/proj" } }, { @@ -210,7 +211,7 @@ "CMAKE_CXX_FLAGS": "--coverage" }, "environment": { - "PROJ_LIB": "${sourceDir}/build/${presetName}/vcpkg_installed/x64-linux/share/proj" + "PROJ_LIB": "${sourceDir}/build/vcpkg_installed/x64-linux/share/proj" } }, { @@ -239,7 +240,7 @@ "CMAKE_CXX_FLAGS": "-fprofile-arcs -ftest-coverage" }, "environment": { - "PROJ_LIB": "${sourceDir}/build/${presetName}/vcpkg_installed/x64-osx/share/proj" + "PROJ_LIB": "${sourceDir}/build/vcpkg_installed/x64-osx/share/proj" } } ], diff --git a/SConstruct b/SConstruct index 9df2c5f9f..99577df30 100644 --- a/SConstruct +++ b/SConstruct @@ -1879,6 +1879,7 @@ if not preconfigured: env.Prepend(CPPPATH = '#deps/mapbox/geometry/include') env.Prepend(CPPPATH = '#deps/mapbox/protozero/include') env.Prepend(CPPPATH = '#deps/mapbox/polylabel/include') + env.Prepend(CPPPATH = '#plugins/input/base/include') # prepend deps dir for auxillary headers env.Prepend(CPPPATH = '#deps') diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 8c328c9fe..822fe56a7 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -31,11 +31,12 @@ function(mapnik_create_benchmark) 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::agg mapnik::mapnik) + target_link_libraries(${TARGET_NAME} PRIVATE + mapnik::agg + mapnik::mapnik + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) + ) set_target_properties(${TARGET_NAME} PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" OUTPUT_NAME "${BENCHNAME}" ) endfunction() diff --git a/benchmark/include/bench_framework.hpp b/benchmark/include/bench_framework.hpp index 94c785ac5..0acfe234e 100644 --- a/benchmark/include/bench_framework.hpp +++ b/benchmark/include/bench_framework.hpp @@ -2,6 +2,7 @@ #define MAPNIK_BENCH_FRAMEWORK_HPP // mapnik +#include #include #include #include @@ -124,6 +125,7 @@ inline int handle_args(int argc, char** argv, mapnik::parameters& params) #define BENCHMARK(test_class, name) \ int main(int argc, char** argv) \ { \ + mapnik::setup(); \ try \ { \ mapnik::parameters params; \ diff --git a/benchmark/src/normalize_angle.cpp b/benchmark/src/normalize_angle.cpp index fcfc7a5c2..97b6cdad1 100644 --- a/benchmark/src/normalize_angle.cpp +++ b/benchmark/src/normalize_angle.cpp @@ -30,6 +30,7 @@ struct bench_func : benchmark::test_case int main(int argc, char** argv) { + mapnik::setup(); return benchmark::sequencer(argc, argv) .BENCH_FUNC1(mapnik::util::normalize_angle, +3) .BENCH_FUNC1(mapnik::util::normalize_angle, +6) diff --git a/benchmark/src/test_array_allocation.cpp b/benchmark/src/test_array_allocation.cpp index 592a93d07..b80e9271f 100644 --- a/benchmark/src/test_array_allocation.cpp +++ b/benchmark/src/test_array_allocation.cpp @@ -349,6 +349,7 @@ class test7 : public benchmark::test_case int main(int argc, char** argv) { + mapnik::setup(); return benchmark::sequencer(argc, argv) .run("calloc") .run("malloc/memcpy") diff --git a/benchmark/src/test_expression_parse.cpp b/benchmark/src/test_expression_parse.cpp index d35a57ab2..956dcd39e 100644 --- a/benchmark/src/test_expression_parse.cpp +++ b/benchmark/src/test_expression_parse.cpp @@ -36,6 +36,7 @@ class test : public benchmark::test_case int main(int argc, char** argv) { + mapnik::setup(); mapnik::parameters params; benchmark::handle_args(argc, argv, params); test test_runner(params); diff --git a/benchmark/src/test_face_ptr_creation.cpp b/benchmark/src/test_face_ptr_creation.cpp index 4bbdf0301..64071c32f 100644 --- a/benchmark/src/test_face_ptr_creation.cpp +++ b/benchmark/src/test_face_ptr_creation.cpp @@ -59,6 +59,7 @@ class test : public benchmark::test_case int main(int argc, char** argv) { + mapnik::setup(); mapnik::parameters params; benchmark::handle_args(argc, argv, params); bool success = mapnik::freetype_engine::register_fonts("./fonts", true); diff --git a/benchmark/src/test_getline.cpp b/benchmark/src/test_getline.cpp index 7320d9271..d6b6996fa 100644 --- a/benchmark/src/test_getline.cpp +++ b/benchmark/src/test_getline.cpp @@ -101,6 +101,7 @@ class test2 : public benchmark::test_case int main(int argc, char** argv) { + mapnik::setup(); int return_value = 0; try { diff --git a/benchmark/src/test_numeric_cast_vs_static_cast.cpp b/benchmark/src/test_numeric_cast_vs_static_cast.cpp index 1b28513f2..90ea86c8b 100644 --- a/benchmark/src/test_numeric_cast_vs_static_cast.cpp +++ b/benchmark/src/test_numeric_cast_vs_static_cast.cpp @@ -76,5 +76,6 @@ class test_numeric : public benchmark::test_case int main(int argc, char** argv) { + mapnik::setup(); return benchmark::sequencer(argc, argv).run("static_cast").run("numeric_cast").done(); } diff --git a/benchmark/src/test_offset_converter.cpp b/benchmark/src/test_offset_converter.cpp index 93988ce4c..e591d552f 100644 --- a/benchmark/src/test_offset_converter.cpp +++ b/benchmark/src/test_offset_converter.cpp @@ -92,6 +92,7 @@ class test_offset : public benchmark::test_case int main(int argc, char** argv) { + mapnik::setup(); mapnik::parameters params; benchmark::handle_args(argc, argv, params); int return_value = 0; diff --git a/benchmark/src/test_polygon_clipping.cpp b/benchmark/src/test_polygon_clipping.cpp index 9ec54f251..d8c3fce6d 100644 --- a/benchmark/src/test_polygon_clipping.cpp +++ b/benchmark/src/test_polygon_clipping.cpp @@ -510,6 +510,7 @@ expected_count << "\n"; valid = false; int main(int argc, char** argv) { + mapnik::setup(); mapnik::parameters params; benchmark::handle_args(argc, argv, params); diff --git a/benchmark/src/test_polygon_clipping_rendering.cpp b/benchmark/src/test_polygon_clipping_rendering.cpp index b0daba0c9..9c3e99b33 100644 --- a/benchmark/src/test_polygon_clipping_rendering.cpp +++ b/benchmark/src/test_polygon_clipping_rendering.cpp @@ -43,6 +43,7 @@ class test : public benchmark::test_case int main(int argc, char** argv) { + mapnik::setup(); mapnik::parameters params; benchmark::handle_args(argc, argv, params); mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); diff --git a/benchmark/src/test_proj_transform1.cpp b/benchmark/src/test_proj_transform1.cpp index 96e338ceb..e179a671b 100644 --- a/benchmark/src/test_proj_transform1.cpp +++ b/benchmark/src/test_proj_transform1.cpp @@ -60,6 +60,7 @@ class test : public benchmark::test_case // echo -180 -60 | cs2cs -f "%.10f" epsg:4326 +to epsg:3857 int main(int argc, char** argv) { + mapnik::setup(); mapnik::box2d from(-180, -80, 180, 80); mapnik::box2d to(-20037508.3427892476, -15538711.0963092316, 20037508.3427892476, 15538711.0963092316); std::string from_str("epsg:4326"); diff --git a/benchmark/src/test_rendering.cpp b/benchmark/src/test_rendering.cpp index 3764f946c..3905af922 100644 --- a/benchmark/src/test_rendering.cpp +++ b/benchmark/src/test_rendering.cpp @@ -95,6 +95,7 @@ class test : public benchmark::test_case int main(int argc, char** argv) { + mapnik::setup(); int return_value = 0; try { diff --git a/benchmark/src/test_rendering_shared_map.cpp b/benchmark/src/test_rendering_shared_map.cpp index 43ae727b9..bf5078bbf 100644 --- a/benchmark/src/test_rendering_shared_map.cpp +++ b/benchmark/src/test_rendering_shared_map.cpp @@ -150,6 +150,7 @@ class test : public benchmark::test_case int main(int argc, char** argv) { + mapnik::setup(); int return_value = 0; try { diff --git a/benchmark/src/test_utf_encoding.cpp b/benchmark/src/test_utf_encoding.cpp index badb0a661..c677541db 100644 --- a/benchmark/src/test_utf_encoding.cpp +++ b/benchmark/src/test_utf_encoding.cpp @@ -106,6 +106,7 @@ class test3 : public benchmark::test_case int main(int argc, char** argv) { + mapnik::setup(); mapnik::parameters params; benchmark::handle_args(argc, argv, params); int return_value = 0; diff --git a/cmake/FindCairo.cmake b/cmake/FindCairo.cmake deleted file mode 100644 index 30b175010..000000000 --- a/cmake/FindCairo.cmake +++ /dev/null @@ -1,98 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#[=======================================================================[.rst: -FindCairo ------------ - -Find Cairo 2D graphics library. - - -Imported Targets -^^^^^^^^^^^^^^^^ -This module defines :prop_tgt:`IMPORTED` target ``Cairo::Cairo``, if -cairo has been found. - -Result variables -^^^^^^^^^^^^^^^^ - -This module will set the following variables in your project: - -``CAIRO_FOUND`` - True if cairo headers and library were found. -``CAIRO_INCLUDE_DIRS`` - Directory where cairo headers are located. -``CAIRO_LIBRARIES`` - cairo libraries to link against. -``CAIRO_VERSION_MAJOR`` - The major version of cairo -``CAIRO_VERSION_MINOR`` - The minor version of cairo -``CAIRO_VERSION_PATCH`` - The patch version of cairo -``CAIRO_VERSION_STRING`` - version number as a string (ex: "1.16.0") -#]=======================================================================] - -if(NOT CAIRO_LIBRARY) - find_path(CAIRO_INCLUDE_DIR NAMES cairo.h HINTS ${PC_CAIRO_INCLUDEDIR} ${PC_CAIRO_INCLUDE_DIR} PATH_SUFFIXES cairo) - find_library(CAIRO_LIBRARY_RELEASE NAMES ${Cairo_NAMES} cairo HINTS ${PC_CAIRO_LIBDIR} ${PC_CAIRO_LIBRARY_DIRS}) - find_library(CAIRO_LIBRARY_DEBUG NAMES ${Cairo_NAMES} cairod HINTS ${PC_CAIRO_LIBDIR} ${PC_CAIRO_LIBRARY_DIRS}) - include(SelectLibraryConfigurations) - select_library_configurations(CAIRO) -else() - file(TO_CMAKE_PATH "${CAIRO_LIBRARY}" CAIRO_LIBRARY) -endif() - -if(CAIRO_INCLUDE_DIR AND NOT CAIRO_VERSION) - if(EXISTS "${CAIRO_INCLUDE_DIR}/cairo-version.h") - file(READ "${CAIRO_INCLUDE_DIR}/cairo-version.h" CAIRO_VERSION_CONTENT) - - string(REGEX MATCH "#define +CAIRO_VERSION_MAJOR +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}") - set(CAIRO_VERSION_MAJOR "${CMAKE_MATCH_1}") - - string(REGEX MATCH "#define +CAIRO_VERSION_MINOR +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}") - set(CAIRO_VERSION_MINOR "${CMAKE_MATCH_1}") - - string(REGEX MATCH "#define +CAIRO_VERSION_MICRO +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}") - set(CAIRO_VERSION_PATCH "${CMAKE_MATCH_1}") - - set(CAIRO_VERSION "${CAIRO_VERSION_MAJOR}.${CAIRO_VERSION_MINOR}.${CAIRO_VERSION_PATCH}") - set(CAIRO_VERSION_STRING ${CAIRO_VERSION}) - endif() -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Cairo - REQUIRED_VARS - CAIRO_LIBRARY - CAIRO_INCLUDE_DIR - VERSION_VAR - CAIRO_VERSION_STRING -) -mark_as_advanced(CAIRO_INCLUDE_DIR CAIRO_LIBRARY) - -if (CAIRO_FOUND) - set(CAIRO_LIBRARIES ${CAIRO_LIBRARY}) - set(CAIRO_INCLUDE_DIRS ${CAIRO_INCLUDE_DIR}) - if(NOT TARGET Cairo::Cairo) - add_library(Cairo::Cairo UNKNOWN IMPORTED) - set_target_properties(Cairo::Cairo PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CAIRO_INCLUDE_DIR} - IMPORTED_LINK_INTERFACE_LANGUAGES C) - - if(CAIRO_LIBRARY_RELEASE) - set_property(TARGET Cairo::Cairo APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) - set_target_properties(Cairo::Cairo PROPERTIES IMPORTED_LOCATION_RELEASE "${CAIRO_LIBRARY_RELEASE}") - endif() - - if(CAIRO_LIBRARY_DEBUG) - set_property(TARGET Cairo::Cairo APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) - set_target_properties(Cairo::Cairo PROPERTIES IMPORTED_LOCATION_DEBUG "${CAIRO_LIBRARY_DEBUG}") - endif() - - if(NOT CAIRO_LIBRARY_RELEASE AND NOT CAIRO_LIBRARY_DEBUG) - set_target_properties(Cairo::Cairo PROPERTIES IMPORTED_LOCATION "${CAIRO_LIBRARY}") - endif() - endif() -endif () diff --git a/cmake/FindWebP.cmake b/cmake/FindWebP.cmake deleted file mode 100644 index 9fc3ac841..000000000 --- a/cmake/FindWebP.cmake +++ /dev/null @@ -1,97 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#[=======================================================================[.rst: -FindWebP -------- - -Finds the WebP library. - -Imported Targets -^^^^^^^^^^^^^^^^ - -This module provides the following imported targets, if found: - -``WebP::WebP`` - The WebP library - -Result Variables -^^^^^^^^^^^^^^^^ - -This will define the following variables: - -``WebP_FOUND`` - True if the system has the WebP library. -``WebP_VERSION`` - The version of the WebP library which was found. -``WebP_INCLUDE_DIRS`` - Include directories needed to use WebP. -``WebP_LIBRARIES`` - Libraries needed to link to WebP. - -Cache Variables -^^^^^^^^^^^^^^^ - -The following cache variables may also be set: - -``WebP_INCLUDE_DIR`` - The directory containing ``decode.h``. -``WebP_LIBRARY`` - The path to the Foo library. - -#]=======================================================================] - -if(NOT WebP_LIBRARY) - find_package(PkgConfig QUIET) - pkg_check_modules(PC_WebP QUIET libwebp) - set(WebP_VERSION ${PC_WebP_VERSION}) - find_path(WebP_INCLUDE_DIR NAMES decode.h HINTS ${PC_WebP_INCLUDEDIR} ${PC_WebP_INCLUDE_DIR} PATH_SUFFIXES webp) - find_library(WebP_LIBRARY_RELEASE NAMES ${WebP_NAMES} webp HINTS ${PC_WebP_LIBDIR} ${PC_WebP_LIBRARY_DIRS}) - find_library(WebP_LIBRARY_DEBUG NAMES ${WebP_NAMES} webpd HINTS ${PC_WebP_LIBDIR} ${PC_WebP_LIBRARY_DIRS}) - include(SelectLibraryConfigurations) - select_library_configurations(WebP) -else() - file(TO_CMAKE_PATH "${WebP_LIBRARY}" WebP_LIBRARY) -endif() - -if ("${WebP_FIND_VERSION}" VERSION_GREATER "${WebP_VERSION}") - if (WebP_VERSION) - message(FATAL_ERROR "Required version (" ${WebP_FIND_VERSION} ") is higher than found version (" ${PC_WebP_VERSION} ")") - else () - message(WARNING "Cannot determine WebP version without pkg-config") - endif () -endif () - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(WebP - REQUIRED_VARS - WebP_LIBRARY - WebP_INCLUDE_DIR - VERSION_VAR WebP_VERSION -) -mark_as_advanced(WebP_INCLUDE_DIR WebP_LIBRARY) - -if (WebP_FOUND) - set(WebP_LIBRARIES ${WebP_LIBRARY}) - set(WebP_INCLUDE_DIRS ${WebP_INCLUDE_DIR}) - if(NOT TARGET WebP::WebP) - add_library(WebP::WebP UNKNOWN IMPORTED) - set_target_properties(WebP::WebP PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${WebP_INCLUDE_DIR} - IMPORTED_LINK_INTERFACE_LANGUAGES C) - - if(WebP_LIBRARY_RELEASE) - set_property(TARGET WebP::WebP APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) - set_target_properties(WebP::WebP PROPERTIES IMPORTED_LOCATION_RELEASE "${WebP_LIBRARY_RELEASE}") - endif() - - if(WebP_LIBRARY_DEBUG) - set_property(TARGET WebP::WebP APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) - set_target_properties(WebP::WebP PROPERTIES IMPORTED_LOCATION_DEBUG "${WebP_LIBRARY_DEBUG}") - endif() - - if(NOT WebP_LIBRARY_RELEASE AND NOT WebP_LIBRARY_DEBUG) - set_target_properties(WebP::WebP PROPERTIES IMPORTED_LOCATION "${WebP_LIBRARY}") - endif() - endif() -endif () diff --git a/cmake/MapnikExport.cmake b/cmake/MapnikExport.cmake index 5c083bba9..34c5573b7 100644 --- a/cmake/MapnikExport.cmake +++ b/cmake/MapnikExport.cmake @@ -1,34 +1,46 @@ include(CMakePackageConfigHelpers) -# export mapnik configuration -write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/mapnikConfigVersion.cmake" - VERSION ${MAPNIK_VERSION} - COMPATIBILITY ExactVersion -) -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 MAPNIK_INCLUDE_DIR PLUGINS_INSTALL_DIR FONTS_INSTALL_DIR MAPNIK_DEPENDENCIES MAPNIK_UTILITIES - NO_CHECK_REQUIRED_COMPONENTS_MACRO -) - -install( - FILES - "${CMAKE_CURRENT_BINARY_DIR}/mapnikConfig.cmake" +### exports mapnik cmake config files (mapnikConfigVersion and mapnikConfig) +function(mapnik_export_cmake_config) + # export mapnik configuration + write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/mapnikConfigVersion.cmake" - DESTINATION ${MAPNIK_CMAKE_DIR} -) + VERSION ${MAPNIK_VERSION} + COMPATIBILITY ExactVersion + ) + get_property(MAPNIK_UTILITIES GLOBAL PROPERTY MAPNIK_UTILITIES) -# install our modules, so that the expected target names are found. -install( - FILES - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindCairo.cmake" - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindWebP.cmake" - DESTINATION ${MAPNIK_CMAKE_DIR}/Modules -) + # 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_find_deps 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} + ) +endfunction() + + +mapnik_export_cmake_config() install(EXPORT MapnikTargets DESTINATION ${MAPNIK_CMAKE_DIR} @@ -36,21 +48,21 @@ install(EXPORT MapnikTargets NAMESPACE mapnik:: ) - +### install plugin cmake config files ### # 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) -set(_mapnik_plugin_file_name "mapnikPlugins-${_build_type}") -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_mapnik_plugin_file_name}.cmake.in "set(MAPNIK_PLUGINS_DIR_${_build_type_l} \"@PACKAGE_PLUGINS_INSTALL_DIR@\" CACHE STRING \"\")\n") +set(m_mapnik_plugin_file_name mapnikPlugins-${_build_type}) +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${m_mapnik_plugin_file_name}.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}/${_mapnik_plugin_file_name}.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/${_mapnik_plugin_file_name}.cmake + "${CMAKE_CURRENT_BINARY_DIR}/${m_mapnik_plugin_file_name}.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/${m_mapnik_plugin_file_name}.cmake" PATH_VARS PLUGINS_INSTALL_DIR INSTALL_DESTINATION ${MAPNIK_CMAKE_DIR} ) install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/${_mapnik_plugin_file_name}.cmake + FILES "${CMAKE_CURRENT_BINARY_DIR}/${m_mapnik_plugin_file_name}.cmake" DESTINATION ${MAPNIK_CMAKE_DIR} ) diff --git a/cmake/MapnikFindPackage.cmake b/cmake/MapnikFindPackage.cmake index 8bcd96216..e80ad44c1 100644 --- a/cmake/MapnikFindPackage.cmake +++ b/cmake/MapnikFindPackage.cmake @@ -1,28 +1,50 @@ -macro(mapnik_print_version) - string(TOUPPER ${ARGV0} TLNUP) - set(TLN ${ARGV0}) - if(${TLN}_VERSION_STRING) - message(STATUS "Using ${ARGV0} version: ${${TLN}_VERSION_STRING}") - elseif(${TLN}_VERSION) - message(STATUS "Using ${ARGV0} version: ${${TLN}_VERSION}") - elseif(${TLNUP}_VERSION_STRING) - message(STATUS "Using ${ARGV0} version: ${${TLNUP}_VERSION_STRING}") - elseif(${TLNUP}_VERSION) - message(STATUS "Using ${ARGV0} version: ${${TLNUP}_VERSION}") +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) + set(${var} ${${m_package_name}_VERSION_STRING} PARENT_SCOPE) + elseif(${m_package_name}_VERSION) + set(${var} ${${m_package_name}_VERSION} PARENT_SCOPE) + elseif(${m_package_name_upc}_VERSION_STRING) + set(${var} ${${m_package_name_upc}_VERSION_STRING} PARENT_SCOPE) + elseif(${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 ${ARGV0}") + 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/MapnikInstall.cmake b/cmake/MapnikInstall.cmake index b0a781116..43e01b8dd 100644 --- a/cmake/MapnikInstall.cmake +++ b/cmake/MapnikInstall.cmake @@ -23,6 +23,9 @@ endfunction() # Install plugins # function(mapnik_install_plugin _target) + if(NOT BUILD_SHARED_PLUGINS) + return() + endif() install(TARGETS ${_target} RUNTIME DESTINATION ${PLUGINS_INSTALL_DIR} COMPONENT MapnikPluginRuntime 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") diff --git a/demo/c++/CMakeLists.txt b/demo/c++/CMakeLists.txt index 7bd9397c9..25bfd356d 100644 --- a/demo/c++/CMakeLists.txt +++ b/demo/c++/CMakeLists.txt @@ -1,8 +1,6 @@ add_executable(mapnik-demo rundemo.cpp) -set_target_properties(mapnik-demo PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" +target_link_libraries(mapnik-demo PRIVATE + mapnik::agg + mapnik::mapnik + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) - -target_link_libraries(mapnik-demo PRIVATE mapnik::agg mapnik::mapnik) diff --git a/demo/c++/rundemo.cpp b/demo/c++/rundemo.cpp index c5b56cb3c..ab4413161 100644 --- a/demo/c++/rundemo.cpp +++ b/demo/c++/rundemo.cpp @@ -20,6 +20,7 @@ * *****************************************************************************/ +#include #include #include #include @@ -52,7 +53,7 @@ int main(int, char**) "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"; const std::string srs_merc = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 " "+units=m +nadgrids=@null +wktext +no_defs +over"; - + mapnik::setup(); try { std::cout << " running demo ... \n"; @@ -131,8 +132,8 @@ int main(int, char**) line_symbolizer line_sym; put(line_sym, keys::stroke, color(171, 158, 137)); put(line_sym, keys::stroke_width, 2.0); - put(line_sym, keys::stroke_linecap, ROUND_CAP); - put(line_sym, keys::stroke_linejoin, ROUND_JOIN); + put(line_sym, keys::stroke_linecap, line_cap_enum::ROUND_CAP); + put(line_sym, keys::stroke_linejoin, line_join_enum::ROUND_JOIN); r.append(std::move(line_sym)); } roads34_style.add_rule(std::move(r)); @@ -148,8 +149,8 @@ int main(int, char**) line_symbolizer line_sym; put(line_sym, keys::stroke, color(171, 158, 137)); put(line_sym, keys::stroke_width, 4.0); - put(line_sym, keys::stroke_linecap, ROUND_CAP); - put(line_sym, keys::stroke_linejoin, ROUND_JOIN); + put(line_sym, keys::stroke_linecap, line_cap_enum::ROUND_CAP); + put(line_sym, keys::stroke_linejoin, line_join_enum::ROUND_JOIN); r.append(std::move(line_sym)); } roads2_style_1.add_rule(std::move(r)); @@ -164,8 +165,8 @@ int main(int, char**) line_symbolizer line_sym; put(line_sym, keys::stroke, color(255, 250, 115)); put(line_sym, keys::stroke_width, 2.0); - put(line_sym, keys::stroke_linecap, ROUND_CAP); - put(line_sym, keys::stroke_linejoin, ROUND_JOIN); + put(line_sym, keys::stroke_linecap, line_cap_enum::ROUND_CAP); + put(line_sym, keys::stroke_linejoin, line_join_enum::ROUND_JOIN); r.append(std::move(line_sym)); } roads2_style_2.add_rule(std::move(r)); @@ -181,8 +182,8 @@ int main(int, char**) line_symbolizer line_sym; put(line_sym, keys::stroke, color(188, 149, 28)); put(line_sym, keys::stroke_width, 7.0); - put(line_sym, keys::stroke_linecap, ROUND_CAP); - put(line_sym, keys::stroke_linejoin, ROUND_JOIN); + put(line_sym, keys::stroke_linecap, line_cap_enum::ROUND_CAP); + put(line_sym, keys::stroke_linejoin, line_join_enum::ROUND_JOIN); r.append(std::move(line_sym)); } roads1_style_1.add_rule(std::move(r)); @@ -197,8 +198,8 @@ int main(int, char**) line_symbolizer line_sym; put(line_sym, keys::stroke, color(242, 191, 36)); put(line_sym, keys::stroke_width, 5.0); - put(line_sym, keys::stroke_linecap, ROUND_CAP); - put(line_sym, keys::stroke_linejoin, ROUND_JOIN); + put(line_sym, keys::stroke_linecap, line_cap_enum::ROUND_CAP); + put(line_sym, keys::stroke_linejoin, line_join_enum::ROUND_JOIN); r.append(std::move(line_sym)); } roads1_style_2.add_rule(std::move(r)); diff --git a/demo/viewer/CMakeLists.txt b/demo/viewer/CMakeLists.txt index 33d33d9ec..89c0865cb 100644 --- a/demo/viewer/CMakeLists.txt +++ b/demo/viewer/CMakeLists.txt @@ -40,15 +40,13 @@ set_target_properties(mapnik-viewer PROPERTIES AUTORCC ON AUTOUIC ON AUTOMOC ON - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" ) target_link_libraries(mapnik-viewer PRIVATE Qt${QT_VERSION_MAJOR}::Widgets mapnik::agg mapnik::mapnik + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/viewer.ini diff --git a/demo/viewer/main.cpp b/demo/viewer/main.cpp index aa73b9ce3..114655d79 100644 --- a/demo/viewer/main.cpp +++ b/demo/viewer/main.cpp @@ -23,12 +23,14 @@ #include #include #include +#include #include "mainwindow.hpp" int main(int argc, char** argv) { using mapnik::datasource_cache; using mapnik::freetype_engine; + mapnik::setup(); try { #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) diff --git a/include/mapnik/adaptive_smooth.hpp b/include/mapnik/adaptive_smooth.hpp index 0f5748f3c..ae088d460 100644 --- a/include/mapnik/adaptive_smooth.hpp +++ b/include/mapnik/adaptive_smooth.hpp @@ -4,6 +4,8 @@ #include #include +#include +#include MAPNIK_DISABLE_WARNING_PUSH #include #include "agg_conv_smooth_poly1.h" @@ -80,9 +82,9 @@ class smooth_converter { switch (algo) { - case SMOOTH_ALGORITHM_ADAPTIVE: + case smooth_algorithm_enum::SMOOTH_ALGORITHM_ADAPTIVE: return adaptive_impl_type(geom); - case SMOOTH_ALGORITHM_BASIC: + case smooth_algorithm_enum::SMOOTH_ALGORITHM_BASIC: default: break; } @@ -92,7 +94,7 @@ class smooth_converter public: smooth_converter(Geometry& geom) : geom_(geom) - , impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom))) + , impl_(std::move(init_impl(smooth_algorithm_enum::SMOOTH_ALGORITHM_BASIC, geom))) {} void algorithm(smooth_algorithm_enum algo) { impl_ = init_impl(algo, geom_); } diff --git a/include/mapnik/agg_helpers.hpp b/include/mapnik/agg_helpers.hpp index 00a419287..01f9a27e2 100644 --- a/include/mapnik/agg_helpers.hpp +++ b/include/mapnik/agg_helpers.hpp @@ -39,19 +39,19 @@ void set_gamma_method(T& ras_ptr, double gamma, gamma_method_enum method) { switch (method) { - case GAMMA_POWER: + case gamma_method_enum::GAMMA_POWER: ras_ptr->gamma(agg::gamma_power(gamma)); break; - case GAMMA_LINEAR: + case gamma_method_enum::GAMMA_LINEAR: ras_ptr->gamma(agg::gamma_linear(0.0, gamma)); break; - case GAMMA_NONE: + case gamma_method_enum::GAMMA_NONE: ras_ptr->gamma(agg::gamma_none()); break; - case GAMMA_THRESHOLD: + case gamma_method_enum::GAMMA_THRESHOLD: ras_ptr->gamma(agg::gamma_threshold(gamma)); break; - case GAMMA_MULTIPLY: + case gamma_method_enum::GAMMA_MULTIPLY: ras_ptr->gamma(agg::gamma_multiply(gamma)); break; default: diff --git a/include/mapnik/config.hpp b/include/mapnik/config.hpp index 0370de1f8..312d72ffb 100644 --- a/include/mapnik/config.hpp +++ b/include/mapnik/config.hpp @@ -24,32 +24,40 @@ #define MAPNIK_CONFIG_HPP // Windows DLL support - +// clang-format off #ifdef _WIN32 -#define MAPNIK_EXP __declspec(dllexport) -#define MAPNIK_IMP __declspec(dllimport) -#ifdef MAPNIK_EXPORTS -#define MAPNIK_DECL __declspec(dllexport) +#ifdef MAPNIK_STATIC_DEFINE +# define MAPNIK_DECL +# define MAPNIK_EXP #else -#define MAPNIK_DECL __declspec(dllimport) -#endif -#pragma warning(disable: 4251) -#pragma warning(disable: 4275) -#if (_MSC_VER >= 1400) // vc8 -#pragma warning(disable: 4996) //_CRT_SECURE_NO_DEPRECATE +# define MAPNIK_EXP __declspec(dllexport) +# ifndef MAPNIK_DECL +# ifdef MAPNIK_EXPORTS + /* We are building this library */ +# define MAPNIK_DECL __declspec(dllexport) +# else + /* We are using this library */ +# define MAPNIK_DECL __declspec(dllimport) +# endif +# endif #endif +# pragma warning( disable: 4251 ) +# pragma warning( disable: 4275 ) +# if (_MSC_VER >= 1400) // vc8 +# pragma warning(disable : 4996) //_CRT_SECURE_NO_DEPRECATE +# endif #else -#if __GNUC__ >= 4 -#define MAPNIK_EXP __attribute__((visibility("default"))) -#define MAPNIK_DECL __attribute__((visibility("default"))) -#define MAPNIK_IMP __attribute__((visibility("default"))) -#else -#define MAPNIK_EXP -#define MAPNIK_DECL -#define MAPNIK_IMP +# if __GNUC__ >= 4 +# define MAPNIK_EXP __attribute__ ((visibility ("default"))) +# define MAPNIK_DECL __attribute__ ((visibility ("default"))) +# define MAPNIK_IMP __attribute__ ((visibility ("default"))) +# else +# define MAPNIK_EXP +# define MAPNIK_DECL +# define MAPNIK_IMP +# endif #endif -#endif - +// clang-format on #define PROJ_ENVELOPE_POINTS 20 #endif // MAPNIK_CONFIG_HPP diff --git a/include/mapnik/css/css_color_grammar_x3_def.hpp b/include/mapnik/css/css_color_grammar_x3_def.hpp index 2b07f0dea..eec9abae3 100644 --- a/include/mapnik/css/css_color_grammar_x3_def.hpp +++ b/include/mapnik/css/css_color_grammar_x3_def.hpp @@ -48,11 +48,9 @@ namespace css_color_grammar { using x3::attr; using x3::double_; -using x3::hex; using x3::lit; using x3::no_case; using x3::no_skip; -using x3::omit; using x3::symbols; using x3::uint_parser; @@ -214,11 +212,11 @@ struct named_colors_ : x3::symbols ; // clang-format on } -} named_colors; +} const named_colors; -x3::uint_parser hex2; -x3::uint_parser hex1; -x3::uint_parser dec3; +const x3::uint_parser hex2; +const x3::uint_parser hex1; +const x3::uint_parser dec3; // rules x3::rule const hex2_color("hex2_color"); @@ -245,67 +243,67 @@ struct percent_converter static std::uint8_t call(double val) { return safe_cast(std::lround((255.0 * val) / 100.0)); } }; -auto dec_red = [](auto& ctx) { +const auto dec_red = [](auto& ctx) { _val(ctx).red_ = _attr(ctx); }; -auto dec_green = [](auto& ctx) { +const auto dec_green = [](auto& ctx) { _val(ctx).green_ = _attr(ctx); }; -auto dec_blue = [](auto& ctx) { +const auto dec_blue = [](auto& ctx) { _val(ctx).blue_ = _attr(ctx); }; -auto opacity = [](auto& ctx) { +const auto opacity = [](auto& ctx) { _val(ctx).alpha_ = uint8_t((255.0 * clip_opacity::call(_attr(ctx))) + 0.5); }; -auto percent_red = [](auto& ctx) { +const auto percent_red = [](auto& ctx) { _val(ctx).red_ = percent_converter::call(_attr(ctx)); }; -auto percent_green = [](auto& ctx) { +const auto percent_green = [](auto& ctx) { _val(ctx).green_ = percent_converter::call(_attr(ctx)); }; -auto percent_blue = [](auto& ctx) { +const auto percent_blue = [](auto& ctx) { _val(ctx).blue_ = percent_converter::call(_attr(ctx)); }; -auto hex1_red = [](auto& ctx) { +const auto hex1_red = [](auto& ctx) { _val(ctx).red_ = _attr(ctx) | _attr(ctx) << 4; }; -auto hex1_green = [](auto& ctx) { +const auto hex1_green = [](auto& ctx) { _val(ctx).green_ = _attr(ctx) | _attr(ctx) << 4; }; -auto hex1_blue = [](auto& ctx) { +const auto hex1_blue = [](auto& ctx) { _val(ctx).blue_ = _attr(ctx) | _attr(ctx) << 4; }; -auto hex1_opacity = [](auto& ctx) { +const auto hex1_opacity = [](auto& ctx) { _val(ctx).alpha_ = _attr(ctx) | _attr(ctx) << 4; }; -auto hex2_red = [](auto& ctx) { +const auto hex2_red = [](auto& ctx) { _val(ctx).red_ = _attr(ctx); }; -auto hex2_green = [](auto& ctx) { +const auto hex2_green = [](auto& ctx) { _val(ctx).green_ = _attr(ctx); }; -auto hex2_blue = [](auto& ctx) { +const auto hex2_blue = [](auto& ctx) { _val(ctx).blue_ = _attr(ctx); }; -auto hex2_opacity = [](auto& ctx) { +const auto hex2_opacity = [](auto& ctx) { _val(ctx).alpha_ = _attr(ctx); }; -auto hsl_to_rgba = [](auto& ctx) { +const auto hsl_to_rgba = [](auto& ctx) { double h = std::get<0>(_attr(ctx)); double s = std::get<1>(_attr(ctx)); double l = std::get<2>(_attr(ctx)); @@ -325,10 +323,10 @@ auto hsl_to_rgba = [](auto& ctx) { } m1 = l * 2 - m2; - double r = hue_to_rgb(m1, m2, h + 1.0 / 3.0); - double g = hue_to_rgb(m1, m2, h); - double b = hue_to_rgb(m1, m2, h - 1.0 / 3.0); - uint8_t alpha = uint8_t((255.0 * clip_opacity::call(std::get<3>(_attr(ctx)))) + 0.5); + const double r = hue_to_rgb(m1, m2, h + 1.0 / 3.0); + const double g = hue_to_rgb(m1, m2, h); + const double b = hue_to_rgb(m1, m2, h - 1.0 / 3.0); + const uint8_t alpha = uint8_t((255.0 * clip_opacity::call(std::get<3>(_attr(ctx)))) + 0.5); _val(ctx) = color(safe_cast(std::lround(255.0 * r)), safe_cast(std::lround(255.0 * g)), safe_cast(std::lround(255.0 * b)), diff --git a/include/mapnik/css/css_grammar_x3_def.hpp b/include/mapnik/css/css_grammar_x3_def.hpp index a4f533c47..2e18c9fb7 100644 --- a/include/mapnik/css/css_grammar_x3_def.hpp +++ b/include/mapnik/css/css_grammar_x3_def.hpp @@ -150,32 +150,27 @@ namespace css_grammar { using x3::alnum; using x3::alpha; -using x3::attr; using x3::char_; using x3::lexeme; using x3::lit; -using x3::no_case; -using x3::no_skip; using x3::raw; using x3::standard::space; // import unicode string rule -namespace { -auto const& css_string = mapnik::json::grammar::unicode_string; -} +const auto css_string = mapnik::json::grammar::unicode_string; -auto assign_def = [](auto const& ctx) { +const auto assign_def = [](auto const& ctx) { for (auto const& k : std::get<0>(_attr(ctx))) { _val(ctx).emplace(k, std::get<1>(_attr(ctx))); } }; -auto assign_key = [](auto const& ctx) { +const auto assign_key = [](auto const& ctx) { _val(ctx).first = std::move(_attr(ctx)); }; -auto assign_value = [](auto const& ctx) { +const auto assign_value = [](auto const& ctx) { _val(ctx).second = std::move(_attr(ctx)); }; diff --git a/include/mapnik/csv/csv_grammar_x3_def.hpp b/include/mapnik/csv/csv_grammar_x3_def.hpp index 2fc1f021e..1d9a20135 100644 --- a/include/mapnik/csv/csv_grammar_x3_def.hpp +++ b/include/mapnik/csv/csv_grammar_x3_def.hpp @@ -39,9 +39,9 @@ using standard::char_; using x3::lexeme; using x3::lit; -struct unesc_char_ : x3::symbols +struct unesc_char_csv_ : x3::symbols { - unesc_char_() + unesc_char_csv_() { add("\\a", '\a') // ("\\b", '\b') // @@ -56,7 +56,7 @@ struct unesc_char_ : x3::symbols ("\"\"", '\"') // double quote ; } -} unesc_char; +} const unesc_char_csv; template struct literal : x3::parser> @@ -93,7 +93,7 @@ auto const column_def = quoted_text | *(char_ - separator); auto const quoted_text_def = quote > text > quote // support unmatched quotes or not (??) ; -auto const text_def = *(unesc_char | (char_ - quote)); +auto const text_def = *(unesc_char_csv | (char_ - quote)); BOOST_SPIRIT_DEFINE(line, column, quoted_text, text); diff --git a/include/mapnik/datasource.hpp b/include/mapnik/datasource.hpp index 6dd82e088..b08a5f993 100644 --- a/include/mapnik/datasource.hpp +++ b/include/mapnik/datasource.hpp @@ -113,25 +113,6 @@ class datasource_deleter }; using datasource_ptr = std::shared_ptr; - -#ifdef MAPNIK_STATIC_PLUGINS -#define DATASOURCE_PLUGIN(classname) -#else -#define DATASOURCE_PLUGIN(classname) \ - extern "C" MAPNIK_EXP const char* datasource_name() \ - { \ - return classname::name(); \ - } \ - extern "C" MAPNIK_EXP datasource* create(parameters const& params) \ - { \ - return new classname(params); \ - } \ - extern "C" MAPNIK_EXP void destroy(datasource* ds) \ - { \ - delete ds; \ - } -#endif - } // namespace mapnik #endif // MAPNIK_DATASOURCE_HPP diff --git a/include/mapnik/datasource_cache.hpp b/include/mapnik/datasource_cache.hpp index 8504b05c2..4e321c9ad 100644 --- a/include/mapnik/datasource_cache.hpp +++ b/include/mapnik/datasource_cache.hpp @@ -47,7 +47,8 @@ class MAPNIK_DECL datasource_cache : public singleton; public: - std::vector plugin_names(); + bool plugin_registered(const std::string& plugin_name) const; + std::vector plugin_names() const; std::string plugin_directories(); bool register_datasources(std::string const& path, bool recurse = false); bool register_datasource(std::string const& path); @@ -62,7 +63,7 @@ class MAPNIK_DECL datasource_cache : public singleton; diff --git a/include/mapnik/enumeration.hpp b/include/mapnik/enumeration.hpp index a0f08e3ac..943abdeb3 100644 --- a/include/mapnik/enumeration.hpp +++ b/include/mapnik/enumeration.hpp @@ -31,6 +31,13 @@ #include #include #include +#include +#include +#include +#include +#if __cpp_lib_string_view >= 201606L +#include +#endif #include @@ -51,9 +58,160 @@ class illegal_enum_value : public std::exception virtual const char* what() const noexcept { return what_.c_str(); } protected: - std::string what_; + const std::string what_; }; +namespace detail { +#if __cpp_lib_string_view >= 201606L +using mapnik_string_view = std::string_view; +#else +class mapnik_string_view // use std::string_view in C++17 +{ + public: + + template + constexpr mapnik_string_view(const char (&s)[N]) + : size_(N) + , data_(s) + {} + + constexpr mapnik_string_view(const char* s, std::size_t N) + : size_(N) + , data_(s) + {} + + constexpr char operator[](std::size_t index) const + { + return (index >= size_) ? throw std::out_of_range("Invalid index.") : data_[index]; + } + + constexpr char const* data() const { return data_; } + + private: + std::size_t size_; + const char* data_; +}; + +constexpr bool mapnik_string_view_equals(mapnik_string_view const& a, char const* b, std::size_t i) +{ + if (a[i] != b[i]) + { + return false; + } + else if (a[i] == 0 || b[i] == 0) + { + return true; + } + else + { + return mapnik_string_view_equals(a, b, i + 1); + } +} + +constexpr bool operator==(mapnik_string_view const& a, char const* b) +{ + return mapnik_string_view_equals(a, b, 0); +} +#endif + +template +using EnumStringT = std::tuple; + +template +using EnumMapT = std::array, N>; + +template +constexpr char const* EnumGetValue(EnumMapT const& map, EnumT key, std::size_t i = 0) +{ + if (i >= map.size()) + { + throw illegal_enum_value{"Enum value not present in map."}; + } + return (std::get<0>(map[i]) == key) ? std::get<1>(map[i]).data() : EnumGetValue(map, key, i + 1); +} + +template +constexpr EnumT EnumGetKey(EnumMapT const& map, char const* value, std::size_t i = 0) +{ + if (i >= map.size()) + { + throw illegal_enum_value{"Enum key not present in map."}; + } + return (std::get<1>(map[i]) == value) ? std::get<0>(map[i]) : EnumGetKey(map, value, i + 1); +} +} // namespace detail + +template (*F_LOOKUP)()> +struct MAPNIK_DECL enumeration +{ + using native_type = ENUM; + constexpr operator ENUM() const { return value_; } + // constexpr bool operator==(const enumeration_new& rhs) { return value_ == rhs.value_; } + void operator=(ENUM v) { value_ = v; } + void operator=(const enumeration& other) { value_ = other.value_; } + + enumeration() + : value_() + {} + + enumeration(ENUM v) + : value_(v) + {} + + void from_string(const std::string& str) { value_ = F_FROM_STRING(str.c_str()); } + std::string as_string() const { return F_TO_STRING(value_); } + static std::map lookupMap() { return F_LOOKUP(); } + + ENUM value_; +}; + +#define DEFINE_ENUM_FNCS(fnc_name, enum_class) \ + MAPNIK_DECL char const* fnc_name##_to_string(enum_class value); \ + MAPNIK_DECL enum_class fnc_name##_from_string(const char* value); \ + MAPNIK_DECL std::ostream& operator<<(std::ostream& stream, enum_class value); \ + MAPNIK_DECL std::map fnc_name##_lookup(); + +#define IMPLEMENT_ENUM_FNCS(fnc_name, enum_class) \ + char const* fnc_name##_to_string(enum_class value) \ + { \ + return mapnik::detail::EnumGetValue(fnc_name##_map, value); \ + } \ + enum_class fnc_name##_from_string(const char* value) \ + { \ + return mapnik::detail::EnumGetKey(fnc_name##_map, value); \ + } \ + std::ostream& operator<<(std::ostream& stream, enum_class value) \ + { \ + stream << fnc_name##_to_string(value); \ + return stream; \ + } \ + std::map fnc_name##_lookup() \ + { \ + std::map val_map; \ + std::transform( \ + fnc_name##_map.begin(), \ + fnc_name##_map.end(), \ + std::inserter(val_map, val_map.end()), \ + [](const mapnik::detail::EnumStringT& val) { \ + return std::pair{std::get<0>(val), std::string{std::get<1>(val).data()}}; \ + }); \ + return val_map; \ + } + +#define DEFINE_ENUM(type_alias, enum_class) \ + DEFINE_ENUM_FNCS(type_alias, enum_class) \ + using type_alias = enumeration; \ + extern template struct MAPNIK_DECL \ + enumeration; + +#define IMPLEMENT_ENUM(type_alias, enum_class) \ + IMPLEMENT_ENUM_FNCS(type_alias, enum_class) \ + template class MAPNIK_DECL \ + enumeration; + /** Slim wrapper for enumerations. It creates a new type from a native enum and * a char pointer array. It almost exactly behaves like a native enumeration * type. It supports string conversion through stream operators. This is useful @@ -133,159 +291,6 @@ class illegal_enum_value : public std::exception * @endcode */ -template -class MAPNIK_DECL enumeration -{ - public: - using native_type = ENUM; - - enumeration() - : value_() - {} - - enumeration(ENUM v) - : value_(v) - {} - - enumeration(enumeration const& other) - : value_(other.value_) - {} - - /** Assignment operator for native enum values. */ - void operator=(ENUM v) { value_ = v; } - - /** Assignment operator. */ - void operator=(enumeration const& other) { value_ = other.value_; } - - /** Conversion operator for native enum values. */ - operator ENUM() const { return value_; } - - enum Max { MAX = THE_MAX }; - - /** Converts @p str to an enum. - * @throw illegal_enum_value @p str is not a legal identifier. - * */ - void from_string(std::string const& str) - { - // TODO: Enum value strings with underscore are deprecated in Mapnik 3.x - // and support will be removed in Mapnik 4.x. - bool deprecated = false; - std::string str_copy(str); - if (str_copy.find('_') != std::string::npos) - { - std::replace(str_copy.begin(), str_copy.end(), '_', '-'); - deprecated = true; - } - for (unsigned i = 0; i < THE_MAX; ++i) - { - MAPNIK_DISABLE_WARNING_PUSH - MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS - MAPNIK_DISABLE_WARNING_PRAGMAS - MAPNIK_DISABLE_LONG_LONG - if (str_copy == our_strings_[i]) - MAPNIK_DISABLE_WARNING_POP - { - value_ = static_cast(i); - if (deprecated) - { - MAPNIK_LOG_ERROR(enumerations) - << "enumeration value (" << str - << ") using \"_\" is deprecated and will be removed in Mapnik 4.x, use '" << str_copy - << "' instead"; - } - return; - } - } - MAPNIK_DISABLE_WARNING_PUSH - MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS - MAPNIK_DISABLE_WARNING_PRAGMAS - MAPNIK_DISABLE_LONG_LONG - throw illegal_enum_value(std::string("Illegal enumeration value '") + str + "' for enum " + our_name_); - MAPNIK_DISABLE_WARNING_POP - } - - /** Returns the current value as a string identifier. */ - std::string as_string() const - { - MAPNIK_DISABLE_WARNING_PUSH - MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS - MAPNIK_DISABLE_WARNING_PRAGMAS - MAPNIK_DISABLE_LONG_LONG - return our_strings_[value_]; - MAPNIK_DISABLE_WARNING_POP - } - - /** Static helper function to iterate over valid identifiers. */ - static const char* get_string(unsigned i) { return our_strings_[i]; } - - /** Performs some simple checks and quits the application if - * any error is detected. Tries to print helpful error messages. - */ - static bool verify_mapnik_enum(const char* filename, unsigned line_no) - { - for (unsigned i = 0; i < THE_MAX; ++i) - { - if (our_strings_[i] == 0) - { - std::cerr << "### FATAL: Not enough strings for enum " << our_name_ << " defined in file '" << filename - << "' at line " << line_no; - } - } - if (std::string("") != our_strings_[THE_MAX]) - { - std::cerr << "### FATAL: The string array for enum " << our_name_ << " defined in file '" << filename - << "' at line " << line_no << " has too many items or is not terminated with an " - << "empty string"; - } - return true; - } - - private: - ENUM value_; - static const char** our_strings_; - static std::string our_name_; - static bool our_verified_flag_; -}; - -/** ostream operator for enumeration - * @relates mapnik::enumeration - */ -template -std::ostream& operator<<(std::ostream& os, const mapnik::enumeration& e) -{ - return os << e.as_string(); -} - } // namespace mapnik -/** Helper macro. - * @relates mapnik::enumeration - */ -#ifdef _MSC_VER -#define DEFINE_ENUM(name, e) \ - template enumeration; \ - using name = enumeration; -#else -#define DEFINE_ENUM(name, e) \ - using name = enumeration; \ - template<> \ - MAPNIK_DECL const char** name ::our_strings_; \ - template<> \ - MAPNIK_DECL std::string name ::our_name_; \ - template<> \ - MAPNIK_DECL bool name ::our_verified_flag_; -#endif - -/** Helper macro. Runs the verify_mapnik_enum() method during static initialization. - * @relates mapnik::enumeration - */ - -#define IMPLEMENT_ENUM(name, strings) \ - template<> \ - MAPNIK_DECL const char** name ::our_strings_ = strings; \ - template<> \ - MAPNIK_DECL std::string name ::our_name_ = #name; \ - template<> \ - MAPNIK_DECL bool name ::our_verified_flag_(name ::verify_mapnik_enum(__FILE__, __LINE__)); - #endif // MAPNIK_ENUMERATION_HPP diff --git a/include/mapnik/expression_grammar_x3_def.hpp b/include/mapnik/expression_grammar_x3_def.hpp index 9b6d28f74..56ab3e348 100644 --- a/include/mapnik/expression_grammar_x3_def.hpp +++ b/include/mapnik/expression_grammar_x3_def.hpp @@ -51,23 +51,17 @@ namespace grammar { namespace x3 = boost::spirit::x3; namespace ascii = boost::spirit::x3::ascii; using ascii::char_; -using ascii::string; using x3::_attr; using x3::_val; using x3::alnum; using x3::alpha; -using x3::bool_; -using x3::double_; -using x3::int_; using x3::lexeme; using x3::lit; using x3::no_case; using x3::no_skip; x3::uint_parser const hex2{}; -namespace { -auto const& escaped_unicode = json::grammar::escaped_unicode; -} +const auto escaped_unicode = json::grammar::escaped_unicode; template inline mapnik::transcoder const& extract_transcoder(Context const& ctx) @@ -75,19 +69,19 @@ inline mapnik::transcoder const& extract_transcoder(Context const& ctx) return x3::get(ctx); } -auto append = [](auto const& ctx) { +const auto append = [](auto const& ctx) { _val(ctx) += _attr(ctx); }; -auto do_assign = [](auto const& ctx) { +const auto do_assign = [](auto const& ctx) { _val(ctx) = std::move(_attr(ctx)); }; -auto do_negate = [](auto const& ctx) { +const auto do_negate = [](auto const& ctx) { _val(ctx) = std::move(unary_node(_attr(ctx))); }; -auto do_attribute = [](auto const& ctx) { +const auto do_attribute = [](auto const& ctx) { auto const& attr = _attr(ctx); if (attr == "mapnik::geometry_type") { @@ -99,84 +93,84 @@ auto do_attribute = [](auto const& ctx) { } }; -auto do_global_attribute = [](auto const& ctx) { +const auto do_global_attribute = [](auto const& ctx) { _val(ctx) = std::move(global_attribute(_attr(ctx))); }; -auto do_add = [](auto const& ctx) { +const auto do_add = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_subt = [](auto const& ctx) { +const auto do_subt = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_mult = [](auto const& ctx) { +const auto do_mult = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_div = [](auto const& ctx) { +const auto do_div = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_mod = [](auto const& ctx) { +const auto do_mod = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_unicode = [](auto const& ctx) { +const auto do_unicode = [](auto const& ctx) { auto const& tr = extract_transcoder(ctx); _val(ctx) = std::move(tr.transcode(_attr(ctx).c_str())); }; -auto do_null = [](auto const& ctx) { +const auto do_null = [](auto const& ctx) { _val(ctx) = std::move(mapnik::value_null()); }; -auto do_not = [](auto const& ctx) { +const auto do_not = [](auto const& ctx) { mapnik::unary_node node(_attr(ctx)); _val(ctx) = std::move(node); }; -auto do_and = [](auto const& ctx) { +const auto do_and = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_or = [](auto const& ctx) { +const auto do_or = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_equal = [](auto const& ctx) { +const auto do_equal = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_not_equal = [](auto const& ctx) { +const auto do_not_equal = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_less = [](auto const& ctx) { +const auto do_less = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_less_equal = [](auto const& ctx) { +const auto do_less_equal = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_greater = [](auto const& ctx) { +const auto do_greater = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_greater_equal = [](auto const& ctx) { +const auto do_greater_equal = [](auto const& ctx) { _val(ctx) = std::move(mapnik::binary_node(std::move(_val(ctx)), std::move(_attr(ctx)))); }; // regex -auto do_regex_match = [](auto const& ctx) { +const auto do_regex_match = [](auto const& ctx) { auto const& tr = extract_transcoder(ctx); _val(ctx) = std::move(mapnik::regex_match_node(tr, std::move(_val(ctx)), std::move(_attr(ctx)))); }; -auto do_regex_replace = [](auto const& ctx) { +const auto do_regex_replace = [](auto const& ctx) { auto const& tr = extract_transcoder(ctx); auto const& pair = _attr(ctx); auto const& pattern = std::get<0>(pair); @@ -197,7 +191,7 @@ struct boolean_ : x3::symbols ("false", false) // ; } -} boolean; +} const boolean; struct floating_point_constants : x3::symbols { @@ -208,7 +202,7 @@ struct floating_point_constants : x3::symbols ("rad_to_deg", 57.295779513082320876798154814105) // ; } -} float_const; +} const float_const; // unary functions struct unary_function_types_ : x3::symbols @@ -225,7 +219,7 @@ struct unary_function_types_ : x3::symbols ("length", length_impl()) // ; } -} unary_func_types; +} const unary_func_types; // binary functions @@ -238,7 +232,7 @@ struct binary_function_types_ : x3::symbols ("pow", binary_function_impl(pow_impl)) // ; } -} binary_func_types; +} const binary_func_types; // geometry types struct geometry_types_ : x3::symbols @@ -251,7 +245,7 @@ struct geometry_types_ : x3::symbols ("collection", 4) // ; } -} geometry_type; +} const geometry_type; struct unesc_chars_ : x3::symbols { @@ -269,7 +263,7 @@ struct unesc_chars_ : x3::symbols ("\\\"", '\"') // ; } -} unesc_char; +} const unesc_char; // rules x3::rule const logical_expression("logical expression"); diff --git a/include/mapnik/feature_style_processor_impl.hpp b/include/mapnik/feature_style_processor_impl.hpp index 0b569d065..801f3c255 100644 --- a/include/mapnik/feature_style_processor_impl.hpp +++ b/include/mapnik/feature_style_processor_impl.hpp @@ -592,7 +592,7 @@ void feature_style_processor::render_style(Processor& p, util::apply_visitor(symbolizer_dispatch(p, *feature, prj_trans), sym); } } - if (style->get_filter_mode() == FILTER_FIRST) + if (style->get_filter_mode() == filter_mode_enum::FILTER_FIRST) { // Stop iterating over rules and proceed with next feature. do_also = false; diff --git a/include/mapnik/feature_type_style.hpp b/include/mapnik/feature_type_style.hpp index 76a6c1b20..238622021 100644 --- a/include/mapnik/feature_type_style.hpp +++ b/include/mapnik/feature_type_style.hpp @@ -43,7 +43,7 @@ namespace mapnik { class rule; -enum filter_mode_enum { FILTER_ALL, FILTER_FIRST, filter_mode_enum_MAX }; +enum class filter_mode_enum { FILTER_ALL, FILTER_FIRST, filter_mode_enum_MAX }; DEFINE_ENUM(filter_mode_e, filter_mode_enum); diff --git a/include/mapnik/image_filter_grammar_x3_def.hpp b/include/mapnik/image_filter_grammar_x3_def.hpp index b51a40801..ecbf9826f 100644 --- a/include/mapnik/image_filter_grammar_x3_def.hpp +++ b/include/mapnik/image_filter_grammar_x3_def.hpp @@ -57,41 +57,35 @@ namespace x3 = boost::spirit::x3; namespace image_filter { -using x3::attr; -using x3::char_; using x3::double_; -using x3::hex; using x3::lit; -using x3::no_case; -using x3::no_skip; -using x3::omit; using x3::symbols; using x3::uint_parser; -auto push_back = [](auto& ctx) { +const auto push_back = [](auto& ctx) { _val(ctx).push_back(_attr(ctx)); }; -auto set_rx_ry = [](auto& ctx) { +const auto set_rx_ry = [](auto& ctx) { _val(ctx).rx = _val(ctx).ry = _attr(ctx); }; -auto set_ry = [](auto& ctx) { +const auto set_ry = [](auto& ctx) { _val(ctx).ry = _attr(ctx); }; -auto offset_value = [](auto& ctx) { +const auto offset_value = [](auto& ctx) { _val(ctx) = _attr(ctx); }; -auto percent = [](auto& ctx) { +const auto percent = [](auto& ctx) { double val = std::abs(_val(ctx) / 100.0); if (val > 1.0) val = 1.0; _val(ctx) = val; }; -x3::uint_parser radius; +const x3::uint_parser radius; // Import the expression rule namespace { diff --git a/include/mapnik/json/feature_grammar_x3_def.hpp b/include/mapnik/json/feature_grammar_x3_def.hpp index ac5ad68fe..a3b518928 100644 --- a/include/mapnik/json/feature_grammar_x3_def.hpp +++ b/include/mapnik/json/feature_grammar_x3_def.hpp @@ -154,14 +154,14 @@ struct geometry_type_ : x3::symbols ("\"GeometryCollection\"", mapnik::geometry::geometry_types::GeometryCollection) // ; } -} geometry_type_symbols; +} const geometry_type_symbols; namespace { -auto assign_name = [](auto const& ctx) { +const auto assign_name = [](auto const& ctx) { std::get<0>(_val(ctx)) = std::move(_attr(ctx)); }; -auto assign_value = [](auto const& ctx) { +const auto assign_value = [](auto const& ctx) { std::get<1>(_val(ctx)) = std::move(_attr(ctx)); }; @@ -207,7 +207,7 @@ auto const assign_collection = [](auto const& ctx) { std::get<2>(_val(ctx)) = std::move(_attr(ctx)); }; -auto assign_property = [](auto const& ctx) { +const auto assign_property = [](auto const& ctx) { mapnik::feature_impl& feature = x3::get(ctx); mapnik::transcoder const& tr = x3::get(ctx); feature.put_new(std::get<0>(_attr(ctx)), diff --git a/include/mapnik/json/generic_json_grammar_x3_def.hpp b/include/mapnik/json/generic_json_grammar_x3_def.hpp index dcd1cd9be..ca7801b86 100644 --- a/include/mapnik/json/generic_json_grammar_x3_def.hpp +++ b/include/mapnik/json/generic_json_grammar_x3_def.hpp @@ -35,39 +35,36 @@ namespace x3 = boost::spirit::x3; namespace { -auto make_null = [](auto const& ctx) { +const auto make_null = [](auto const& ctx) { _val(ctx) = mapnik::value_null{}; }; -auto make_true = [](auto const& ctx) { +const auto make_true = [](auto const& ctx) { _val(ctx) = true; }; -auto make_false = [](auto const& ctx) { +const auto make_false = [](auto const& ctx) { _val(ctx) = false; }; -auto assign = [](auto const& ctx) { +const auto assign = [](auto const& ctx) { _val(ctx) = std::move(_attr(ctx)); }; -auto assign_key = [](auto const& ctx) { +const auto assign_key = [](auto const& ctx) { std::get<0>(_val(ctx)) = std::move(_attr(ctx)); }; -auto assign_value = [](auto const& ctx) { +const auto assign_value = [](auto const& ctx) { std::get<1>(_val(ctx)) = std::move(_attr(ctx)); }; } // namespace using x3::lit; -using x3::string; // import unicode string rule -namespace { -auto const& json_string = mapnik::json::grammar::unicode_string; -} +const auto json_string = mapnik::json::grammar::unicode_string; // rules x3::rule const object("JSON Object"); diff --git a/include/mapnik/json/geojson_grammar_x3_def.hpp b/include/mapnik/json/geojson_grammar_x3_def.hpp index 2fab6b902..db3257a48 100644 --- a/include/mapnik/json/geojson_grammar_x3_def.hpp +++ b/include/mapnik/json/geojson_grammar_x3_def.hpp @@ -35,30 +35,30 @@ namespace grammar { namespace x3 = boost::spirit::x3; -auto make_null = [](auto const& ctx) { +const auto make_null = [](auto const& ctx) { _val(ctx) = mapnik::value_null{}; }; -auto make_true = [](auto const& ctx) { +const auto make_true = [](auto const& ctx) { _val(ctx) = true; }; -auto make_false = [](auto const& ctx) { +const auto make_false = [](auto const& ctx) { _val(ctx) = false; }; -auto assign = [](auto const& ctx) { +const auto assign = [](auto const& ctx) { _val(ctx) = std::move(_attr(ctx)); }; -auto assign_key = [](auto const& ctx) { +const auto assign_key = [](auto const& ctx) { std::string const& name = _attr(ctx); keys_map& keys = x3::get(ctx); auto result = keys.insert(keys_map::value_type(name, keys.size() + 1)); std::get<0>(_val(ctx)) = result.first->right; }; -auto assign_value = [](auto const& ctx) { +const auto assign_value = [](auto const& ctx) { std::get<1>(_val(ctx)) = std::move(_attr(ctx)); }; @@ -81,7 +81,7 @@ struct geometry_type_ : x3::symbols ("\"GeometryCollection\"", mapnik::geometry::geometry_types::GeometryCollection) // ; } -} geometry_type_sym; +} const geometry_type_sym; // rules x3::rule const object("JSON Object"); @@ -95,13 +95,9 @@ auto const geojson_double = x3::real_parser(); // import unicode string rule -namespace { -auto const& geojson_string = unicode_string; -} +const auto geojson_string = unicode_string; // import positions rule -namespace { -auto const& positions_rule = positions; -} +const auto positions_rule = positions; // GeoJSON types // clang-format off diff --git a/include/mapnik/json/positions_grammar_x3_def.hpp b/include/mapnik/json/positions_grammar_x3_def.hpp index da9ab75d5..e4399d759 100644 --- a/include/mapnik/json/positions_grammar_x3_def.hpp +++ b/include/mapnik/json/positions_grammar_x3_def.hpp @@ -33,14 +33,11 @@ namespace grammar { namespace x3 = boost::spirit::x3; using x3::double_; using x3::lit; -using x3::no_case; using x3::omit; -namespace { -auto assign_helper = [](auto const& ctx) { +const auto assign_helper = [](auto const& ctx) { _val(ctx) = std::move(_attr(ctx)); }; -} // namespace // rules x3::rule const point("Position"); diff --git a/include/mapnik/json/topojson_grammar_x3_def.hpp b/include/mapnik/json/topojson_grammar_x3_def.hpp index 6a4d02026..40b083915 100644 --- a/include/mapnik/json/topojson_grammar_x3_def.hpp +++ b/include/mapnik/json/topojson_grammar_x3_def.hpp @@ -169,7 +169,7 @@ struct create_multi_polygon } }; -auto create_geometry = [](auto const& ctx) { +const auto create_geometry = [](auto const& ctx) { auto const geom_type = std::get<0>(_attr(ctx)); auto const& coord = std::get<1>(_attr(ctx)); auto const& arcs = std::get<2>(_attr(ctx)); @@ -199,27 +199,27 @@ auto create_geometry = [](auto const& ctx) { _val(ctx) = std::move(geom); }; -auto assign_bbox = [](auto const& ctx) { +const auto assign_bbox = [](auto const& ctx) { _val(ctx).bbox = std::move(_attr(ctx)); }; -auto assign_transform = [](auto const& ctx) { +const auto assign_transform = [](auto const& ctx) { _val(ctx).tr = std::move(_attr(ctx)); }; -auto assign_arcs = [](auto const& ctx) { +const auto assign_arcs = [](auto const& ctx) { _val(ctx).arcs = std::move(_attr(ctx)); }; -auto assign_objects = [](auto const& ctx) { +const auto assign_objects = [](auto const& ctx) { _val(ctx).geometries = std::move(_attr(ctx)); }; -auto push_geometry = [](auto const& ctx) { +const auto push_geometry = [](auto const& ctx) { _val(ctx).push_back(std::move(_attr(ctx))); }; -auto push_collection = [](auto const& ctx) { +const auto push_collection = [](auto const& ctx) { auto& dest = _val(ctx); auto& src = _attr(ctx); if (dest.empty()) @@ -231,27 +231,27 @@ auto push_collection = [](auto const& ctx) { } }; -auto assign_geometry_type = [](auto const& ctx) { +const auto assign_geometry_type = [](auto const& ctx) { std::get<0>(_val(ctx)) = _attr(ctx); }; -auto assign_coordinates = [](auto const& ctx) { +const auto assign_coordinates = [](auto const& ctx) { std::get<1>(_val(ctx)) = std::move(_attr(ctx)); }; -auto assign_rings = [](auto const& ctx) { +const auto assign_rings = [](auto const& ctx) { std::get<2>(_val(ctx)) = std::move(_attr(ctx)); }; -auto assign_properties = [](auto const& ctx) { +const auto assign_properties = [](auto const& ctx) { std::get<3>(_val(ctx)) = std::move(_attr(ctx)); }; -auto assign_prop_name = [](auto const& ctx) { +const auto assign_prop_name = [](auto const& ctx) { std::get<0>(_val(ctx)) = std::move(_attr(ctx)); }; -auto assign_prop_value = [](auto const& ctx) { +const auto assign_prop_value = [](auto const& ctx) { std::get<1>(_val(ctx)) = std::move(_attr(ctx)); }; @@ -262,12 +262,10 @@ using x3::int_; using x3::lit; using x3::omit; -namespace { // import unicode string rule -auto const& json_string = json::grammar::unicode_string; +const auto json_string = json::grammar::unicode_string; // json value -auto const& json_value = json::grammar::value; -} // namespace +const auto json_value = json::grammar::value; using coordinates_type = util::variant>; using arcs_type = util::variant, @@ -287,7 +285,7 @@ struct topojson_geometry_type_ : x3::symbols ("\"MultiPolygon\"", 6) // ; } -} topojson_geometry_type; +} const topojson_geometry_type; // rules x3::rule const transform = "Transform"; diff --git a/include/mapnik/json/unicode_string_grammar_x3_def.hpp b/include/mapnik/json/unicode_string_grammar_x3_def.hpp index 6a8c77eb1..cbd854532 100644 --- a/include/mapnik/json/unicode_string_grammar_x3_def.hpp +++ b/include/mapnik/json/unicode_string_grammar_x3_def.hpp @@ -35,7 +35,7 @@ namespace x3 = boost::spirit::x3; using uchar = std::uint32_t; // a unicode code point -auto append = [](auto const& ctx) { +const auto append = [](auto const& ctx) { _val(ctx) += _attr(ctx); }; @@ -50,15 +50,15 @@ static inline void push_utf8_impl(std::string& str, uchar code_point) } } // namespace detail -auto push_char = [](auto const& ctx) { +const auto push_char = [](auto const& ctx) { _val(ctx).push_back(_attr(ctx)); }; -auto push_utf8 = [](auto const& ctx) { +const auto push_utf8 = [](auto const& ctx) { detail::push_utf8_impl(_val(ctx), _attr(ctx)); }; -auto push_utf16 = [](auto const& ctx) { +const auto push_utf16 = [](auto const& ctx) { using iterator_type = std::vector::const_iterator; auto const& utf16 = _attr(ctx); try @@ -76,7 +76,7 @@ auto push_utf16 = [](auto const& ctx) { } }; -auto push_esc = [](auto const& ctx) { +const auto push_esc = [](auto const& ctx) { std::string& utf8 = _val(ctx); char c = _attr(ctx); switch (c) diff --git a/include/mapnik/mapnik.hpp b/include/mapnik/mapnik.hpp new file mode 100644 index 000000000..e1545a48d --- /dev/null +++ b/include/mapnik/mapnik.hpp @@ -0,0 +1,9 @@ +#ifndef MAPNIK_MAPNIK_HPP +#define MAPNIK_MAPNIK_HPP +#include "config.hpp" + +namespace mapnik { +MAPNIK_DECL void setup(); +} + +#endif diff --git a/include/mapnik/markers_placement.hpp b/include/mapnik/markers_placement.hpp index bb1a09be3..7af01b69c 100644 --- a/include/mapnik/markers_placement.hpp +++ b/include/mapnik/markers_placement.hpp @@ -46,26 +46,26 @@ class markers_placement_finder : util::noncopyable switch (marker_placement_enum(placement_type)) { default: - case MARKER_POINT_PLACEMENT: + case marker_placement_enum::MARKER_POINT_PLACEMENT: construct(&point_, locator, detector, params); break; - case MARKER_ANGLED_POINT_PLACEMENT: + case marker_placement_enum::MARKER_ANGLED_POINT_PLACEMENT: construct(&point_, locator, detector, params); point_.use_angle(true); break; - case MARKER_INTERIOR_PLACEMENT: + case marker_placement_enum::MARKER_INTERIOR_PLACEMENT: construct(&interior_, locator, detector, params); break; - case MARKER_LINE_PLACEMENT: + case marker_placement_enum::MARKER_LINE_PLACEMENT: construct(&line_, locator, detector, params); break; - case MARKER_VERTEX_FIRST_PLACEMENT: + case marker_placement_enum::MARKER_VERTEX_FIRST_PLACEMENT: construct(&vertex_first_, locator, detector, params); break; - case MARKER_VERTEX_LAST_PLACEMENT: + case marker_placement_enum::MARKER_VERTEX_LAST_PLACEMENT: construct(&vertex_last_, locator, detector, params); break; - case MARKER_POLYLABEL_PLACEMENT: + case marker_placement_enum::MARKER_POLYLABEL_PLACEMENT: construct(&polylabel_, locator, detector, params); break; } @@ -73,26 +73,26 @@ class markers_placement_finder : util::noncopyable ~markers_placement_finder() { - switch (marker_placement_enum(placement_type_)) + switch (marker_placement_enum{placement_type_}) { default: - case MARKER_POINT_PLACEMENT: - case MARKER_ANGLED_POINT_PLACEMENT: + case marker_placement_enum::MARKER_POINT_PLACEMENT: + case marker_placement_enum::MARKER_ANGLED_POINT_PLACEMENT: destroy(&point_); break; - case MARKER_INTERIOR_PLACEMENT: + case marker_placement_enum::MARKER_INTERIOR_PLACEMENT: destroy(&interior_); break; - case MARKER_LINE_PLACEMENT: + case marker_placement_enum::MARKER_LINE_PLACEMENT: destroy(&line_); break; - case MARKER_VERTEX_FIRST_PLACEMENT: + case marker_placement_enum::MARKER_VERTEX_FIRST_PLACEMENT: destroy(&vertex_first_); break; - case MARKER_VERTEX_LAST_PLACEMENT: + case marker_placement_enum::MARKER_VERTEX_LAST_PLACEMENT: destroy(&vertex_last_); break; - case MARKER_POLYLABEL_PLACEMENT: + case marker_placement_enum::MARKER_POLYLABEL_PLACEMENT: destroy(&polylabel_); break; } @@ -101,21 +101,21 @@ class markers_placement_finder : util::noncopyable // Get next point where the marker should be placed. Returns true if a place is found, false if none is found. bool get_point(double& x, double& y, double& angle, bool ignore_placement) { - switch (marker_placement_enum(placement_type_)) + switch (marker_placement_enum{placement_type_}) { default: - case MARKER_POINT_PLACEMENT: - case MARKER_ANGLED_POINT_PLACEMENT: + case marker_placement_enum::MARKER_POINT_PLACEMENT: + case marker_placement_enum::MARKER_ANGLED_POINT_PLACEMENT: return point_.get_point(x, y, angle, ignore_placement); - case MARKER_INTERIOR_PLACEMENT: + case marker_placement_enum::MARKER_INTERIOR_PLACEMENT: return interior_.get_point(x, y, angle, ignore_placement); - case MARKER_LINE_PLACEMENT: + case marker_placement_enum::MARKER_LINE_PLACEMENT: return line_.get_point(x, y, angle, ignore_placement); - case MARKER_VERTEX_FIRST_PLACEMENT: + case marker_placement_enum::MARKER_VERTEX_FIRST_PLACEMENT: return vertex_first_.get_point(x, y, angle, ignore_placement); - case MARKER_VERTEX_LAST_PLACEMENT: + case marker_placement_enum::MARKER_VERTEX_LAST_PLACEMENT: return vertex_last_.get_point(x, y, angle, ignore_placement); - case MARKER_POLYLABEL_PLACEMENT: + case marker_placement_enum::MARKER_POLYLABEL_PLACEMENT: return polylabel_.get_point(x, y, angle, ignore_placement); } } diff --git a/include/mapnik/markers_placements/basic.hpp b/include/mapnik/markers_placements/basic.hpp index 44d82509d..7a37cc5a1 100644 --- a/include/mapnik/markers_placements/basic.hpp +++ b/include/mapnik/markers_placements/basic.hpp @@ -32,7 +32,6 @@ #include MAPNIK_DISABLE_WARNING_PUSH #include -#include "agg_basics.h" #include "agg_trans_affine.h" MAPNIK_DISABLE_WARNING_POP @@ -72,32 +71,32 @@ class markers_basic_placement : util::noncopyable { switch (params_.direction) { - case DIRECTION_UP: + case direction_enum::DIRECTION_UP: angle = 0; return true; - case DIRECTION_DOWN: + case direction_enum::DIRECTION_DOWN: angle = util::pi; return true; - case DIRECTION_AUTO: + case direction_enum::DIRECTION_AUTO: angle = util::normalize_angle(angle); if (std::abs(angle) > util::pi / 2) angle += util::pi; return true; - case DIRECTION_AUTO_DOWN: + case direction_enum::DIRECTION_AUTO_DOWN: angle = util::normalize_angle(angle); if (std::abs(angle) < util::pi / 2) angle += util::pi; return true; - case DIRECTION_LEFT: + case direction_enum::DIRECTION_LEFT: angle += util::pi; return true; - case DIRECTION_LEFT_ONLY: + case direction_enum::DIRECTION_LEFT_ONLY: angle = util::normalize_angle(angle + util::pi); return std::fabs(angle) < util::pi / 2; - case DIRECTION_RIGHT_ONLY: + case direction_enum::DIRECTION_RIGHT_ONLY: angle = util::normalize_angle(angle); return std::fabs(angle) < util::pi / 2; - case DIRECTION_RIGHT: + case direction_enum::DIRECTION_RIGHT: default: return true; } diff --git a/include/mapnik/memory_datasource.hpp b/include/mapnik/memory_datasource.hpp index 833b3c09e..9591c8181 100644 --- a/include/mapnik/memory_datasource.hpp +++ b/include/mapnik/memory_datasource.hpp @@ -26,12 +26,14 @@ // mapnik #include #include +#include // stl #include namespace mapnik { +DATASOURCE_PLUGIN_DEF(memory_datasource_plugin, memory) class MAPNIK_DECL memory_datasource : public datasource { friend class memory_featureset; diff --git a/include/mapnik/path_expression_grammar_x3_def.hpp b/include/mapnik/path_expression_grammar_x3_def.hpp index f137868f3..3600fa986 100644 --- a/include/mapnik/path_expression_grammar_x3_def.hpp +++ b/include/mapnik/path_expression_grammar_x3_def.hpp @@ -32,10 +32,10 @@ namespace grammar { namespace x3 = boost::spirit::x3; using x3::lexeme; using x3::standard_wide::char_; -auto create_string = [](auto& ctx) { +const auto create_string = [](auto& ctx) { _val(ctx).push_back(_attr(ctx)); }; -auto create_attribute = [](auto& ctx) { +const auto create_attribute = [](auto& ctx) { _val(ctx).push_back(mapnik::attribute(_attr(ctx))); }; // rules diff --git a/include/mapnik/plugin.hpp b/include/mapnik/plugin.hpp index 46c06c421..d1907411d 100644 --- a/include/mapnik/plugin.hpp +++ b/include/mapnik/plugin.hpp @@ -25,9 +25,9 @@ // mapnik #include - // stl #include +#include namespace mapnik { @@ -45,13 +45,10 @@ class PluginInfo : util::noncopyable bool valid() const; std::string get_error() const; void* get_symbol(std::string const& sym_name) const; - static void init(); - static void exit(); private: std::string filename_; - std::string name_; - mapnik_lib_t* module_; + std::unique_ptr module_; }; } // namespace mapnik diff --git a/include/mapnik/raster_colorizer.hpp b/include/mapnik/raster_colorizer.hpp index 217e6def7..9813c724a 100644 --- a/include/mapnik/raster_colorizer.hpp +++ b/include/mapnik/raster_colorizer.hpp @@ -57,7 +57,7 @@ class feature_impl; class raster; //! \brief Enumerates the modes of interpolation -enum colorizer_mode_enum : std::uint8_t { +enum class colorizer_mode_enum : std::uint8_t { COLORIZER_INHERIT = 0, //!< The stop inherits the mode from the colorizer COLORIZER_LINEAR = 1, //!< Linear interpolation between colors, each channel separately COLORIZER_DISCRETE = 2, //!< Single color for stop @@ -80,7 +80,7 @@ class MAPNIK_DECL colorizer_stop //! \param[in] mode The stop mode //! \param[in] _color The stop color colorizer_stop(float value = 0, - colorizer_mode mode = COLORIZER_INHERIT, + colorizer_mode mode = colorizer_mode_enum::COLORIZER_INHERIT, color const& _color = color(0, 0, 0, 0), std::string const& label = ""); @@ -146,7 +146,8 @@ class MAPNIK_DECL raster_colorizer { public: //! \brief Constructor - raster_colorizer(colorizer_mode mode = COLORIZER_LINEAR, color const& _color = color(0, 0, 0, 0)); + raster_colorizer(colorizer_mode mode = colorizer_mode_enum::COLORIZER_LINEAR, + color const& _color = color(0, 0, 0, 0)); //! \brief Destructor ~raster_colorizer(); @@ -158,7 +159,8 @@ class MAPNIK_DECL raster_colorizer void set_default_mode(colorizer_mode mode) { - default_mode_ = (mode == COLORIZER_INHERIT) ? COLORIZER_LINEAR : static_cast(mode); + default_mode_ = + (mode == colorizer_mode_enum::COLORIZER_INHERIT) ? colorizer_mode_enum::COLORIZER_LINEAR : mode.value_; } void set_default_mode_enum(colorizer_mode_enum mode) { set_default_mode(mode); } diff --git a/include/mapnik/renderer_common/process_point_symbolizer.hpp b/include/mapnik/renderer_common/process_point_symbolizer.hpp index b5a944d68..fc62855ec 100644 --- a/include/mapnik/renderer_common/process_point_symbolizer.hpp +++ b/include/mapnik/renderer_common/process_point_symbolizer.hpp @@ -52,28 +52,28 @@ void render_point_symbolizer(point_symbolizer const& sym, if (!mark->is()) { - value_double opacity = get(sym, feature, common.vars_); - value_bool allow_overlap = get(sym, feature, common.vars_); - value_bool ignore_placement = get(sym, feature, common.vars_); - point_placement_enum placement = + const value_double opacity = get(sym, feature, common.vars_); + const value_bool allow_overlap = get(sym, feature, common.vars_); + const value_bool ignore_placement = get(sym, feature, common.vars_); + const point_placement_enum placement = get(sym, feature, common.vars_); - box2d const& bbox = mark->bounding_box(); - coord2d center = bbox.center(); + const box2d& bbox = mark->bounding_box(); + const coord2d center = bbox.center(); agg::trans_affine tr; - auto image_transform = get_optional(sym, keys::image_transform); + const auto image_transform = get_optional(sym, keys::image_transform); if (image_transform) evaluate_transform(tr, feature, common.vars_, *image_transform, common.scale_factor_); - agg::trans_affine_translation recenter(-center.x, -center.y); - agg::trans_affine recenter_tr = recenter * tr; + const agg::trans_affine_translation recenter(-center.x, -center.y); + const agg::trans_affine recenter_tr = recenter * tr; box2d label_ext = bbox * recenter_tr * agg::trans_affine_scaling(common.scale_factor_); - mapnik::geometry::geometry const& geometry = feature.get_geometry(); + const mapnik::geometry::geometry& geometry = feature.get_geometry(); mapnik::geometry::point pt; geometry::geometry_types type = geometry::geometry_type(geometry); - if (placement == CENTROID_POINT_PLACEMENT || type == geometry::geometry_types::Point || + if (placement == point_placement_enum::CENTROID_POINT_PLACEMENT || type == geometry::geometry_types::Point || type == geometry::geometry_types::MultiPoint) { if (!geometry::centroid(geometry, pt)) diff --git a/include/mapnik/symbolizer.hpp b/include/mapnik/symbolizer.hpp index f6c93a32b..b24dab7e4 100644 --- a/include/mapnik/symbolizer.hpp +++ b/include/mapnik/symbolizer.hpp @@ -147,14 +147,14 @@ struct enum_traits static result_type from_string(std::string const& str) { return simplify_algorithm_from_string(str); } }; -#define ENUM_FROM_STRING(e) \ +#define ENUM_FROM_STRING(alias, e) \ template<> \ struct enum_traits \ { \ using result_type = boost::optional; \ static result_type from_string(std::string const& str) \ { \ - enumeration enum_; \ + enumeration enum_; \ try \ { \ enum_.from_string(str); \ @@ -166,26 +166,25 @@ struct enum_traits } \ } \ }; - -ENUM_FROM_STRING(line_cap_enum) -ENUM_FROM_STRING(line_join_enum) -ENUM_FROM_STRING(point_placement_enum) -ENUM_FROM_STRING(line_rasterizer_enum) -ENUM_FROM_STRING(marker_placement_enum) -ENUM_FROM_STRING(marker_multi_policy_enum) -ENUM_FROM_STRING(debug_symbolizer_mode_enum) -ENUM_FROM_STRING(pattern_alignment_enum) -ENUM_FROM_STRING(halo_rasterizer_enum) -ENUM_FROM_STRING(label_placement_enum) -ENUM_FROM_STRING(vertical_alignment_enum) -ENUM_FROM_STRING(horizontal_alignment_enum) -ENUM_FROM_STRING(justify_alignment_enum) -ENUM_FROM_STRING(text_transform_enum) -ENUM_FROM_STRING(text_upright_enum) -ENUM_FROM_STRING(direction_enum) -ENUM_FROM_STRING(gamma_method_enum) -ENUM_FROM_STRING(line_pattern_enum) -ENUM_FROM_STRING(smooth_algorithm_enum) +ENUM_FROM_STRING(line_cap_e, line_cap_enum) +ENUM_FROM_STRING(line_join_e, line_join_enum) +ENUM_FROM_STRING(point_placement_e, point_placement_enum) +ENUM_FROM_STRING(line_rasterizer_e, line_rasterizer_enum) +ENUM_FROM_STRING(marker_placement_e, marker_placement_enum) +ENUM_FROM_STRING(marker_multi_policy_e, marker_multi_policy_enum) +ENUM_FROM_STRING(debug_symbolizer_mode_e, debug_symbolizer_mode_enum) +ENUM_FROM_STRING(pattern_alignment_e, pattern_alignment_enum) +ENUM_FROM_STRING(halo_rasterizer_e, halo_rasterizer_enum) +ENUM_FROM_STRING(label_placement_e, label_placement_enum) +ENUM_FROM_STRING(vertical_alignment_e, vertical_alignment_enum) +ENUM_FROM_STRING(horizontal_alignment_e, horizontal_alignment_enum) +ENUM_FROM_STRING(justify_alignment_e, justify_alignment_enum) +ENUM_FROM_STRING(text_transform_e, text_transform_enum) +ENUM_FROM_STRING(text_upright_e, text_upright_enum) +ENUM_FROM_STRING(direction_e, direction_enum) +ENUM_FROM_STRING(gamma_method_e, gamma_method_enum) +ENUM_FROM_STRING(line_pattern_e, line_pattern_enum) +ENUM_FROM_STRING(smooth_algorithm_e, smooth_algorithm_enum) // enum template diff --git a/include/mapnik/symbolizer_base.hpp b/include/mapnik/symbolizer_base.hpp index acd92cb32..734a20f50 100644 --- a/include/mapnik/symbolizer_base.hpp +++ b/include/mapnik/symbolizer_base.hpp @@ -69,7 +69,7 @@ struct enumeration_wrapper enumeration_wrapper() = delete; template explicit enumeration_wrapper(T value_) - : value(value_) + : value(static_cast(value_)) {} inline bool operator==(enumeration_wrapper const& rhs) const { return value == rhs.value; } diff --git a/include/mapnik/symbolizer_default_values.hpp b/include/mapnik/symbolizer_default_values.hpp index 1835c04d3..a9b05f45b 100644 --- a/include/mapnik/symbolizer_default_values.hpp +++ b/include/mapnik/symbolizer_default_values.hpp @@ -50,7 +50,7 @@ struct symbolizer_default template<> struct symbolizer_default { - static gamma_method_enum value() { return GAMMA_POWER; } + static gamma_method_enum value() { return gamma_method_enum::GAMMA_POWER; } }; // opacity @@ -64,7 +64,7 @@ struct symbolizer_default template<> struct symbolizer_default { - static pattern_alignment_enum value() { return GLOBAL_ALIGNMENT; } + static pattern_alignment_enum value() { return pattern_alignment_enum::GLOBAL_ALIGNMENT; } }; // offset @@ -127,14 +127,14 @@ struct symbolizer_default template<> struct symbolizer_default { - static line_join_enum value() { return MITER_JOIN; } + static line_join_enum value() { return line_join_enum::MITER_JOIN; } }; // stroke-linecap template<> struct symbolizer_default { - static line_cap_enum value() { return BUTT_CAP; } + static line_cap_enum value() { return line_cap_enum::BUTT_CAP; } }; // stroke-gamma @@ -148,7 +148,7 @@ struct symbolizer_default template<> struct symbolizer_default { - static gamma_method_enum value() { return GAMMA_POWER; } + static gamma_method_enum value() { return gamma_method_enum::GAMMA_POWER; } }; // stroke-dashoffset @@ -173,7 +173,7 @@ struct symbolizer_default template<> struct symbolizer_default { - static line_rasterizer_enum value() { return RASTERIZER_FULL; } + static line_rasterizer_enum value() { return line_rasterizer_enum::RASTERIZER_FULL; } }; // transform @@ -315,7 +315,7 @@ struct symbolizer_default template<> struct symbolizer_default { - static halo_rasterizer_enum value() { return HALO_RASTERIZER_FULL; } + static halo_rasterizer_enum value() { return halo_rasterizer_enum::HALO_RASTERIZER_FULL; } }; // text-placements @@ -324,28 +324,28 @@ struct symbolizer_default template<> struct symbolizer_default { - static point_placement_enum value() { return CENTROID_POINT_PLACEMENT; } + static point_placement_enum value() { return point_placement_enum::CENTROID_POINT_PLACEMENT; } }; // marker placement template<> struct symbolizer_default { - static marker_placement_enum value() { return MARKER_POINT_PLACEMENT; } + static marker_placement_enum value() { return marker_placement_enum::MARKER_POINT_PLACEMENT; } }; // multi-policy template<> struct symbolizer_default { - static marker_multi_policy_enum value() { return MARKER_EACH_MULTI; } + static marker_multi_policy_enum value() { return marker_multi_policy_enum::MARKER_EACH_MULTI; } }; // direction template<> struct symbolizer_default { - static direction_enum value() { return DIRECTION_RIGHT; } + static direction_enum value() { return direction_enum::DIRECTION_RIGHT; } }; // placement @@ -380,7 +380,7 @@ struct symbolizer_default template<> struct symbolizer_default { - static line_pattern_enum value() { return LINE_PATTERN_WARP; } + static line_pattern_enum value() { return line_pattern_enum::LINE_PATTERN_WARP; } }; // extend @@ -393,7 +393,7 @@ struct symbolizer_default template<> struct symbolizer_default { - static smooth_algorithm_enum value() { return SMOOTH_ALGORITHM_BASIC; } + static smooth_algorithm_enum value() { return smooth_algorithm_enum::SMOOTH_ALGORITHM_BASIC; } }; } // namespace mapnik diff --git a/include/mapnik/symbolizer_enumerations.hpp b/include/mapnik/symbolizer_enumerations.hpp index 6131f0e46..8c2477f67 100644 --- a/include/mapnik/symbolizer_enumerations.hpp +++ b/include/mapnik/symbolizer_enumerations.hpp @@ -27,50 +27,43 @@ namespace mapnik { -enum line_cap_enum : std::uint8_t { BUTT_CAP, SQUARE_CAP, ROUND_CAP, line_cap_enum_MAX }; - +enum class line_cap_enum : std::uint8_t { BUTT_CAP, SQUARE_CAP, ROUND_CAP, line_cap_enum_MAX }; DEFINE_ENUM(line_cap_e, line_cap_enum); -enum line_join_enum : std::uint8_t { MITER_JOIN, MITER_REVERT_JOIN, ROUND_JOIN, BEVEL_JOIN, line_join_enum_MAX }; - +enum class line_join_enum : std::uint8_t { MITER_JOIN, MITER_REVERT_JOIN, ROUND_JOIN, BEVEL_JOIN, line_join_enum_MAX }; DEFINE_ENUM(line_join_e, line_join_enum); -enum line_rasterizer_enum : std::uint8_t { +enum class line_rasterizer_enum : std::uint8_t { RASTERIZER_FULL, // agg::renderer_scanline_aa_solid RASTERIZER_FAST, // agg::rasterizer_outline_aa, twice as fast but only good for thin lines line_rasterizer_enum_MAX }; - DEFINE_ENUM(line_rasterizer_e, line_rasterizer_enum); -enum halo_rasterizer_enum : std::uint8_t { HALO_RASTERIZER_FULL, HALO_RASTERIZER_FAST, halo_rasterizer_enum_MAX }; - +enum class halo_rasterizer_enum : std::uint8_t { HALO_RASTERIZER_FULL, HALO_RASTERIZER_FAST, halo_rasterizer_enum_MAX }; DEFINE_ENUM(halo_rasterizer_e, halo_rasterizer_enum); -enum point_placement_enum : std::uint8_t { +enum class point_placement_enum : std::uint8_t { CENTROID_POINT_PLACEMENT, INTERIOR_POINT_PLACEMENT, point_placement_enum_MAX }; - DEFINE_ENUM(point_placement_e, point_placement_enum); -enum pattern_alignment_enum : std::uint8_t { LOCAL_ALIGNMENT, GLOBAL_ALIGNMENT, pattern_alignment_enum_MAX }; - +enum class pattern_alignment_enum : std::uint8_t { LOCAL_ALIGNMENT, GLOBAL_ALIGNMENT, pattern_alignment_enum_MAX }; DEFINE_ENUM(pattern_alignment_e, pattern_alignment_enum); -enum debug_symbolizer_mode_enum : std::uint8_t { +enum class debug_symbolizer_mode_enum : std::uint8_t { DEBUG_SYM_MODE_COLLISION, DEBUG_SYM_MODE_VERTEX, DEBUG_SYM_MODE_RINGS, debug_symbolizer_mode_enum_MAX }; - DEFINE_ENUM(debug_symbolizer_mode_e, debug_symbolizer_mode_enum); // markers // TODO - consider merging with text_symbolizer label_placement_e -enum marker_placement_enum : std::uint8_t { +enum class marker_placement_enum : std::uint8_t { MARKER_POINT_PLACEMENT, MARKER_INTERIOR_PLACEMENT, MARKER_LINE_PLACEMENT, @@ -80,19 +73,17 @@ enum marker_placement_enum : std::uint8_t { MARKER_POLYLABEL_PLACEMENT, marker_placement_enum_MAX }; - DEFINE_ENUM(marker_placement_e, marker_placement_enum); -enum marker_multi_policy_enum : std::uint8_t { +enum class marker_multi_policy_enum : std::uint8_t { MARKER_EACH_MULTI, // each component in a multi gets its marker MARKER_WHOLE_MULTI, // consider all components of a multi as a whole MARKER_LARGEST_MULTI, // only the largest component of a multi gets a marker marker_multi_policy_enum_MAX }; - DEFINE_ENUM(marker_multi_policy_e, marker_multi_policy_enum); -enum text_transform_enum : std::uint8_t { +enum class text_transform_enum : std::uint8_t { NONE = 0, UPPERCASE, LOWERCASE, @@ -100,10 +91,9 @@ enum text_transform_enum : std::uint8_t { REVERSE, text_transform_enum_MAX }; - DEFINE_ENUM(text_transform_e, text_transform_enum); -enum label_placement_enum : std::uint8_t { +enum class label_placement_enum : std::uint8_t { POINT_PLACEMENT, LINE_PLACEMENT, VERTEX_PLACEMENT, @@ -113,14 +103,18 @@ enum label_placement_enum : std::uint8_t { ALTERNATING_GRID_PLACEMENT, label_placement_enum_MAX }; - DEFINE_ENUM(label_placement_e, label_placement_enum); -enum vertical_alignment_enum : std::uint8_t { V_TOP = 0, V_MIDDLE, V_BOTTOM, V_AUTO, vertical_alignment_enum_MAX }; - +enum class vertical_alignment_enum : std::uint8_t { + V_TOP = 0, + V_MIDDLE, + V_BOTTOM, + V_AUTO, + vertical_alignment_enum_MAX +}; DEFINE_ENUM(vertical_alignment_e, vertical_alignment_enum); -enum horizontal_alignment_enum : std::uint8_t { +enum class horizontal_alignment_enum : std::uint8_t { H_LEFT = 0, H_MIDDLE, H_RIGHT, @@ -128,14 +122,12 @@ enum horizontal_alignment_enum : std::uint8_t { H_ADJUST, horizontal_alignment_enum_MAX }; - DEFINE_ENUM(horizontal_alignment_e, horizontal_alignment_enum); -enum justify_alignment_enum : std::uint8_t { J_LEFT = 0, J_MIDDLE, J_RIGHT, J_AUTO, justify_alignment_enum_MAX }; - +enum class justify_alignment_enum : std::uint8_t { J_LEFT = 0, J_MIDDLE, J_RIGHT, J_AUTO, justify_alignment_enum_MAX }; DEFINE_ENUM(justify_alignment_e, justify_alignment_enum); -enum text_upright_enum : std::uint8_t { +enum class text_upright_enum : std::uint8_t { UPRIGHT_AUTO, UPRIGHT_AUTO_DOWN, UPRIGHT_LEFT, @@ -144,10 +136,9 @@ enum text_upright_enum : std::uint8_t { UPRIGHT_RIGHT_ONLY, text_upright_enum_MAX }; - DEFINE_ENUM(text_upright_e, text_upright_enum); -enum direction_enum : std::uint8_t { +enum class direction_enum : std::uint8_t { DIRECTION_LEFT, DIRECTION_RIGHT, DIRECTION_LEFT_ONLY, @@ -158,10 +149,9 @@ enum direction_enum : std::uint8_t { DIRECTION_DOWN, direction_enum_MAX }; - DEFINE_ENUM(direction_e, direction_enum); -enum gamma_method_enum : std::uint8_t { +enum class gamma_method_enum : std::uint8_t { GAMMA_POWER, // agg::gamma_power GAMMA_LINEAR, // agg::gamma_linear GAMMA_NONE, // agg::gamma_none @@ -169,19 +159,16 @@ enum gamma_method_enum : std::uint8_t { GAMMA_MULTIPLY, // agg::gamma_multiply gamma_method_enum_MAX }; - DEFINE_ENUM(gamma_method_e, gamma_method_enum); -enum line_pattern_enum : std::uint8_t { LINE_PATTERN_WARP, LINE_PATTERN_REPEAT, line_pattern_enum_MAX }; - +enum class line_pattern_enum : std::uint8_t { LINE_PATTERN_WARP, LINE_PATTERN_REPEAT, line_pattern_enum_MAX }; DEFINE_ENUM(line_pattern_e, line_pattern_enum); -enum smooth_algorithm_enum : std::uint8_t { +enum class smooth_algorithm_enum : std::uint8_t { SMOOTH_ALGORITHM_BASIC = 0, SMOOTH_ALGORITHM_ADAPTIVE, smooth_algorithm_enum_MAX }; - DEFINE_ENUM(smooth_algorithm_e, smooth_algorithm_enum); } // namespace mapnik diff --git a/include/mapnik/text/placement_finder_impl.hpp b/include/mapnik/text/placement_finder_impl.hpp index 432271b5f..fa8411402 100644 --- a/include/mapnik/text/placement_finder_impl.hpp +++ b/include/mapnik/text/placement_finder_impl.hpp @@ -65,12 +65,14 @@ bool placement_finder::find_line_placements(T& path, bool points) // horizontal_alignment_e halign = layouts_.back()->horizontal_alignment(); // halign == H_LEFT -> don't move - if (horizontal_alignment_ == H_MIDDLE || horizontal_alignment_ == H_AUTO || horizontal_alignment_ == H_ADJUST) + if (horizontal_alignment_ == horizontal_alignment_enum::H_MIDDLE || + horizontal_alignment_ == horizontal_alignment_enum::H_AUTO || + horizontal_alignment_ == horizontal_alignment_enum::H_ADJUST) { if (!pp.forward(spacing / 2.0)) continue; } - else if (horizontal_alignment_ == H_RIGHT) + else if (horizontal_alignment_ == horizontal_alignment_enum::H_RIGHT) { if (!pp.forward(pp.length())) continue; diff --git a/include/mapnik/text/properties_util.hpp b/include/mapnik/text/properties_util.hpp index 1cd4a0136..ade172348 100644 --- a/include/mapnik/text/properties_util.hpp +++ b/include/mapnik/text/properties_util.hpp @@ -46,7 +46,7 @@ struct is_mapnik_enumeration }; template -struct is_mapnik_enumeration::value>::type> +struct is_mapnik_enumeration::value>> { static constexpr bool value = true; }; @@ -117,7 +117,7 @@ struct set_property_from_xml_impl { target_enum_type e; e.from_string(*enum_str); - val = enumeration_wrapper(e); + val = enumeration_wrapper(e.value_); } } catch (...) diff --git a/include/mapnik/text/text_properties.hpp b/include/mapnik/text/text_properties.hpp index 187f3082e..7e157d24a 100644 --- a/include/mapnik/text/text_properties.hpp +++ b/include/mapnik/text/text_properties.hpp @@ -159,7 +159,7 @@ struct MAPNIK_DECL text_layout_properties struct text_properties_expressions { - symbolizer_base::value_type label_placement = enumeration_wrapper(POINT_PLACEMENT); + symbolizer_base::value_type label_placement = enumeration_wrapper(label_placement_enum::POINT_PLACEMENT); symbolizer_base::value_type label_spacing = 0.0; symbolizer_base::value_type label_position_tolerance = 0.0; symbolizer_base::value_type avoid_edges = false; @@ -171,7 +171,7 @@ struct text_properties_expressions symbolizer_base::value_type max_char_angle_delta = 22.5; symbolizer_base::value_type allow_overlap = false; symbolizer_base::value_type largest_bbox_only = true; - symbolizer_base::value_type upright = enumeration_wrapper(UPRIGHT_AUTO); + symbolizer_base::value_type upright = enumeration_wrapper(text_upright_enum::UPRIGHT_AUTO); symbolizer_base::value_type grid_cell_width = 0.0; symbolizer_base::value_type grid_cell_height = 0.0; }; diff --git a/include/mapnik/vertex_converters.hpp b/include/mapnik/vertex_converters.hpp index c56ba5a0d..c52daea9a 100644 --- a/include/mapnik/vertex_converters.hpp +++ b/include/mapnik/vertex_converters.hpp @@ -46,7 +46,6 @@ MAPNIK_DISABLE_WARNING_PUSH #include "agg_trans_affine.h" #include "agg_conv_clip_polygon.h" #include "agg_conv_clip_polyline.h" -#include "agg_conv_smooth_poly1.h" #include "agg_conv_stroke.h" #include "agg_conv_dash.h" #include "agg_conv_transform.h" @@ -156,30 +155,29 @@ struct converter_traits template void set_join_caps(Symbolizer const& sym, PathType& stroke, Feature const& feature, attributes const& vars) { - line_join_enum join = get(sym, feature, vars); + const line_join_enum join = get(sym, feature, vars); switch (join) { - case MITER_JOIN: + case line_join_enum::MITER_JOIN: stroke.generator().line_join(agg::miter_join); break; - case MITER_REVERT_JOIN: + case line_join_enum::MITER_REVERT_JOIN: stroke.generator().line_join(agg::miter_join); break; - case ROUND_JOIN: + case line_join_enum::ROUND_JOIN: stroke.generator().line_join(agg::round_join); break; default: stroke.generator().line_join(agg::bevel_join); } - line_cap_enum cap = get(sym, feature, vars); - + const line_cap_enum cap = get(sym, feature, vars); switch (cap) { - case BUTT_CAP: + case line_cap_enum::BUTT_CAP: stroke.generator().line_cap(agg::butt_cap); break; - case SQUARE_CAP: + case line_cap_enum::SQUARE_CAP: stroke.generator().line_cap(agg::square_cap); break; default: diff --git a/include/mapnik/webp_io.hpp b/include/mapnik/webp_io.hpp index 02a468ba0..404bcbaf3 100644 --- a/include/mapnik/webp_io.hpp +++ b/include/mapnik/webp_io.hpp @@ -24,6 +24,7 @@ #define MAPNIK_WEBP_IO_HPP // mapnik +#include #include #include @@ -50,45 +51,7 @@ int webp_stream_write(const uint8_t* data, size_t data_size, const WebPPicture* return true; } -std::string webp_encoding_error(WebPEncodingError error) -{ - std::string os; - switch (error) - { - case VP8_ENC_ERROR_OUT_OF_MEMORY: - os = "memory error allocating objects"; - break; - case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY: - os = "memory error while flushing bits"; - break; - case VP8_ENC_ERROR_NULL_PARAMETER: - os = "a pointer parameter is NULL"; - break; - case VP8_ENC_ERROR_INVALID_CONFIGURATION: - os = "configuration is invalid"; - break; - case VP8_ENC_ERROR_BAD_DIMENSION: - os = "picture has invalid width/height"; - break; - case VP8_ENC_ERROR_PARTITION0_OVERFLOW: - os = "partition is bigger than 512k"; - break; - case VP8_ENC_ERROR_PARTITION_OVERFLOW: - os = "partition is bigger than 16M"; - break; - case VP8_ENC_ERROR_BAD_WRITE: - os = "error while flushing bytes"; - break; - case VP8_ENC_ERROR_FILE_TOO_BIG: - os = "file is bigger than 4G"; - break; - default: - mapnik::util::to_string(os, error); - os = "unknown error (" + os + ")"; - break; - } - return os; -} +std::string MAPNIK_DECL webp_encoding_error(WebPEncodingError error); template inline int import_image(T2 const& im_in, WebPPicture& pic, bool alpha) diff --git a/include/mapnik/well_known_srs.hpp b/include/mapnik/well_known_srs.hpp index 863768ea3..fe5a1772c 100644 --- a/include/mapnik/well_known_srs.hpp +++ b/include/mapnik/well_known_srs.hpp @@ -39,8 +39,7 @@ MAPNIK_DISABLE_WARNING_POP namespace mapnik { -enum well_known_srs_enum : std::uint8_t { WGS_84, WEB_MERC, well_known_srs_enum_MAX }; - +enum class well_known_srs_enum : std::uint8_t { WGS_84, WEB_MERC, well_known_srs_enum_MAX }; DEFINE_ENUM(well_known_srs_e, well_known_srs_enum); constexpr double EARTH_RADIUS = 6378137.0; diff --git a/include/mapnik/wkt/wkt_grammar_x3_def.hpp b/include/mapnik/wkt/wkt_grammar_x3_def.hpp index 40302fb7f..3af4dcbd4 100644 --- a/include/mapnik/wkt/wkt_grammar_x3_def.hpp +++ b/include/mapnik/wkt/wkt_grammar_x3_def.hpp @@ -47,17 +47,16 @@ namespace mapnik { namespace grammar { namespace x3 = boost::spirit::x3; -namespace ascii = boost::spirit::x3::ascii; using x3::double_; using x3::lit; using x3::no_case; // functors -auto make_empty = [](auto const& ctx) { +const auto make_empty = [](auto const& ctx) { _val(ctx) = geometry::geometry_empty(); }; -auto add_ring = [](auto const& ctx) { +const auto add_ring = [](auto const& ctx) { auto& ring = reinterpret_cast&>(_attr(ctx)); _val(ctx).push_back(std::move(ring)); }; diff --git a/include/mapnik/xml_attribute_cast.hpp b/include/mapnik/xml_attribute_cast.hpp index a2b434ea5..a39938e75 100644 --- a/include/mapnik/xml_attribute_cast.hpp +++ b/include/mapnik/xml_attribute_cast.hpp @@ -161,17 +161,20 @@ struct do_xml_attribute_cast } }; -// specialization for mapnik::enumeration -template -struct do_xml_attribute_cast> +// specialization for mapnik::enumeration<...> +template (*F_LOOKUP)()> +struct do_xml_attribute_cast> { - static inline boost::optional> xml_attribute_cast_impl(xml_tree const& /*tree*/, - std::string const& source) + using Enum = mapnik::enumeration; + static inline boost::optional xml_attribute_cast_impl(xml_tree const& /*tree*/, std::string const& source) { - using result_type = typename boost::optional>; + using result_type = typename boost::optional; try { - mapnik::enumeration e; + Enum e; e.from_string(source); return result_type(e); } diff --git a/plugins/input/CMakeLists.txt b/plugins/input/CMakeLists.txt index 4bf03e016..8a1bcd5fd 100644 --- a/plugins/input/CMakeLists.txt +++ b/plugins/input/CMakeLists.txt @@ -1,5 +1,28 @@ set(_plugin_prefix "") set(_plugin_suffix ".input") +set(_plugin_library_output "${MAPNIK_OUTPUT_DIR}/plugins/input") +set(_plugin_fpic ON) +set(_plugin_linkage MODULE) +set(_plugin_visibility PRIVATE) +if(NOT BUILD_SHARED_PLUGINS) + set(_plugin_linkage INTERFACE) + set(_plugin_visibility INTERFACE) +endif() + +macro(add_plugin_target plugin_target output_name) + add_library(${plugin_target} ${_plugin_linkage}) + set_target_properties(${plugin_target} PROPERTIES + OUTPUT_NAME "${output_name}" + POSITION_INDEPENDENT_CODE ${_plugin_fpic} + PREFIX "${_plugin_prefix}" + SUFFIX "${_plugin_suffix}" + LIBRARY_OUTPUT_DIRECTORY "${_plugin_library_output}" + ) + mapnik_install_plugin(${plugin_target}) +endmacro() + + +add_subdirectory(base) # add a list with all build plugins so the copy dependencies command can wait for all build events set(m_build_plugins "") @@ -51,7 +74,7 @@ endif() # # Copy all plugin dlls, so that these are in the main output dir, since cmake copies those into ${MAPNIK_OUTPUT_DIR}/plugins/input, too. # -if(WIN32) +if(BUILD_SHARED_PLUGINS AND WIN32) list(LENGTH m_build_plugins m_number_plugins) if(m_number_plugins GREATER 0) string(CONFIGURE diff --git a/plugins/input/base/CMakeLists.txt b/plugins/input/base/CMakeLists.txt new file mode 100644 index 000000000..bf76706b8 --- /dev/null +++ b/plugins/input/base/CMakeLists.txt @@ -0,0 +1,12 @@ +add_library(datasource-base INTERFACE) +add_library(mapnik::datasource-base ALIAS datasource-base) + + +target_include_directories(datasource-base INTERFACE + $ + $ +) +target_link_libraries(datasource-base INTERFACE mapnik::core) + +mapnik_install(datasource-base) +install(DIRECTORY include/ DESTINATION "${MAPNIK_INCLUDE_DIR}") diff --git a/plugins/input/base/include/mapnik/datasource_plugin.hpp b/plugins/input/base/include/mapnik/datasource_plugin.hpp new file mode 100644 index 000000000..ee6f7a854 --- /dev/null +++ b/plugins/input/base/include/mapnik/datasource_plugin.hpp @@ -0,0 +1,54 @@ +#ifndef DATASOURCE_PLUGIN_HPP +#define DATASOURCE_PLUGIN_HPP +#include +#include +#include + +namespace mapnik { +class MAPNIK_DECL datasource_plugin +{ + public: + datasource_plugin() = default; + virtual ~datasource_plugin() = default; + virtual void after_load() const = 0; + virtual void before_unload() const = 0; + virtual const char* name() const = 0; + virtual datasource_ptr create(parameters const& params) const = 0; +}; +} // namespace mapnik + +#define DATASOURCE_PLUGIN_DEF(classname, pluginname) \ + class classname : public mapnik::datasource_plugin \ + { \ + public: \ + static constexpr const char* kName = #pluginname; \ + void after_load() const override; \ + void before_unload() const override; \ + const char* name() const override; \ + mapnik::datasource_ptr create(mapnik::parameters const& params) const override; \ + }; + +#define DATASOURCE_PLUGIN_IMPL(classname, pluginclassname) \ + const char* classname::name() const \ + { \ + return kName; \ + } \ + mapnik::datasource_ptr classname::create(mapnik::parameters const& params) const \ + { \ + return std::make_shared(params); \ + } + +#define DATASOURCE_PLUGIN_EMPTY_AFTER_LOAD(classname) \ + void classname::after_load() const {} +#define DATASOURCE_PLUGIN_EMPTY_BEFORE_UNLOAD(classname) \ + void classname::before_unload() const {} + +#ifndef MAPNIK_STATIC_PLUGINS +#define DATASOURCE_PLUGIN_EXPORT(classname) \ + extern "C" MAPNIK_EXP classname plugin; \ + classname plugin; +#else +#define DATASOURCE_PLUGIN_EXPORT(classname) // export classname +#endif + +#endif diff --git a/plugins/input/csv/CMakeLists.txt b/plugins/input/csv/CMakeLists.txt index 5fc60254c..bb2739dd1 100644 --- a/plugins/input/csv/CMakeLists.txt +++ b/plugins/input/csv/CMakeLists.txt @@ -1,21 +1,15 @@ -add_library(input-csv MODULE +add_plugin_target(input-csv "csv") + +target_sources(input-csv ${_plugin_visibility} csv_datasource.cpp csv_featureset.cpp csv_index_featureset.cpp csv_inline_featureset.cpp csv_utils.cpp ) -target_link_libraries(input-csv PRIVATE +target_link_libraries(input-csv ${_plugin_visibility} mapnik::mapnik mapnik::wkt mapnik::json + mapnik::datasource-base ) -set_target_properties(input-csv PROPERTIES - OUTPUT_NAME "csv" - PREFIX "${_plugin_prefix}" - SUFFIX "${_plugin_suffix}" - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/plugins/input" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) -mapnik_install_plugin(input-csv) diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index 1a0d36461..7068882db 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -65,7 +65,10 @@ MAPNIK_DISABLE_WARNING_POP using mapnik::datasource; using mapnik::parameters; -DATASOURCE_PLUGIN(csv_datasource) +DATASOURCE_PLUGIN_IMPL(csv_datasource_plugin, csv_datasource); +DATASOURCE_PLUGIN_EXPORT(csv_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_AFTER_LOAD(csv_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_BEFORE_UNLOAD(csv_datasource_plugin); csv_datasource::csv_datasource(parameters const& params) : datasource(params) diff --git a/plugins/input/csv/csv_datasource.hpp b/plugins/input/csv/csv_datasource.hpp index 8dcd5e6e5..9a710f25f 100644 --- a/plugins/input/csv/csv_datasource.hpp +++ b/plugins/input/csv/csv_datasource.hpp @@ -48,6 +48,8 @@ MAPNIK_DISABLE_WARNING_POP #include #include +#include + template struct csv_linear : boost::geometry::index::linear {}; @@ -79,6 +81,8 @@ struct options_type> } // namespace geometry } // namespace boost +DATASOURCE_PLUGIN_DEF(csv_datasource_plugin, csv); + class csv_datasource : public mapnik::datasource, private csv_utils::csv_file_parser { diff --git a/plugins/input/gdal/CMakeLists.txt b/plugins/input/gdal/CMakeLists.txt index cf6f272c5..440c545b3 100644 --- a/plugins/input/gdal/CMakeLists.txt +++ b/plugins/input/gdal/CMakeLists.txt @@ -1,20 +1,13 @@ find_package(GDAL REQUIRED) -add_library(input-gdal MODULE +add_plugin_target(input-gdal "gdal") +target_sources(input-gdal ${_plugin_visibility} gdal_datasource.cpp gdal_featureset.cpp ) -target_include_directories(input-gdal PRIVATE ${GDAL_INCLUDE_DIRS}) -target_link_libraries(input-gdal PRIVATE +target_include_directories(input-gdal ${_plugin_visibility} ${GDAL_INCLUDE_DIRS}) +target_link_libraries(input-gdal ${_plugin_visibility} mapnik::mapnik + mapnik::datasource-base ${GDAL_LIBRARIES} ) -set_target_properties(input-gdal PROPERTIES - OUTPUT_NAME "gdal" - PREFIX "${_plugin_prefix}" - SUFFIX "${_plugin_suffix}" - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/plugins/input" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) -mapnik_install_plugin(input-gdal) diff --git a/plugins/input/gdal/gdal_datasource.cpp b/plugins/input/gdal/gdal_datasource.cpp index 54b5c20ed..f86e17361 100644 --- a/plugins/input/gdal/gdal_datasource.cpp +++ b/plugins/input/gdal/gdal_datasource.cpp @@ -37,8 +37,6 @@ using mapnik::datasource; using mapnik::parameters; -DATASOURCE_PLUGIN(gdal_datasource) - using mapnik::box2d; using mapnik::coord2d; using mapnik::datasource_exception; @@ -46,12 +44,16 @@ using mapnik::featureset_ptr; using mapnik::layer_descriptor; using mapnik::query; -static std::once_flag once_flag; - -extern "C" MAPNIK_EXP void on_plugin_load() +DATASOURCE_PLUGIN_IMPL(gdal_datasource_plugin, gdal_datasource); +DATASOURCE_PLUGIN_EXPORT(gdal_datasource_plugin); +void gdal_datasource_plugin::after_load() const { - // initialize gdal formats - std::call_once(once_flag, []() { GDALAllRegister(); }); + GDALAllRegister(); +} + +void gdal_datasource_plugin::before_unload() const +{ + GDALDestroyDriverManager(); } gdal_datasource::gdal_datasource(parameters const& params) diff --git a/plugins/input/gdal/gdal_datasource.hpp b/plugins/input/gdal/gdal_datasource.hpp index 5ff2a72b0..2dad23023 100644 --- a/plugins/input/gdal/gdal_datasource.hpp +++ b/plugins/input/gdal/gdal_datasource.hpp @@ -31,7 +31,7 @@ #include #include #include - +#include // boost #include @@ -42,6 +42,8 @@ // gdal #include +DATASOURCE_PLUGIN_DEF(gdal_datasource_plugin, gdal); + class gdal_datasource : public mapnik::datasource { public: diff --git a/plugins/input/geobuf/CMakeLists.txt b/plugins/input/geobuf/CMakeLists.txt index feadf82d9..8bcf7b132 100644 --- a/plugins/input/geobuf/CMakeLists.txt +++ b/plugins/input/geobuf/CMakeLists.txt @@ -1,14 +1,10 @@ -add_library(input-geobuf MODULE +add_plugin_target(input-geobuf "geobuf") + +target_sources(input-geobuf ${_plugin_visibility} geobuf_datasource.cpp geobuf_featureset.cpp ) -target_link_libraries(input-geobuf PRIVATE mapnik::mapnik) -set_target_properties(input-geobuf PROPERTIES - OUTPUT_NAME "geobuf" - PREFIX "${_plugin_prefix}" - SUFFIX "${_plugin_suffix}" - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/plugins/input" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" +target_link_libraries(input-geobuf ${_plugin_visibility} + mapnik::mapnik + mapnik::datasource-base ) -mapnik_install_plugin(input-geobuf) diff --git a/plugins/input/geobuf/geobuf_datasource.cpp b/plugins/input/geobuf/geobuf_datasource.cpp index 974225153..48eafa299 100644 --- a/plugins/input/geobuf/geobuf_datasource.cpp +++ b/plugins/input/geobuf/geobuf_datasource.cpp @@ -48,7 +48,10 @@ using mapnik::datasource; using mapnik::parameters; -DATASOURCE_PLUGIN(geobuf_datasource) +DATASOURCE_PLUGIN_IMPL(geobuf_datasource_plugin, geobuf_datasource); +DATASOURCE_PLUGIN_EXPORT(geobuf_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_AFTER_LOAD(geobuf_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_BEFORE_UNLOAD(geobuf_datasource_plugin); struct attr_value_converter { diff --git a/plugins/input/geobuf/geobuf_datasource.hpp b/plugins/input/geobuf/geobuf_datasource.hpp index f6da2ebb4..48088ec9b 100644 --- a/plugins/input/geobuf/geobuf_datasource.hpp +++ b/plugins/input/geobuf/geobuf_datasource.hpp @@ -32,6 +32,7 @@ #include #include #include +#include // boost #include #include @@ -84,6 +85,7 @@ struct options_type> } // namespace geometry } // namespace boost +DATASOURCE_PLUGIN_DEF(geobuf_datasource_plugin, geobuf); class geobuf_datasource : public mapnik::datasource { public: diff --git a/plugins/input/geojson/CMakeLists.txt b/plugins/input/geojson/CMakeLists.txt index b973f3f68..d6919a405 100644 --- a/plugins/input/geojson/CMakeLists.txt +++ b/plugins/input/geojson/CMakeLists.txt @@ -1,19 +1,12 @@ -add_library(input-geojson MODULE +add_plugin_target(input-geojson "geojson") +target_sources(input-geojson ${_plugin_visibility} geojson_datasource.cpp geojson_featureset.cpp geojson_index_featureset.cpp geojson_memory_index_featureset.cpp ) -target_link_libraries(input-geojson PRIVATE +target_link_libraries(input-geojson ${_plugin_visibility} mapnik::mapnik mapnik::json + mapnik::datasource-base ) -set_target_properties(input-geojson PROPERTIES - OUTPUT_NAME "geojson" - PREFIX "${_plugin_prefix}" - SUFFIX "${_plugin_suffix}" - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/plugins/input" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) -mapnik_install_plugin(input-geojson) diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index b811e9d8d..f4ecf82ed 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -67,7 +67,10 @@ MAPNIK_DISABLE_WARNING_POP using mapnik::datasource; using mapnik::parameters; -DATASOURCE_PLUGIN(geojson_datasource) +DATASOURCE_PLUGIN_IMPL(geojson_datasource_plugin, geojson_datasource); +DATASOURCE_PLUGIN_EXPORT(geojson_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_AFTER_LOAD(geojson_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_BEFORE_UNLOAD(geojson_datasource_plugin); struct attr_value_converter { diff --git a/plugins/input/geojson/geojson_datasource.hpp b/plugins/input/geojson/geojson_datasource.hpp index 216c656a4..57584717e 100644 --- a/plugins/input/geojson/geojson_datasource.hpp +++ b/plugins/input/geojson/geojson_datasource.hpp @@ -32,6 +32,7 @@ #include #include #include +#include #include MAPNIK_DISABLE_WARNING_PUSH @@ -82,6 +83,8 @@ struct options_type> } // namespace geometry } // namespace boost +DATASOURCE_PLUGIN_DEF(geojson_datasource_plugin, geojson); + class geojson_datasource : public mapnik::datasource { public: diff --git a/plugins/input/ogr/CMakeLists.txt b/plugins/input/ogr/CMakeLists.txt index d030eb618..0034d4684 100644 --- a/plugins/input/ogr/CMakeLists.txt +++ b/plugins/input/ogr/CMakeLists.txt @@ -1,22 +1,15 @@ find_package(GDAL REQUIRED) -add_library(input-ogr MODULE +add_plugin_target(input-ogr "ogr") +target_sources(input-ogr ${_plugin_visibility} ogr_converter.cpp ogr_datasource.cpp ogr_featureset.cpp ogr_index_featureset.cpp ) -target_include_directories(input-ogr PRIVATE ${GDAL_INCLUDE_DIRS}) -target_link_libraries(input-ogr PRIVATE +target_include_directories(input-ogr ${_plugin_visibility} ${GDAL_INCLUDE_DIRS}) +target_link_libraries(input-ogr ${_plugin_visibility} mapnik::mapnik + mapnik::datasource-base ${GDAL_LIBRARIES} ) -set_target_properties(input-ogr PROPERTIES - OUTPUT_NAME "ogr" - PREFIX "${_plugin_prefix}" - SUFFIX "${_plugin_suffix}" - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/plugins/input" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) -mapnik_install_plugin(input-ogr) diff --git a/plugins/input/ogr/ogr_datasource.cpp b/plugins/input/ogr/ogr_datasource.cpp index 6bc00a23e..2e4cad22e 100644 --- a/plugins/input/ogr/ogr_datasource.cpp +++ b/plugins/input/ogr/ogr_datasource.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include MAPNIK_DISABLE_WARNING_PUSH @@ -49,8 +50,6 @@ MAPNIK_DISABLE_WARNING_POP using mapnik::datasource; using mapnik::parameters; -DATASOURCE_PLUGIN(ogr_datasource) - using mapnik::attribute_descriptor; using mapnik::box2d; using mapnik::coord2d; @@ -63,11 +62,21 @@ using mapnik::query; static std::once_flag once_flag; -extern "C" MAPNIK_EXP void on_plugin_load() +DATASOURCE_PLUGIN_IMPL(ogr_datasource_plugin, ogr_datasource); +DATASOURCE_PLUGIN_EXPORT(ogr_datasource_plugin); + +void ogr_datasource_plugin::after_load() const { // initialize ogr formats // NOTE: in GDAL >= 2.0 this is the same as GDALAllRegister() - std::call_once(once_flag, []() { OGRRegisterAll(); }); + OGRRegisterAll(); +} + +void ogr_datasource_plugin::before_unload() const +{ + // initialize ogr formats + // NOTE: in GDAL >= 2.0 this is the same as GDALDestroyDriverManager() + OGRCleanupAll(); } ogr_datasource::ogr_datasource(parameters const& params) diff --git a/plugins/input/ogr/ogr_datasource.hpp b/plugins/input/ogr/ogr_datasource.hpp index 26f74d221..bde5829b0 100644 --- a/plugins/input/ogr/ogr_datasource.hpp +++ b/plugins/input/ogr/ogr_datasource.hpp @@ -31,6 +31,7 @@ #include #include #include +#include // boost #include @@ -47,6 +48,8 @@ MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_POP #include "ogr_layer_ptr.hpp" +DATASOURCE_PLUGIN_DEF(ogr_datasource_plugin, ogr); + class ogr_datasource : public mapnik::datasource { public: diff --git a/plugins/input/pgraster/CMakeLists.txt b/plugins/input/pgraster/CMakeLists.txt index 387f168ca..21a58e733 100644 --- a/plugins/input/pgraster/CMakeLists.txt +++ b/plugins/input/pgraster/CMakeLists.txt @@ -1,20 +1,13 @@ -find_package(PostgreSQL REQUIRED) +mapnik_find_package(PostgreSQL REQUIRED) -add_library(input-pgraster MODULE +add_plugin_target(input-pgraster "pgraster") +target_sources(input-pgraster ${_plugin_visibility} pgraster_datasource.cpp pgraster_featureset.cpp pgraster_wkb_reader.cpp ) -target_link_libraries(input-pgraster PRIVATE +target_link_libraries(input-pgraster ${_plugin_visibility} mapnik::mapnik + mapnik::datasource-base PostgreSQL::PostgreSQL ) -set_target_properties(input-pgraster PROPERTIES - OUTPUT_NAME "pgraster" - PREFIX "${_plugin_prefix}" - SUFFIX "${_plugin_suffix}" - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/plugins/input" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) -mapnik_install_plugin(input-pgraster) diff --git a/plugins/input/pgraster/pgraster_datasource.cpp b/plugins/input/pgraster/pgraster_datasource.cpp index 4428cfc06..fdba3c335 100644 --- a/plugins/input/pgraster/pgraster_datasource.cpp +++ b/plugins/input/pgraster/pgraster_datasource.cpp @@ -51,7 +51,10 @@ MAPNIK_DISABLE_WARNING_POP #include #include -DATASOURCE_PLUGIN(pgraster_datasource) +DATASOURCE_PLUGIN_IMPL(pgraster_datasource_plugin, pgraster_datasource); +DATASOURCE_PLUGIN_EXPORT(pgraster_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_AFTER_LOAD(pgraster_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_BEFORE_UNLOAD(pgraster_datasource_plugin); const std::string pgraster_datasource::RASTER_COLUMNS = "raster_columns"; const std::string pgraster_datasource::RASTER_OVERVIEWS = "raster_overviews"; diff --git a/plugins/input/pgraster/pgraster_datasource.hpp b/plugins/input/pgraster/pgraster_datasource.hpp index 3d3a0b4c8..136bd50e0 100644 --- a/plugins/input/pgraster/pgraster_datasource.hpp +++ b/plugins/input/pgraster/pgraster_datasource.hpp @@ -37,6 +37,7 @@ #include #include #include +#include // boost #include @@ -73,6 +74,7 @@ struct pgraster_overview float scale; // max absolute scale between x and y }; +DATASOURCE_PLUGIN_DEF(pgraster_datasource_plugin, pgraster); class pgraster_datasource : public datasource { public: diff --git a/plugins/input/postgis/CMakeLists.txt b/plugins/input/postgis/CMakeLists.txt index 3fde486aa..e26e9b8c9 100644 --- a/plugins/input/postgis/CMakeLists.txt +++ b/plugins/input/postgis/CMakeLists.txt @@ -1,19 +1,12 @@ -find_package(PostgreSQL REQUIRED) +mapnik_find_package(PostgreSQL REQUIRED) -add_library(input-postgis MODULE +add_plugin_target(input-postgis "postgis") +target_sources(input-postgis ${_plugin_visibility} postgis_datasource.cpp postgis_featureset.cpp ) -target_link_libraries(input-postgis PRIVATE +target_link_libraries(input-postgis ${_plugin_visibility} mapnik::mapnik + mapnik::datasource-base PostgreSQL::PostgreSQL ) -set_target_properties(input-postgis PROPERTIES - OUTPUT_NAME "postgis" - PREFIX "${_plugin_prefix}" - SUFFIX "${_plugin_suffix}" - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/plugins/input" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) -mapnik_install_plugin(input-postgis) diff --git a/plugins/input/postgis/postgis_datasource.cpp b/plugins/input/postgis/postgis_datasource.cpp index 9b236e149..88a03a680 100644 --- a/plugins/input/postgis/postgis_datasource.cpp +++ b/plugins/input/postgis/postgis_datasource.cpp @@ -48,7 +48,10 @@ MAPNIK_DISABLE_WARNING_POP #include #include -DATASOURCE_PLUGIN(postgis_datasource) +DATASOURCE_PLUGIN_IMPL(postgis_datasource_plugin, postgis_datasource); +DATASOURCE_PLUGIN_EXPORT(postgis_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_AFTER_LOAD(postgis_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_BEFORE_UNLOAD(postgis_datasource_plugin); const std::string postgis_datasource::GEOMETRY_COLUMNS = "geometry_columns"; const std::string postgis_datasource::SPATIAL_REF_SYS = "spatial_ref_system"; diff --git a/plugins/input/postgis/postgis_datasource.hpp b/plugins/input/postgis/postgis_datasource.hpp index ce02454ee..377da93b3 100644 --- a/plugins/input/postgis/postgis_datasource.hpp +++ b/plugins/input/postgis/postgis_datasource.hpp @@ -34,6 +34,7 @@ #include #include #include +#include // boost #include @@ -62,6 +63,7 @@ using mapnik::transcoder; using CnxPool_ptr = std::shared_ptr; +DATASOURCE_PLUGIN_DEF(postgis_datasource_plugin, postgis); class postgis_datasource : public datasource { public: diff --git a/plugins/input/raster/CMakeLists.txt b/plugins/input/raster/CMakeLists.txt index 265d600b0..ca3826a70 100644 --- a/plugins/input/raster/CMakeLists.txt +++ b/plugins/input/raster/CMakeLists.txt @@ -1,15 +1,10 @@ -add_library(input-raster MODULE +add_plugin_target(input-raster "raster") +target_sources(input-raster ${_plugin_visibility} raster_datasource.cpp raster_featureset.cpp raster_info.cpp ) -target_link_libraries(input-raster PRIVATE mapnik::mapnik) -set_target_properties(input-raster PROPERTIES - OUTPUT_NAME "raster" - PREFIX "${_plugin_prefix}" - SUFFIX "${_plugin_suffix}" - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/plugins/input" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" +target_link_libraries(input-raster ${_plugin_visibility} + mapnik::mapnik + mapnik::datasource-base ) -mapnik_install_plugin(input-raster) diff --git a/plugins/input/raster/raster_datasource.cpp b/plugins/input/raster/raster_datasource.cpp index 3c136cb88..5e04ebf4f 100644 --- a/plugins/input/raster/raster_datasource.cpp +++ b/plugins/input/raster/raster_datasource.cpp @@ -43,7 +43,10 @@ using mapnik::layer_descriptor; using mapnik::parameters; using mapnik::query; -DATASOURCE_PLUGIN(raster_datasource) +DATASOURCE_PLUGIN_IMPL(raster_datasource_plugin, raster_datasource); +DATASOURCE_PLUGIN_EXPORT(raster_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_AFTER_LOAD(raster_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_BEFORE_UNLOAD(raster_datasource_plugin); raster_datasource::raster_datasource(parameters const& params) : datasource(params) diff --git a/plugins/input/raster/raster_datasource.hpp b/plugins/input/raster/raster_datasource.hpp index 6f834a4b4..f1b78dfe9 100644 --- a/plugins/input/raster/raster_datasource.hpp +++ b/plugins/input/raster/raster_datasource.hpp @@ -31,6 +31,7 @@ #include #include #include +#include // boost #include @@ -40,6 +41,8 @@ #include #include +DATASOURCE_PLUGIN_DEF(raster_datasource_plugin, raster); + class raster_datasource : public mapnik::datasource { public: diff --git a/plugins/input/shape/CMakeLists.txt b/plugins/input/shape/CMakeLists.txt index 8e9c0832f..930d85f11 100644 --- a/plugins/input/shape/CMakeLists.txt +++ b/plugins/input/shape/CMakeLists.txt @@ -1,4 +1,5 @@ -add_library(input-shape MODULE +add_plugin_target(input-shape "shape") +target_sources(input-shape ${_plugin_visibility} dbfile.cpp dbf_test.cpp shape_datasource.cpp @@ -6,13 +7,7 @@ add_library(input-shape MODULE shape_index_featureset.cpp shape_io.cpp shape_utils.cpp ) -target_link_libraries(input-shape PRIVATE mapnik::mapnik) -set_target_properties(input-shape PROPERTIES - OUTPUT_NAME "shape" - PREFIX "${_plugin_prefix}" - SUFFIX "${_plugin_suffix}" - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/plugins/input" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" +target_link_libraries(input-shape ${_plugin_visibility} + mapnik::mapnik + mapnik::datasource-base ) -mapnik_install_plugin(input-shape) diff --git a/plugins/input/shape/shape_datasource.cpp b/plugins/input/shape/shape_datasource.cpp index df96d6684..38f3dbf08 100644 --- a/plugins/input/shape/shape_datasource.cpp +++ b/plugins/input/shape/shape_datasource.cpp @@ -47,7 +47,10 @@ MAPNIK_DISABLE_WARNING_POP #include #include -DATASOURCE_PLUGIN(shape_datasource) +DATASOURCE_PLUGIN_IMPL(shape_datasource_plugin, shape_datasource); +DATASOURCE_PLUGIN_EXPORT(shape_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_AFTER_LOAD(shape_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_BEFORE_UNLOAD(shape_datasource_plugin); using mapnik::attribute_descriptor; using mapnik::Boolean; diff --git a/plugins/input/shape/shape_datasource.hpp b/plugins/input/shape/shape_datasource.hpp index 7329b9345..bc98b9c3b 100644 --- a/plugins/input/shape/shape_datasource.hpp +++ b/plugins/input/shape/shape_datasource.hpp @@ -32,6 +32,7 @@ #include #include #include +#include // boost #include @@ -50,6 +51,8 @@ using mapnik::layer_descriptor; using mapnik::parameters; using mapnik::query; +DATASOURCE_PLUGIN_DEF(shape_datasource_plugin, shape); + class shape_datasource : public datasource { public: diff --git a/plugins/input/sqlite/CMakeLists.txt b/plugins/input/sqlite/CMakeLists.txt index 26e452de3..5d93c3756 100644 --- a/plugins/input/sqlite/CMakeLists.txt +++ b/plugins/input/sqlite/CMakeLists.txt @@ -1,20 +1,12 @@ find_package(SQLite3 REQUIRED) -add_library(input-sqlite MODULE +add_plugin_target(input-sqlite "sqlite") +target_sources(input-sqlite ${_plugin_visibility} sqlite_datasource.cpp sqlite_featureset.cpp ) -add_library(mapnik::plugin::input::sqlite ALIAS input-sqlite) -target_link_libraries(input-sqlite PRIVATE +target_link_libraries(input-sqlite ${_plugin_visibility} mapnik::mapnik + mapnik::datasource-base SQLite::SQLite3 ) -set_target_properties(input-sqlite PROPERTIES - OUTPUT_NAME "sqlite" - PREFIX "${_plugin_prefix}" - SUFFIX "${_plugin_suffix}" - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/plugins/input" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) -mapnik_install_plugin(input-sqlite) diff --git a/plugins/input/sqlite/sqlite_datasource.cpp b/plugins/input/sqlite/sqlite_datasource.cpp index c3522742d..71a55a2eb 100644 --- a/plugins/input/sqlite/sqlite_datasource.cpp +++ b/plugins/input/sqlite/sqlite_datasource.cpp @@ -50,7 +50,10 @@ using mapnik::layer_descriptor; using mapnik::parameters; using mapnik::query; -DATASOURCE_PLUGIN(sqlite_datasource) +DATASOURCE_PLUGIN_IMPL(sqlite_datasource_plugin, sqlite_datasource); +DATASOURCE_PLUGIN_EXPORT(sqlite_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_AFTER_LOAD(sqlite_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_BEFORE_UNLOAD(sqlite_datasource_plugin); sqlite_datasource::sqlite_datasource(parameters const& params) : datasource(params) diff --git a/plugins/input/sqlite/sqlite_datasource.hpp b/plugins/input/sqlite/sqlite_datasource.hpp index 40a989026..49d588f23 100644 --- a/plugins/input/sqlite/sqlite_datasource.hpp +++ b/plugins/input/sqlite/sqlite_datasource.hpp @@ -33,6 +33,7 @@ #include #include #include +#include // boost #include @@ -45,6 +46,8 @@ // sqlite #include "sqlite_connection.hpp" +DATASOURCE_PLUGIN_DEF(sqlite_datasource_plugin, sqlite); + class sqlite_datasource : public mapnik::datasource { public: diff --git a/plugins/input/topojson/CMakeLists.txt b/plugins/input/topojson/CMakeLists.txt index 865adf685..03f885e44 100644 --- a/plugins/input/topojson/CMakeLists.txt +++ b/plugins/input/topojson/CMakeLists.txt @@ -1,18 +1,10 @@ -add_library(input-topojson MODULE +add_plugin_target(input-topojson "topojson") +target_sources(input-topojson ${_plugin_visibility} topojson_datasource.cpp topojson_featureset.cpp ) -add_library(mapnik::plugin::input::topojson ALIAS input-topojson) -target_link_libraries(input-topojson PRIVATE +target_link_libraries(input-topojson ${_plugin_visibility} mapnik::mapnik mapnik::json + mapnik::datasource-base ) -set_target_properties(input-topojson PROPERTIES - OUTPUT_NAME "topojson" - PREFIX "${_plugin_prefix}" - SUFFIX "${_plugin_suffix}" - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/plugins/input" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) -mapnik_install_plugin(input-topojson) diff --git a/plugins/input/topojson/topojson_datasource.cpp b/plugins/input/topojson/topojson_datasource.cpp index b704c4eee..2981ed65d 100644 --- a/plugins/input/topojson/topojson_datasource.cpp +++ b/plugins/input/topojson/topojson_datasource.cpp @@ -42,7 +42,10 @@ using mapnik::datasource; using mapnik::parameters; -DATASOURCE_PLUGIN(topojson_datasource) +DATASOURCE_PLUGIN_IMPL(topojson_datasource_plugin, topojson_datasource); +DATASOURCE_PLUGIN_EXPORT(topojson_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_AFTER_LOAD(topojson_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_BEFORE_UNLOAD(topojson_datasource_plugin); struct attr_value_converter { diff --git a/plugins/input/topojson/topojson_datasource.hpp b/plugins/input/topojson/topojson_datasource.hpp index f1f082961..88aff1c0f 100644 --- a/plugins/input/topojson/topojson_datasource.hpp +++ b/plugins/input/topojson/topojson_datasource.hpp @@ -33,6 +33,7 @@ #include #include #include +#include #include MAPNIK_DISABLE_WARNING_PUSH @@ -52,6 +53,8 @@ MAPNIK_DISABLE_WARNING_POP #include #include +DATASOURCE_PLUGIN_DEF(topojson_datasource_plugin, topojson); + class topojson_datasource : public mapnik::datasource { public: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index beb303d4d..65e649228 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,27 +1,55 @@ add_subdirectory(json) add_subdirectory(wkt) -add_library(mapnik "") -add_library(mapnik::mapnik ALIAS mapnik) - if(BUILD_SHARED_LIBS) + # private as this should only be visibile when building, to dllexport/dllimport correctly target_compile_definitions(mapnik PRIVATE MAPNIK_EXPORTS) endif() -target_link_libraries(mapnik PUBLIC mapnik::core) -target_link_libraries(mapnik PRIVATE mapnik::agg) +target_link_libraries(mapnik PUBLIC mapnik::core mapnik::datasource-base) +target_link_libraries(mapnik PRIVATE + mapnik::agg + # expr: if(BUILD_SHARED_PLUGINS == OFF && is build) then add link target + $<$>,$>:input-csv> + $<$>,$>:input-gdal> + $<$>,$>:input-geobuf> + $<$>,$>:input-geojson> + $<$>,$>:input-ogr> + $<$>,$>:input-pgraster> + $<$>,$>:input-postgis> + $<$>,$>:input-raster> + $<$>,$>:input-shape> + $<$>,$>:input-sqlite> + $<$>,$>:input-topojson> +) +target_compile_definitions(mapnik PRIVATE + # expr: if(BUILD_SHARED_PLUGINS == OFF && is build) then add build definition + $<$>,$>:MAPNIK_STATIC_PLUGIN_CSV> + $<$>,$>:MAPNIK_STATIC_PLUGIN_GDAL> + $<$>,$>:MAPNIK_STATIC_PLUGIN_GEOBUF> + $<$>,$>:MAPNIK_STATIC_PLUGIN_GEOJSON> + $<$>,$>:MAPNIK_STATIC_PLUGIN_OGR> + $<$>,$>:MAPNIK_STATIC_PLUGIN_PGRASTER> + $<$>,$>:MAPNIK_STATIC_PLUGIN_POSTGIS> + $<$>,$>:MAPNIK_STATIC_PLUGIN_RASTER> + $<$>,$>:MAPNIK_STATIC_PLUGIN_SHAPE> + $<$>,$>:MAPNIK_STATIC_PLUGIN_SQLITE> + $<$>,$>:MAPNIK_STATIC_PLUGIN_TOPOJSON> + +) + +if(NOT BUILD_SHARED_PLUGINS) + target_include_directories(mapnik PRIVATE "${PROJECT_SOURCE_DIR}/plugins") +endif() set_target_properties(mapnik PROPERTIES - DEBUG_POSTFIX "${MAPNIK_DEBUG_POSTFIX}" + POSITION_INDEPENDENT_CODE ON OUTPUT_NAME "mapnik" PREFIX "lib" IMPORT_PREFIX "lib" # for the archive on dll platforms VERSION ${MAPNIK_VERSION} # see https://github.com/mapnik/mapnik/pull/4248#issuecomment-925596509 => ABI compability only with the full version SOVERSION ${MAPNIK_VERSION} - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" ) if(MSVC) @@ -74,6 +102,7 @@ target_sources(mapnik PRIVATE layer.cpp load_map.cpp map.cpp + mapnik.cpp mapped_memory_cache.cpp marker_cache.cpp marker_helpers.cpp @@ -258,7 +287,10 @@ if(USE_TIFF) endif() if(USE_WEBP) - target_sources(mapnik PRIVATE webp_reader.cpp) + target_sources(mapnik PRIVATE + webp_reader.cpp + webp_io.cpp + ) endif() if(USE_GRID_RENDERER) diff --git a/src/agg/agg_renderer.cpp b/src/agg/agg_renderer.cpp index 1175487d9..1d171713f 100644 --- a/src/agg/agg_renderer.cpp +++ b/src/agg/agg_renderer.cpp @@ -51,7 +51,6 @@ MAPNIK_DISABLE_WARNING_PUSH #include "agg_color_rgba.h" #include "agg_scanline_u.h" #include "agg_image_filters.h" -#include "agg_trans_bilinear.h" #include "agg_span_allocator.h" #include "agg_image_accessors.h" #include "agg_span_image_filter_rgba.h" @@ -74,8 +73,8 @@ agg_renderer::agg_renderer(Map const& m, T0& pixmap, double scale_factor , buffers_() , internal_buffers_(m.width(), m.height()) , inflated_buffer_() - , ras_ptr(new rasterizer) - , gamma_method_(GAMMA_POWER) + , ras_ptr(std::make_unique()) + , gamma_method_(gamma_method_enum::GAMMA_POWER) , gamma_(1.0) , common_(m, attributes(), offset_x, offset_y, m.width(), m.height(), scale_factor) { @@ -94,8 +93,8 @@ agg_renderer::agg_renderer(Map const& m, , buffers_() , internal_buffers_(req.width(), req.height()) , inflated_buffer_() - , ras_ptr(new rasterizer) - , gamma_method_(GAMMA_POWER) + , ras_ptr(std::make_unique()) + , gamma_method_(gamma_method_enum::GAMMA_POWER) , gamma_(1.0) , common_(m, req, vars, offset_x, offset_y, req.width(), req.height(), scale_factor) { @@ -113,8 +112,8 @@ agg_renderer::agg_renderer(Map const& m, , buffers_() , internal_buffers_(m.width(), m.height()) , inflated_buffer_() - , ras_ptr(new rasterizer) - , gamma_method_(GAMMA_POWER) + , ras_ptr(std::make_unique()) + , gamma_method_(gamma_method_enum::GAMMA_POWER) , gamma_(1.0) , common_(m, attributes(), offset_x, offset_y, m.width(), m.height(), scale_factor, detector) { @@ -405,10 +404,10 @@ struct agg_render_marker_visitor using renderer_type = agg::renderer_scanline_aa_solid; ras_ptr_->reset(); - if (gamma_method_ != GAMMA_POWER || gamma_ != 1.0) + if (gamma_method_ != gamma_method_enum::GAMMA_POWER || gamma_ != 1.0) { ras_ptr_->gamma(agg::gamma_power()); - gamma_method_ = GAMMA_POWER; + gamma_method_ = gamma_method_enum::GAMMA_POWER; gamma_ = 1.0; } agg::scanline_u8 sl; @@ -451,10 +450,10 @@ struct agg_render_marker_visitor using renderer_base = agg::renderer_base; ras_ptr_->reset(); - if (gamma_method_ != GAMMA_POWER || gamma_ != 1.0) + if (gamma_method_ != gamma_method_enum::GAMMA_POWER || gamma_ != 1.0) { ras_ptr_->gamma(agg::gamma_power()); - gamma_method_ = GAMMA_POWER; + gamma_method_ = gamma_method_enum::GAMMA_POWER; gamma_ = 1.0; } agg::scanline_u8 sl; diff --git a/src/agg/process_debug_symbolizer.cpp b/src/agg/process_debug_symbolizer.cpp index cbe761ebd..b00d29944 100644 --- a/src/agg/process_debug_symbolizer.cpp +++ b/src/agg/process_debug_symbolizer.cpp @@ -221,30 +221,34 @@ void agg_renderer::process(debug_symbolizer const& sym, proj_transform const& prj_trans) { debug_symbolizer_mode_enum mode = - get(sym, keys::mode, feature, common_.vars_, DEBUG_SYM_MODE_COLLISION); + get(sym, + keys::mode, + feature, + common_.vars_, + debug_symbolizer_mode_enum::DEBUG_SYM_MODE_COLLISION); ras_ptr->reset(); - if (gamma_method_ != GAMMA_POWER || gamma_ != 1.0) + if (gamma_method_ != gamma_method_enum::GAMMA_POWER || gamma_ != 1.0) { ras_ptr->gamma(agg::gamma_power()); - gamma_method_ = GAMMA_POWER; + gamma_method_ = gamma_method_enum::GAMMA_POWER; gamma_ = 1.0; } - if (mode == DEBUG_SYM_MODE_RINGS) + if (mode == debug_symbolizer_mode_enum::DEBUG_SYM_MODE_RINGS) { RingRenderer renderer(*ras_ptr, buffers_.top().get(), common_.t_, prj_trans); render_ring_visitor apply(renderer); mapnik::util::apply_visitor(apply, feature.get_geometry()); } - else if (mode == DEBUG_SYM_MODE_COLLISION) + else if (mode == debug_symbolizer_mode_enum::DEBUG_SYM_MODE_COLLISION) { for (auto const& n : *common_.detector_) { draw_rect(buffers_.top().get(), n.get().box); } } - else if (mode == DEBUG_SYM_MODE_VERTEX) + else if (mode == debug_symbolizer_mode_enum::DEBUG_SYM_MODE_VERTEX) { using apply_vertex_mode = apply_vertex_mode; apply_vertex_mode apply(buffers_.top().get(), common_.t_, prj_trans); diff --git a/src/agg/process_dot_symbolizer.cpp b/src/agg/process_dot_symbolizer.cpp index 97a328a9d..8c424e210 100644 --- a/src/agg/process_dot_symbolizer.cpp +++ b/src/agg/process_dot_symbolizer.cpp @@ -102,8 +102,8 @@ void agg_renderer::process(dot_symbolizer const& sym, { double width = 0.0; double height = 0.0; - bool has_width = has_key(sym, keys::width); - bool has_height = has_key(sym, keys::height); + const bool has_width = has_key(sym, keys::width); + const bool has_height = has_key(sym, keys::height); if (has_width && has_height) { width = get(sym, keys::width, feature, common_.vars_, 0.0); @@ -117,15 +117,15 @@ void agg_renderer::process(dot_symbolizer const& sym, { width = height = get(sym, keys::height, feature, common_.vars_, 0.0); } - double rx = width / 2.0 * common_.scale_factor_; - double ry = height / 2.0 * common_.scale_factor_; - double opacity = get(sym, keys::opacity, feature, common_.vars_, 1.0); - color const& fill = get(sym, keys::fill, feature, common_.vars_, mapnik::color(128, 128, 128)); + const double rx = width / 2.0 * common_.scale_factor_; + const double ry = height / 2.0 * common_.scale_factor_; + const double opacity = get(sym, keys::opacity, feature, common_.vars_, 1.0); + const color& fill = get(sym, keys::fill, feature, common_.vars_, mapnik::color(128, 128, 128)); ras_ptr->reset(); - if (gamma_method_ != GAMMA_POWER || gamma_ != 1.0) + if (gamma_method_ != gamma_method_enum::GAMMA_POWER || gamma_ != 1.0) { ras_ptr->gamma(agg::gamma_power()); - gamma_method_ = GAMMA_POWER; + gamma_method_ = gamma_method_enum::GAMMA_POWER; gamma_ = 1.0; } buffer_type& current_buffer = buffers_.top().get(); diff --git a/src/agg/process_group_symbolizer.cpp b/src/agg/process_group_symbolizer.cpp index 6866962f2..5c936f63d 100644 --- a/src/agg/process_group_symbolizer.cpp +++ b/src/agg/process_group_symbolizer.cpp @@ -68,7 +68,12 @@ struct thunk_renderer : render_thunk_list_dispatch , ras_ptr_(ras_ptr) , buf_(buf) , common_(common) - , tex_(buf, HALO_RASTERIZER_FULL, src_over, src_over, common.scale_factor_, common.font_manager_.get_stroker()) + , tex_(buf, + halo_rasterizer_enum::HALO_RASTERIZER_FULL, + src_over, + src_over, + common.scale_factor_, + common.font_manager_.get_stroker()) {} virtual void operator()(vector_marker_render_thunk const& thunk) diff --git a/src/agg/process_line_pattern_symbolizer.cpp b/src/agg/process_line_pattern_symbolizer.cpp index a21217460..90dfe43fa 100644 --- a/src/agg/process_line_pattern_symbolizer.cpp +++ b/src/agg/process_line_pattern_symbolizer.cpp @@ -45,15 +45,9 @@ MAPNIK_DISABLE_WARNING_PUSH #include "agg_pixfmt_rgba.h" #include "agg_color_rgba.h" #include "agg_rendering_buffer.h" -#include "agg_rasterizer_outline.h" #include "agg_rasterizer_outline_aa.h" -#include "agg_scanline_u.h" -#include "agg_renderer_scanline.h" #include "agg_pattern_filters_rgba.h" -#include "agg_span_allocator.h" -#include "agg_span_pattern_rgba.h" #include "agg_renderer_outline_image.h" -#include "agg_image_accessors.h" MAPNIK_DISABLE_WARNING_POP namespace mapnik { @@ -216,17 +210,17 @@ struct agg_renderer_process_visitor_l line_pattern_enum pattern = get(sym_, feature_, common_.vars_); switch (pattern) { - case LINE_PATTERN_WARP: { + case line_pattern_enum::LINE_PATTERN_WARP: { warp_pattern pattern(pattern_image, common_, sym_, feature_, prj_trans_); render(pattern); break; } - case LINE_PATTERN_REPEAT: { + case line_pattern_enum::LINE_PATTERN_REPEAT: { repeat_pattern pattern(pattern_image, common_, sym_, feature_, prj_trans_); render(pattern); break; } - case line_pattern_enum_MAX: + case line_pattern_enum::line_pattern_enum_MAX: default: MAPNIK_LOG_ERROR(process_line_pattern_symbolizer) << "Incorrect line-pattern value."; } @@ -265,10 +259,10 @@ void agg_renderer::process(line_pattern_symbolizer const& sym, if (filename.empty()) return; ras_ptr->reset(); - if (gamma_method_ != GAMMA_POWER || gamma_ != 1.0) + if (gamma_method_ != gamma_method_enum::GAMMA_POWER || gamma_ != 1.0) { ras_ptr->gamma(agg::gamma_power()); - gamma_method_ = GAMMA_POWER; + gamma_method_ = gamma_method_enum::GAMMA_POWER; gamma_ = 1.0; } diff --git a/src/agg/process_line_symbolizer.cpp b/src/agg/process_line_symbolizer.cpp index cb48d3297..a6c4adb90 100644 --- a/src/agg/process_line_symbolizer.cpp +++ b/src/agg/process_line_symbolizer.cpp @@ -43,9 +43,6 @@ MAPNIK_DISABLE_WARNING_PUSH #include "agg_rasterizer_scanline_aa.h" #include "agg_scanline_u.h" #include "agg_renderer_scanline.h" -#include "agg_scanline_p.h" -#include "agg_conv_stroke.h" -#include "agg_conv_dash.h" #include "agg_renderer_outline_aa.h" #include "agg_rasterizer_outline_aa.h" MAPNIK_DISABLE_WARNING_POP @@ -59,30 +56,29 @@ namespace mapnik { template void set_join_caps_aa(Symbolizer const& sym, Rasterizer& ras, Feature& feature, attributes const& vars) { - line_join_enum join = get(sym, feature, vars); + const line_join_enum join = get(sym, feature, vars); switch (join) { - case MITER_JOIN: + case line_join_enum::MITER_JOIN: ras.line_join(agg::outline_miter_accurate_join); break; - case MITER_REVERT_JOIN: + case line_join_enum::MITER_REVERT_JOIN: ras.line_join(agg::outline_no_join); break; - case ROUND_JOIN: + case line_join_enum::ROUND_JOIN: ras.line_join(agg::outline_round_join); break; default: ras.line_join(agg::outline_no_join); } - line_cap_enum cap = get(sym, feature, vars); - + const line_cap_enum cap = get(sym, feature, vars); switch (cap) { - case BUTT_CAP: + case line_cap_enum::BUTT_CAP: ras.round_cap(false); break; - case SQUARE_CAP: + case line_cap_enum::SQUARE_CAP: ras.round_cap(false); break; default: @@ -97,10 +93,10 @@ void agg_renderer::process(line_symbolizer const& sym, { color const& col = get(sym, feature, common_.vars_); - unsigned r = col.red(); - unsigned g = col.green(); - unsigned b = col.blue(); - unsigned a = col.alpha(); + const unsigned r = col.red(); + const unsigned g = col.green(); + const unsigned b = col.blue(); + const unsigned a = col.alpha(); double gamma = get(sym, feature, common_.vars_); gamma_method_enum gamma_method = get(sym, feature, common_.vars_); @@ -136,13 +132,14 @@ void agg_renderer::process(line_symbolizer const& sym, box2d clip_box = clipping_extent(common_); - value_bool clip = get(sym, feature, common_.vars_); - value_double width = get(sym, feature, common_.vars_); - value_double opacity = get(sym, feature, common_.vars_); - value_double offset = get(sym, feature, common_.vars_); - value_double simplify_tolerance = get(sym, feature, common_.vars_); - value_double smooth = get(sym, feature, common_.vars_); - line_rasterizer_enum rasterizer_e = get(sym, feature, common_.vars_); + const value_bool clip = get(sym, feature, common_.vars_); + const value_double width = get(sym, feature, common_.vars_); + const value_double opacity = get(sym, feature, common_.vars_); + const value_double offset = get(sym, feature, common_.vars_); + const value_double simplify_tolerance = get(sym, feature, common_.vars_); + const value_double smooth = get(sym, feature, common_.vars_); + const line_rasterizer_enum rasterizer_e = + get(sym, feature, common_.vars_); if (clip) { double pad_per_pixel = static_cast(common_.query_extent_.width() / common_.width_); @@ -153,7 +150,7 @@ void agg_renderer::process(line_symbolizer const& sym, clip_box.pad(padding); } - if (rasterizer_e == RASTERIZER_FAST) + if (rasterizer_e == line_rasterizer_enum::RASTERIZER_FAST) { using renderer_type = agg::renderer_outline_aa; using rasterizer_type = agg::rasterizer_outline_aa; diff --git a/src/agg/process_polygon_symbolizer.cpp b/src/agg/process_polygon_symbolizer.cpp index 9711159a7..63c146acc 100644 --- a/src/agg/process_polygon_symbolizer.cpp +++ b/src/agg/process_polygon_symbolizer.cpp @@ -55,9 +55,9 @@ void agg_renderer::process(polygon_symbolizer const& sym, vertex_converter; ras_ptr->reset(); - double gamma = get(sym, keys::gamma, feature, common_.vars_, 1.0); + const double gamma = get(sym, keys::gamma, feature, common_.vars_, 1.0); gamma_method_enum gamma_method = - get(sym, keys::gamma_method, feature, common_.vars_, GAMMA_POWER); + get(sym, keys::gamma_method, feature, common_.vars_, gamma_method_enum::GAMMA_POWER); if (gamma != gamma_ || gamma_method != gamma_method_) { set_gamma_method(ras_ptr, gamma, gamma_method); diff --git a/src/agg/process_shield_symbolizer.cpp b/src/agg/process_shield_symbolizer.cpp index a88cae52f..222f577a9 100644 --- a/src/agg/process_shield_symbolizer.cpp +++ b/src/agg/process_shield_symbolizer.cpp @@ -37,28 +37,32 @@ void agg_renderer::process(shield_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans) { - box2d clip_box = clipping_extent(common_); + const box2d clip_box = clipping_extent(common_); agg::trans_affine tr; - auto transform = get_optional(sym, keys::geometry_transform); + const auto transform = get_optional(sym, keys::geometry_transform); if (transform) evaluate_transform(tr, feature, common_.vars_, *transform, common_.scale_factor_); - text_symbolizer_helper helper(sym, - feature, - common_.vars_, - prj_trans, - common_.width_, - common_.height_, - common_.scale_factor_, - common_.t_, - common_.font_manager_, - *common_.detector_, - clip_box, - tr); + const text_symbolizer_helper helper(sym, + feature, + common_.vars_, + prj_trans, + common_.width_, + common_.height_, + common_.scale_factor_, + common_.t_, + common_.font_manager_, + *common_.detector_, + clip_box, + tr); - halo_rasterizer_enum halo_rasterizer = - get(sym, keys::halo_rasterizer, feature, common_.vars_, HALO_RASTERIZER_FULL); - composite_mode_e comp_op = get(sym, keys::comp_op, feature, common_.vars_, src_over); - composite_mode_e halo_comp_op = get(sym, keys::halo_comp_op, feature, common_.vars_, src_over); + const halo_rasterizer_enum halo_rasterizer = get(sym, + keys::halo_rasterizer, + feature, + common_.vars_, + halo_rasterizer_enum::HALO_RASTERIZER_FULL); + const composite_mode_e comp_op = get(sym, keys::comp_op, feature, common_.vars_, src_over); + const composite_mode_e halo_comp_op = + get(sym, keys::halo_comp_op, feature, common_.vars_, src_over); agg_text_renderer ren(buffers_.top().get(), halo_rasterizer, comp_op, @@ -66,12 +70,12 @@ void agg_renderer::process(shield_symbolizer const& sym, common_.scale_factor_, common_.font_manager_.get_stroker()); - double opacity = get(sym, keys::opacity, feature, common_.vars_, 1.0); + const double opacity = get(sym, keys::opacity, feature, common_.vars_, 1.0); placements_list const& placements = helper.get(); for (auto const& glyphs : placements) { - marker_info_ptr mark = glyphs->get_marker(); + const marker_info_ptr mark = glyphs->get_marker(); if (mark) { render_marker(glyphs->marker_pos(), *mark->marker_, mark->transform_, opacity, comp_op); diff --git a/src/agg/process_text_symbolizer.cpp b/src/agg/process_text_symbolizer.cpp index 7a8dbec02..54bb45660 100644 --- a/src/agg/process_text_symbolizer.cpp +++ b/src/agg/process_text_symbolizer.cpp @@ -37,28 +37,32 @@ void agg_renderer::process(text_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans) { - box2d clip_box = clipping_extent(common_); + const box2d clip_box = clipping_extent(common_); agg::trans_affine tr; - auto transform = get_optional(sym, keys::geometry_transform); + const auto transform = get_optional(sym, keys::geometry_transform); if (transform) evaluate_transform(tr, feature, common_.vars_, *transform, common_.scale_factor_); - text_symbolizer_helper helper(sym, - feature, - common_.vars_, - prj_trans, - common_.width_, - common_.height_, - common_.scale_factor_, - common_.t_, - common_.font_manager_, - *common_.detector_, - clip_box, - tr); + const text_symbolizer_helper helper(sym, + feature, + common_.vars_, + prj_trans, + common_.width_, + common_.height_, + common_.scale_factor_, + common_.t_, + common_.font_manager_, + *common_.detector_, + clip_box, + tr); - halo_rasterizer_enum halo_rasterizer = - get(sym, keys::halo_rasterizer, feature, common_.vars_, HALO_RASTERIZER_FULL); - composite_mode_e comp_op = get(sym, keys::comp_op, feature, common_.vars_, src_over); - composite_mode_e halo_comp_op = get(sym, keys::halo_comp_op, feature, common_.vars_, src_over); + const halo_rasterizer_enum halo_rasterizer = get(sym, + keys::halo_rasterizer, + feature, + common_.vars_, + halo_rasterizer_enum::HALO_RASTERIZER_FULL); + const composite_mode_e comp_op = get(sym, keys::comp_op, feature, common_.vars_, src_over); + const composite_mode_e halo_comp_op = + get(sym, keys::halo_comp_op, feature, common_.vars_, src_over); agg_text_renderer ren(buffers_.top().get(), halo_rasterizer, comp_op, @@ -66,7 +70,7 @@ void agg_renderer::process(text_symbolizer const& sym, common_.scale_factor_, common_.font_manager_.get_stroker()); - auto halo_transform = get_optional(sym, keys::halo_transform); + const auto halo_transform = get_optional(sym, keys::halo_transform); if (halo_transform) { agg::trans_affine halo_affine_transform; diff --git a/src/build.py b/src/build.py index ac35d44f0..b68d33ef1 100644 --- a/src/build.py +++ b/src/build.py @@ -87,6 +87,7 @@ if '-DHAVE_TIFF' in env['CPPDEFINES']: if '-DHAVE_WEBP' in env['CPPDEFINES']: lib_env['LIBS'].append('webp') enabled_imaging_libraries.append('webp_reader.cpp') + enabled_imaging_libraries.append('webp_io.cpp') if env['XMLPARSER'] == 'libxml2' and env['HAS_LIBXML2']: lib_env['LIBS'].append('xml2') @@ -152,6 +153,7 @@ else: # unix, non-macos source = Split( """ + mapnik.cpp expression_grammar_x3.cpp fs.cpp request.cpp diff --git a/src/cairo/cairo_context.cpp b/src/cairo/cairo_context.cpp index 7be3e4243..50a25018d 100644 --- a/src/cairo/cairo_context.cpp +++ b/src/cairo/cairo_context.cpp @@ -192,11 +192,11 @@ void cairo_context::set_operator(composite_mode_e comp_op) void cairo_context::set_line_join(line_join_e join) { - if (join == MITER_JOIN) + if (join == line_join_enum::MITER_JOIN) cairo_set_line_join(cairo_.get(), CAIRO_LINE_JOIN_MITER); - else if (join == MITER_REVERT_JOIN) + else if (join == line_join_enum::MITER_REVERT_JOIN) cairo_set_line_join(cairo_.get(), CAIRO_LINE_JOIN_MITER); - else if (join == ROUND_JOIN) + else if (join == line_join_enum::ROUND_JOIN) cairo_set_line_join(cairo_.get(), CAIRO_LINE_JOIN_ROUND); else cairo_set_line_join(cairo_.get(), CAIRO_LINE_JOIN_BEVEL); @@ -205,9 +205,9 @@ void cairo_context::set_line_join(line_join_e join) void cairo_context::set_line_cap(line_cap_e cap) { - if (cap == BUTT_CAP) + if (cap == line_cap_enum::BUTT_CAP) cairo_set_line_cap(cairo_.get(), CAIRO_LINE_CAP_BUTT); - else if (cap == SQUARE_CAP) + else if (cap == line_cap_enum::SQUARE_CAP) cairo_set_line_cap(cairo_.get(), CAIRO_LINE_CAP_SQUARE); else cairo_set_line_cap(cairo_.get(), CAIRO_LINE_CAP_ROUND); @@ -480,7 +480,7 @@ void cairo_context::add_text(glyph_positions const& pos, pixel_position new_pos = glyph_pos.pos + glyph.offset.rotate(glyph_pos.rot); glyph_path(glyph.glyph_index, pixel_position(sx + new_pos.x, sy - new_pos.y)); set_line_width(2.0 * halo_radius); - set_line_join(ROUND_JOIN); + set_line_join(line_join_enum::ROUND_JOIN); set_color(glyph.format->halo_fill, glyph.format->halo_opacity); stroke(); } diff --git a/src/cairo/process_debug_symbolizer.cpp b/src/cairo/process_debug_symbolizer.cpp index fa28bc9ac..00e57563a 100644 --- a/src/cairo/process_debug_symbolizer.cpp +++ b/src/cairo/process_debug_symbolizer.cpp @@ -96,23 +96,27 @@ void cairo_renderer::process(debug_symbolizer const& sym, cairo_save_restore guard(context_); debug_symbolizer_mode_enum mode = - get(sym, keys::mode, feature, common_.vars_, DEBUG_SYM_MODE_COLLISION); + get(sym, + keys::mode, + feature, + common_.vars_, + debug_symbolizer_mode_enum::DEBUG_SYM_MODE_COLLISION); context_.set_operator(src_over); context_.set_color(mapnik::color(255, 0, 0), 1.0); - context_.set_line_join(MITER_JOIN); - context_.set_line_cap(BUTT_CAP); + context_.set_line_join(line_join_enum::MITER_JOIN); + context_.set_line_cap(line_cap_enum::BUTT_CAP); context_.set_miter_limit(4.0); context_.set_line_width(1.0); - if (mode == DEBUG_SYM_MODE_COLLISION) + if (mode == debug_symbolizer_mode_enum::DEBUG_SYM_MODE_COLLISION) { for (auto& n : *common_.detector_) { render_debug_box(context_, n.get().box); } } - else if (mode == DEBUG_SYM_MODE_VERTEX) + else if (mode == debug_symbolizer_mode_enum::DEBUG_SYM_MODE_VERTEX) { using apply_vertex_mode = apply_vertex_mode; apply_vertex_mode apply(context_, common_.t_, prj_trans); diff --git a/src/cairo/process_line_pattern_symbolizer.cpp b/src/cairo/process_line_pattern_symbolizer.cpp index 0a2c3fcc1..7371bbbc3 100644 --- a/src/cairo/process_line_pattern_symbolizer.cpp +++ b/src/cairo/process_line_pattern_symbolizer.cpp @@ -216,20 +216,20 @@ void cairo_renderer::process(line_pattern_symbolizer const& sym, return; } - line_pattern_enum pattern = get(sym, feature, common_.vars_); + const line_pattern_enum pattern = get(sym, feature, common_.vars_); switch (pattern) { - case LINE_PATTERN_WARP: { + case line_pattern_enum::LINE_PATTERN_WARP: { warp_pattern pattern(*marker, common_, sym, feature, prj_trans); pattern.render(context_); break; } - case LINE_PATTERN_REPEAT: { + case line_pattern_enum::LINE_PATTERN_REPEAT: { repeat_pattern pattern(*marker, common_, sym, feature, prj_trans); pattern.render(context_); break; } - case line_pattern_enum_MAX: + case line_pattern_enum::line_pattern_enum_MAX: default: MAPNIK_LOG_ERROR(process_line_pattern_symbolizer) << "Incorrect line-pattern value."; } diff --git a/src/create_image_reader.hpp b/src/create_image_reader.hpp new file mode 100644 index 000000000..184b4eb13 --- /dev/null +++ b/src/create_image_reader.hpp @@ -0,0 +1,19 @@ +#ifndef MAPNIK_CREATE_IMAGE_READER_HPP +#define MAPNIK_CREATE_IMAGE_READER_HPP + +namespace mapnik { +#ifdef HAVE_JPEG +void register_jpeg_reader(); +#endif +#ifdef HAVE_PNG +void register_png_reader(); +#endif +#ifdef HAVE_TIFF +void register_tiff_reader(); +#endif +#ifdef HAVE_WEBP +void register_webp_reader(); +#endif +} // namespace mapnik + +#endif diff --git a/src/datasource_cache.cpp b/src/datasource_cache.cpp index 54871f7f3..5539e3fc6 100644 --- a/src/datasource_cache.cpp +++ b/src/datasource_cache.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -53,15 +54,8 @@ bool is_input_plugin(std::string const& filename) return boost::algorithm::ends_with(filename, std::string(".input")); } -datasource_cache::datasource_cache() -{ - PluginInfo::init(); -} - -datasource_cache::~datasource_cache() -{ - PluginInfo::exit(); -} +datasource_cache::datasource_cache() {} +datasource_cache::~datasource_cache() {} datasource_ptr datasource_cache::create(parameters const& params) { @@ -71,11 +65,9 @@ datasource_ptr datasource_cache::create(parameters const& params) throw config_error(std::string("Could not create datasource. Required ") + "parameter 'type' is missing"); } - datasource_ptr ds; - #ifdef MAPNIK_STATIC_PLUGINS // return if it's created, raise otherwise - ds = create_static_datasource(params); + datasource_ptr ds = create_static_datasource(params); if (ds) { return ds; @@ -114,16 +106,14 @@ datasource_ptr datasource_cache::create(parameters const& params) #ifdef __GNUC__ __extension__ #endif - create_ds create_datasource = reinterpret_cast(itr->second->get_symbol("create")); + datasource_plugin* create_datasource = reinterpret_cast(itr->second->get_symbol("plugin")); if (!create_datasource) { throw std::runtime_error(std::string("Cannot load symbols: ") + itr->second->get_error()); } - ds = datasource_ptr(create_datasource(params), datasource_deleter()); - - return ds; + return create_datasource->create(params); } std::string datasource_cache::plugin_directories() @@ -134,7 +124,29 @@ std::string datasource_cache::plugin_directories() return boost::algorithm::join(plugin_directories_, ", "); } -std::vector datasource_cache::plugin_names() +bool datasource_cache::plugin_registered(const std::string& plugin_name) const +{ +#ifdef MAPNIK_STATIC_PLUGINS + const auto static_names = get_static_datasource_names(); + const auto static_it = std::find(static_names.begin(), static_names.end(), plugin_name); + if (static_it != static_names.end()) + return true; +#endif + +#ifdef MAPNIK_THREADSAFE + std::lock_guard lock(instance_mutex_); +#endif + + std::map>::const_iterator itr; + for (itr = plugins_.begin(); itr != plugins_.end(); ++itr) + { + if (itr->second->name() == plugin_name) + return true; + } + return false; +} + +std::vector datasource_cache::plugin_names() const { std::vector names; diff --git a/src/datasource_cache_static.cpp b/src/datasource_cache_static.cpp index 4da5d3480..97e67aad4 100644 --- a/src/datasource_cache_static.cpp +++ b/src/datasource_cache_static.cpp @@ -26,9 +26,7 @@ #ifdef MAPNIK_STATIC_PLUGINS #include - -// boost -#include +#include #endif // stl @@ -43,6 +41,9 @@ #if defined(MAPNIK_STATIC_PLUGIN_GDAL) #include "input/gdal/gdal_datasource.hpp" #endif +#if defined(MAPNIK_STATIC_PLUGIN_GEOBUF) +#include "input/geobuf/geobuf_datasource.hpp" +#endif #if defined(MAPNIK_STATIC_PLUGIN_GEOJSON) #include "input/geojson/geojson_datasource.hpp" #endif @@ -58,6 +59,9 @@ #if defined(MAPNIK_STATIC_PLUGIN_OGR) #include "input/ogr/ogr_datasource.hpp" #endif +#if defined(MAPNIK_STATIC_PLUGIN_PGRASTER) +#include "input/pgraster/pgraster_datasource.hpp" +#endif #if defined(MAPNIK_STATIC_PLUGIN_OSM) #include "input/osm/osm_datasource.hpp" #endif @@ -76,11 +80,21 @@ #if defined(MAPNIK_STATIC_PLUGIN_SQLITE) #include "input/sqlite/sqlite_datasource.hpp" #endif +#if defined(MAPNIK_STATIC_PLUGIN_TOPOJSON) +#include "input/topojson/topojson_datasource.hpp" +#endif #endif +#define REGISTER_STATIC_DATASOURCE_PLUGIN(classname) \ + { \ + auto plugin = std::make_shared(); \ + plugin->after_load(); \ + ds_map.emplace(std::string{classname::kName}, std::move(plugin)); \ + } namespace mapnik { #ifdef MAPNIK_STATIC_PLUGINS + template datasource_ptr ds_generator(parameters const& params) { @@ -88,56 +102,65 @@ datasource_ptr ds_generator(parameters const& params) } typedef datasource_ptr (*ds_generator_ptr)(parameters const& params); -using datasource_map = std::unordered_map; +using datasource_map = std::unordered_map>; -static datasource_map ds_map = boost::assign::map_list_of +static datasource_map ds_map{}; + +void init_datasource_cache_static() +{ #if defined(MAPNIK_STATIC_PLUGIN_CSV) - (std::string("csv"), &ds_generator) + REGISTER_STATIC_DATASOURCE_PLUGIN(csv_datasource_plugin); #endif #if defined(MAPNIK_STATIC_PLUGIN_GDAL) - (std::string("gdal"), &ds_generator) + REGISTER_STATIC_DATASOURCE_PLUGIN(gdal_datasource_plugin); +#endif +#if defined(MAPNIK_STATIC_PLUGIN_GEOBUF) + REGISTER_STATIC_DATASOURCE_PLUGIN(geobuf_datasource_plugin); #endif #if defined(MAPNIK_STATIC_PLUGIN_GEOJSON) - (std::string("geojson"), &ds_generator) + REGISTER_STATIC_DATASOURCE_PLUGIN(geojson_datasource_plugin); #endif #if defined(MAPNIK_STATIC_PLUGIN_OCCI) - (std::string("occi"), &ds_generator) + REGISTER_STATIC_DATASOURCE_PLUGIN(occi_datasource_plugin); #endif #if defined(MAPNIK_STATIC_PLUGIN_OGR) - (std::string("ogr"), &ds_generator) + REGISTER_STATIC_DATASOURCE_PLUGIN(ogr_datasource_plugin); +#endif +#if defined(MAPNIK_STATIC_PLUGIN_PGRASTER) + REGISTER_STATIC_DATASOURCE_PLUGIN(pgraster_datasource_plugin); #endif #if defined(MAPNIK_STATIC_PLUGIN_OSM) - (std::string("osm"), &ds_generator) + REGISTER_STATIC_DATASOURCE_PLUGIN(osm_datasource_plugin); #endif #if defined(MAPNIK_STATIC_PLUGIN_POSTGIS) - (std::string("postgis"), &ds_generator) + REGISTER_STATIC_DATASOURCE_PLUGIN(postgis_datasource_plugin); #endif #if defined(MAPNIK_STATIC_PLUGIN_RASTER) - (std::string("raster"), &ds_generator) + REGISTER_STATIC_DATASOURCE_PLUGIN(raster_datasource_plugin); #endif #if defined(MAPNIK_STATIC_PLUGIN_RASTERLITE) - (std::string("rasterlite"), &ds_generator) + REGISTER_STATIC_DATASOURCE_PLUGIN(rasterlite_datasource_plugin); #endif #if defined(MAPNIK_STATIC_PLUGIN_SHAPE) - (std::string("shape"), &ds_generator) + REGISTER_STATIC_DATASOURCE_PLUGIN(shape_datasource_plugin); #endif #if defined(MAPNIK_STATIC_PLUGIN_SQLITE) - (std::string("sqlite"), &ds_generator) + REGISTER_STATIC_DATASOURCE_PLUGIN(sqlite_datasource_plugin); #endif - ; +#if defined(MAPNIK_STATIC_PLUGIN_TOPOJSON) + REGISTER_STATIC_DATASOURCE_PLUGIN(topojson_datasource_plugin); #endif +}; -#ifdef MAPNIK_STATIC_PLUGINS datasource_ptr create_static_datasource(parameters const& params) { - datasource_ptr ds; boost::optional type = params.get("type"); datasource_map::iterator it = ds_map.find(*type); if (it != ds_map.end()) { - ds = it->second(params); + return it->second->create(params); } - return ds; + return datasource_ptr{}; } #else datasource_ptr create_static_datasource(parameters const& /*params*/) diff --git a/src/feature_type_style.cpp b/src/feature_type_style.cpp index 68587a413..092b1bfa6 100644 --- a/src/feature_type_style.cpp +++ b/src/feature_type_style.cpp @@ -20,21 +20,27 @@ * *****************************************************************************/ +#include +#include +#include #include #include #include -// boost - namespace mapnik { - -static const char* filter_mode_strings[] = {"all", "first", ""}; - -IMPLEMENT_ENUM(filter_mode_e, filter_mode_strings) +namespace { +using E = detail::EnumStringT; +constexpr detail::EnumMapT filter_mode_e_map{{ + E{filter_mode_enum::FILTER_ALL, "all"}, + E{filter_mode_enum::FILTER_FIRST, "first"}, + E{filter_mode_enum::filter_mode_enum_MAX, ""}, +}}; +} // namespace +IMPLEMENT_ENUM(filter_mode_e, filter_mode_enum); feature_type_style::feature_type_style() : rules_() - , filter_mode_(FILTER_ALL) + , filter_mode_(filter_mode_enum::FILTER_ALL) , filters_() , direct_filters_() , comp_op_() diff --git a/src/grid/process_line_pattern_symbolizer.cpp b/src/grid/process_line_pattern_symbolizer.cpp index 0d49c5224..e74d2598e 100644 --- a/src/grid/process_line_pattern_symbolizer.cpp +++ b/src/grid/process_line_pattern_symbolizer.cpp @@ -42,8 +42,6 @@ MAPNIK_DISABLE_WARNING_PUSH #include "agg_rasterizer_scanline_aa.h" #include "agg_renderer_scanline.h" #include "agg_scanline_bin.h" -#include "agg_conv_stroke.h" -#include "agg_conv_dash.h" MAPNIK_DISABLE_WARNING_POP // stl @@ -56,10 +54,10 @@ void grid_renderer::process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans) { - std::string filename = get(sym, feature, common_.vars_); + const std::string filename = get(sym, feature, common_.vars_); if (filename.empty()) return; - std::shared_ptr mark = marker_cache::instance().find(filename, true); + const auto mark = marker_cache::instance().find(filename, true); if (mark->is()) return; @@ -70,10 +68,10 @@ void grid_renderer::process(line_pattern_symbolizer const& sym, return; } - value_bool clip = get(sym, feature, common_.vars_); - value_double offset = get(sym, feature, common_.vars_); - value_double simplify_tolerance = get(sym, feature, common_.vars_); - value_double smooth = get(sym, feature, common_.vars_); + const value_bool clip = get(sym, feature, common_.vars_); + const value_double offset = get(sym, feature, common_.vars_); + const value_double simplify_tolerance = get(sym, feature, common_.vars_); + const value_double smooth = get(sym, feature, common_.vars_); using pixfmt_type = typename grid_renderer_base_type::pixfmt_type; using color_type = typename grid_renderer_base_type::pixfmt_type::color_type; @@ -90,12 +88,12 @@ void grid_renderer::process(line_pattern_symbolizer const& sym, ras_ptr->reset(); line_pattern_enum pattern = get(sym, feature, common_.vars_); - std::size_t stroke_width = (pattern == LINE_PATTERN_WARP) - ? mark->width() - : get(sym, feature, common_.vars_); + const std::size_t stroke_width = (pattern == line_pattern_enum::LINE_PATTERN_WARP) + ? mark->width() + : get(sym, feature, common_.vars_); agg::trans_affine tr; - auto transform = get_optional(sym, keys::geometry_transform); + const auto transform = get_optional(sym, keys::geometry_transform); if (transform) { evaluate_transform(tr, feature, common_.vars_, *transform, common_.scale_factor_); @@ -104,10 +102,10 @@ void grid_renderer::process(line_pattern_symbolizer const& sym, box2d clipping_extent = common_.query_extent_; if (clip) { - double pad_per_pixel = static_cast(common_.query_extent_.width() / common_.width_); - double pixels = std::ceil( + const double pad_per_pixel = static_cast(common_.query_extent_.width() / common_.width_); + const double pixels = std::ceil( std::max(stroke_width / 2.0 + std::fabs(offset), (std::fabs(offset) * offset_converter_default_threshold))); - double padding = pad_per_pixel * pixels * common_.scale_factor_; + const double padding = pad_per_pixel * pixels * common_.scale_factor_; clipping_extent.pad(padding); } diff --git a/src/jpeg_reader.cpp b/src/jpeg_reader.cpp index ff704f691..1e14acb59 100644 --- a/src/jpeg_reader.cpp +++ b/src/jpeg_reader.cpp @@ -91,7 +91,6 @@ class jpeg_reader : public image_reader static void attach_stream(j_decompress_ptr cinfo, input_stream* in); }; -namespace { image_reader* create_jpeg_reader(std::string const& filename) { return new jpeg_reader(filename); @@ -101,10 +100,11 @@ image_reader* create_jpeg_reader2(char const* data, size_t size) { return new jpeg_reader(data, size); } - -const bool registered = register_image_reader("jpeg", create_jpeg_reader); -const bool registered2 = register_image_reader("jpeg", create_jpeg_reader2); -} // namespace +void register_jpeg_reader() +{ + const bool registered = register_image_reader("jpeg", create_jpeg_reader); + const bool registered2 = register_image_reader("jpeg", create_jpeg_reader2); +} // ctors template diff --git a/src/json/CMakeLists.txt b/src/json/CMakeLists.txt index 5e57a1f20..4f64355fd 100644 --- a/src/json/CMakeLists.txt +++ b/src/json/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(json STATIC +target_sources(json PRIVATE extract_bounding_boxes_x3.cpp feature_from_geojson.cpp feature_grammar_x3.cpp @@ -13,7 +13,6 @@ add_library(json STATIC topojson_grammar_x3.cpp unicode_string_grammar_x3.cpp ) -add_library(mapnik::json ALIAS json) target_include_directories(json PRIVATE ${JPEG_INCLUDE_DIR} @@ -26,16 +25,12 @@ target_link_libraries(json PRIVATE mapnik::core ${ICUU_LIB}) set_target_properties(json PROPERTIES POSITION_INDEPENDENT_CODE ON - DEBUG_POSTFIX "${MAPNIK_DEBUG_POSTFIX}" OUTPUT_NAME "mapnikjson" PREFIX "lib" IMPORT_PREFIX "lib" VERSION ${MAPNIK_VERSION} # see mapnik target for explanation SOVERSION ${MAPNIK_VERSION} - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" ) mapnik_install(json) diff --git a/src/load_map.cpp b/src/load_map.cpp index 12833e568..5265d5a39 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -489,7 +489,7 @@ void map_parser::parse_style(Map& map, xml_node const& node) name = node.get_attr("name"); feature_type_style style; - filter_mode_e filter_mode = node.get_attr("filter-mode", FILTER_ALL); + filter_mode_e filter_mode = node.get_attr("filter-mode", filter_mode_enum::FILTER_ALL); style.set_filter_mode(filter_mode); // compositing @@ -1586,9 +1586,10 @@ bool map_parser::parse_raster_colorizer(raster_colorizer_ptr const& rc, xml_node try { // mode - colorizer_mode default_mode = node.get_attr("default-mode", COLORIZER_LINEAR); + colorizer_mode default_mode = + node.get_attr("default-mode", colorizer_mode_enum::COLORIZER_LINEAR); - if (default_mode == COLORIZER_INHERIT) + if (default_mode == colorizer_mode_enum::COLORIZER_INHERIT) { throw config_error("RasterColorizer mode must not be INHERIT. "); } @@ -1626,7 +1627,7 @@ bool map_parser::parse_raster_colorizer(raster_colorizer_ptr const& rc, xml_node } // mode default to INHERIT - colorizer_mode mode = n.get_attr("mode", COLORIZER_INHERIT); + colorizer_mode mode = n.get_attr("mode", colorizer_mode_enum::COLORIZER_INHERIT); // value is required, and it must be bigger than the previous optional val = n.get_opt_attr("value"); diff --git a/src/map.cpp b/src/map.cpp index ac77218cc..e10b10478 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -46,19 +46,22 @@ #include namespace mapnik { - -static const char* aspect_fix_mode_strings[] = {"GROW_BBOX", - "GROW_CANVAS", - "SHRINK_BBOX", - "SHRINK_CANVAS", - "ADJUST_BBOX_WIDTH", - "ADJUST_BBOX_HEIGHT", - "ADJUST_CANVAS_WIDTH", - "ADJUST_CANVAS_HEIGHT", - "RESPECT", - ""}; - -IMPLEMENT_ENUM(aspect_fix_mode_e, aspect_fix_mode_strings) +namespace { +using E = detail::EnumStringT; +constexpr detail::EnumMapT aspect_fix_mode_e_map{{ + E{Map::aspect_fix_mode::GROW_BBOX, "GROW_BBOX"}, + E{Map::aspect_fix_mode::GROW_CANVAS, "GROW_CANVAS"}, + E{Map::aspect_fix_mode::SHRINK_BBOX, "SHRINK_BBOX"}, + E{Map::aspect_fix_mode::SHRINK_CANVAS, "SHRINK_CANVAS"}, + E{Map::aspect_fix_mode::ADJUST_BBOX_WIDTH, "ADJUST_BBOX_WIDTH"}, + E{Map::aspect_fix_mode::ADJUST_BBOX_HEIGHT, "ADJUST_BBOX_HEIGHT"}, + E{Map::aspect_fix_mode::ADJUST_CANVAS_WIDTH, "ADJUST_CANVAS_WIDTH"}, + E{Map::aspect_fix_mode::ADJUST_CANVAS_HEIGHT, "ADJUST_CANVAS_HEIGHT"}, + E{Map::aspect_fix_mode::RESPECT, "RESPECT"}, + E{Map::aspect_fix_mode::aspect_fix_mode_MAX, ""}, +}}; +} // namespace +IMPLEMENT_ENUM(aspect_fix_mode_e, Map::aspect_fix_mode) Map::Map() : width_(400) diff --git a/src/mapnik.cpp b/src/mapnik.cpp new file mode 100644 index 000000000..11406cd69 --- /dev/null +++ b/src/mapnik.cpp @@ -0,0 +1,53 @@ +#include +#include // call once +#include "create_image_reader.hpp" +namespace mapnik { + +static void setup_once(); + +void setup() +{ + static std::once_flag init_flag; + std::call_once(init_flag, setup_once); +} +#ifdef MAPNIK_STATIC_PLUGINS +extern void init_datasource_cache_static(); +#endif +static void register_image_readers(); + +void setup_once() +{ +#ifdef MAPNIK_STATIC_PLUGINS + init_datasource_cache_static(); // defined in datasource_cache_static.cpp +#endif + register_image_readers(); +} + +void register_image_readers() +{ +#ifdef HAVE_JPEG + register_jpeg_reader(); +#endif +#ifdef HAVE_PNG + register_png_reader(); +#endif +#ifdef HAVE_TIFF + register_tiff_reader(); +#endif +#ifdef HAVE_WEBP + register_webp_reader(); +#endif +} +} // namespace mapnik + +// only on other systems then windows and in shared builds +#if !defined(MAPNIK_DISABLE_AUTOSETUP) && MAPNIK_STATIC_PLUGINS == 0 && !defined(_WIN32) +namespace { +class AutoSetup final +{ + public: + AutoSetup() { mapnik::setup(); }; +}; +AutoSetup auto_setup{}; +} // namespace +#endif diff --git a/src/marker_helpers.cpp b/src/marker_helpers.cpp index ec3733963..ccfb08237 100644 --- a/src/marker_helpers.cpp +++ b/src/marker_helpers.cpp @@ -302,7 +302,8 @@ void apply_markers_multi(feature_impl const& feature, get(sym, feature, vars); marker_placement_enum placement = get(sym, feature, vars); - if (placement == MARKER_POINT_PLACEMENT && multi_policy == MARKER_WHOLE_MULTI) + if (placement == marker_placement_enum::MARKER_POINT_PLACEMENT && + multi_policy == marker_multi_policy_enum::MARKER_WHOLE_MULTI) { geometry::point pt; // test if centroid is contained by bounding box @@ -314,9 +315,10 @@ void apply_markers_multi(feature_impl const& feature, converter.apply(va, proc); } } - else if ((placement == MARKER_POINT_PLACEMENT || placement == MARKER_INTERIOR_PLACEMENT || - placement == MARKER_POLYLABEL_PLACEMENT) && - multi_policy == MARKER_LARGEST_MULTI) + else if ((placement == marker_placement_enum::MARKER_POINT_PLACEMENT || + placement == marker_placement_enum::MARKER_INTERIOR_PLACEMENT || + placement == marker_placement_enum::MARKER_POLYLABEL_PLACEMENT) && + multi_policy == marker_multi_policy_enum::MARKER_LARGEST_MULTI) { // Only apply to path with largest envelope area // TODO: consider using true area for polygon types @@ -349,7 +351,8 @@ void apply_markers_multi(feature_impl const& feature, } else { - if (multi_policy != MARKER_EACH_MULTI && placement != MARKER_POINT_PLACEMENT) + if (multi_policy != marker_multi_policy_enum::MARKER_EACH_MULTI && + placement != marker_placement_enum::MARKER_POINT_PLACEMENT) { MAPNIK_LOG_WARN(marker_symbolizer) << "marker_multi_policy != 'each' has no effect with marker_placement != 'point'"; diff --git a/src/memory_datasource.cpp b/src/memory_datasource.cpp index eee058be6..60019011a 100644 --- a/src/memory_datasource.cpp +++ b/src/memory_datasource.cpp @@ -35,10 +35,14 @@ using mapnik::datasource; using mapnik::parameters; -DATASOURCE_PLUGIN(mapnik::memory_datasource) +DATASOURCE_PLUGIN_EXPORT(mapnik::memory_datasource_plugin) namespace mapnik { +DATASOURCE_PLUGIN_IMPL(memory_datasource_plugin, memory_datasource); +DATASOURCE_PLUGIN_EMPTY_AFTER_LOAD(memory_datasource_plugin); +DATASOURCE_PLUGIN_EMPTY_BEFORE_UNLOAD(memory_datasource_plugin); + struct accumulate_extent { accumulate_extent(box2d& ext) @@ -67,7 +71,7 @@ struct accumulate_extent const char* memory_datasource::name() { - return "memory"; + return mapnik::memory_datasource_plugin::kName; } memory_datasource::memory_datasource(parameters const& _params) diff --git a/src/plugin.cpp b/src/plugin.cpp index 6b6c6e8b7..fb37f9a03 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -23,6 +23,8 @@ #include #include +#include + #ifdef _WIN32 #define NOMINMAX #include @@ -45,56 +47,15 @@ namespace mapnik { struct _mapnik_lib_t { + std::string name; + std::string error_str; handle dl; -}; - -PluginInfo::PluginInfo(std::string const& filename, std::string const& library_name) - : filename_(filename) - , name_() - , module_(new mapnik_lib_t) -{ -#ifdef _WIN32 - if (module_) - module_->dl = LoadLibraryA(filename.c_str()); - if (module_ && module_->dl) - { - callable_returning_string name_call = - reinterpret_cast(dlsym(module_->dl, library_name.c_str())); - if (name_call) - name_ = name_call(); - callable_returning_void init_once = - reinterpret_cast(dlsym(module_->dl, "on_plugin_load")); - if (init_once) - { - init_once(); - } - } -#else -#ifdef MAPNIK_HAS_DLCFN - if (module_) - module_->dl = dlopen(filename.c_str(), RTLD_LAZY); - if (module_ && module_->dl) - { - callable_returning_string name_call = - reinterpret_cast(dlsym(module_->dl, library_name.c_str())); - if (name_call) - name_ = name_call(); - callable_returning_void init_once = - reinterpret_cast(dlsym(module_->dl, "on_plugin_load")); - if (init_once) - { - init_once(); - } - } -#else - throw std::runtime_error("no support for loading dynamic objects (Mapnik not compiled with -DMAPNIK_HAS_DLCFN)"); -#endif -#endif -} - -PluginInfo::~PluginInfo() -{ - if (module_) + _mapnik_lib_t() + : name{"unknown"} + , error_str{""} + , dl{nullptr} + {} + ~_mapnik_lib_t() { #ifdef MAPNIK_SUPPORTS_DLOPEN /* @@ -108,17 +69,55 @@ PluginInfo::~PluginInfo() in the case that gdal is linked as a shared library. This workaround therefore prevents crashes with gdal 1.11.x and gdal 2.x when using a static libgdal. */ - if (module_->dl && name_ != "gdal" && name_ != "ogr") + if (dl /*&& name_ != "gdal" && name_ != "ogr"*/) // is the gdal issue sill present? We are now + // unregister all drivers for ogal and gdal (todo: + // before_unload call) { #ifndef MAPNIK_NO_DLCLOSE - dlclose(module_->dl), module_->dl = 0; + dlclose(dl); + dl = nullptr; #endif } #endif - delete module_; } +}; + +PluginInfo::PluginInfo(std::string const& filename, std::string const& library_name) + : filename_(filename) + , module_{std::make_unique()} +{ + assert(module_ != nullptr); +#if defined(_WIN32) + module_->dl = LoadLibraryA(filename.c_str()); +#elif defined(MAPNIK_HAS_DLCFN) + module_->dl = dlopen(filename.c_str(), RTLD_LAZY); +#else + throw std::runtime_error("no support for loading dynamic objects (Mapnik not compiled with -DMAPNIK_HAS_DLCFN)"); +#endif +#if defined(MAPNIK_HAS_DLCFN) || defined(_WIN32) + if (module_->dl) + { + datasource_plugin* plugin{reinterpret_cast(get_symbol("plugin"))}; + if (!plugin) + throw std::runtime_error("plugin has a false interface"); //! todo: better error text + module_->name = plugin->name(); + module_->error_str = ""; + plugin->after_load(); + } + else + { + const auto errcode = dlerror(); +#ifdef _WIN32 + module_->error_str = std::system_category().message(errcode); +#else + module_->error_str = errcode ? errcode : ""; +#endif + } +#endif // defined(MAPNIK_HAS_DLCFN) || defined(_WIN32) } +PluginInfo::~PluginInfo() {} + void* PluginInfo::get_symbol(std::string const& sym_name) const { #ifdef MAPNIK_SUPPORTS_DLOPEN @@ -130,13 +129,13 @@ void* PluginInfo::get_symbol(std::string const& sym_name) const std::string const& PluginInfo::name() const { - return name_; + return module_->name; } bool PluginInfo::valid() const { #ifdef MAPNIK_SUPPORTS_DLOPEN - if (module_ && module_->dl && !name_.empty()) + if (module_->dl && !module_->name.empty()) return true; #endif return false; @@ -144,17 +143,7 @@ bool PluginInfo::valid() const std::string PluginInfo::get_error() const { - return std::string("could not open: '") + name_ + "'"; -} - -void PluginInfo::init() -{ - // do any initialization needed -} - -void PluginInfo::exit() -{ - // do any shutdown needed + return std::string{"could not open: '"} + module_->name + "'. Error: " + module_->error_str; } } // namespace mapnik diff --git a/src/png_reader.cpp b/src/png_reader.cpp index 746705b21..799cdeda5 100644 --- a/src/png_reader.cpp +++ b/src/png_reader.cpp @@ -80,8 +80,6 @@ class png_reader : public image_reader static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length); }; -namespace { - image_reader* create_png_reader(std::string const& filename) { return new png_reader(filename); @@ -92,9 +90,11 @@ image_reader* create_png_reader2(char const* data, std::size_t size) return new png_reader(data, size); } -const bool registered = register_image_reader("png", create_png_reader); -const bool registered2 = register_image_reader("png", create_png_reader2); -} // namespace +void register_png_reader() +{ + const bool registered = register_image_reader("png", create_png_reader); + const bool registered2 = register_image_reader("png", create_png_reader2); +} void user_error_fn(png_structp /*png_ptr*/, png_const_charp error_msg) { diff --git a/src/proj_transform.cpp b/src/proj_transform.cpp index 29be99f8b..33e6847f0 100644 --- a/src/proj_transform.cpp +++ b/src/proj_transform.cpp @@ -109,12 +109,12 @@ proj_transform::proj_transform(projection const& source, projection const& dest) bool known_trans = false; if (src_k && dest_k) { - if (*src_k == WGS_84 && *dest_k == WEB_MERC) + if (*src_k == well_known_srs_enum::WGS_84 && *dest_k == well_known_srs_enum::WEB_MERC) { wgs84_to_merc_ = true; known_trans = true; } - else if (*src_k == WEB_MERC && *dest_k == WGS_84) + else if (*src_k == well_known_srs_enum::WEB_MERC && *dest_k == well_known_srs_enum::WGS_84) { merc_to_wgs84_ = true; known_trans = true; diff --git a/src/raster_colorizer.cpp b/src/raster_colorizer.cpp index 1d4dae4ac..864aa9b23 100644 --- a/src/raster_colorizer.cpp +++ b/src/raster_colorizer.cpp @@ -36,10 +36,17 @@ namespace mapnik { //! \brief Strings for the colorizer_mode enumeration -static const char* colorizer_mode_strings[] = - {"inherit", "linear", "discrete", "exact", "linear-rgba", "linear-bgra", ""}; - -IMPLEMENT_ENUM(colorizer_mode, colorizer_mode_strings) +using colorizer_mode_str = detail::EnumStringT; +constexpr detail::EnumMapT colorizer_mode_map{{ + colorizer_mode_str{colorizer_mode_enum::COLORIZER_INHERIT, "inherit"}, + colorizer_mode_str{colorizer_mode_enum::COLORIZER_LINEAR, "linear"}, + colorizer_mode_str{colorizer_mode_enum::COLORIZER_DISCRETE, "discrete"}, + colorizer_mode_str{colorizer_mode_enum::COLORIZER_EXACT, "exact"}, + colorizer_mode_str{colorizer_mode_enum::COLORIZER_LINEAR_RGBA, "linear-rgba"}, + colorizer_mode_str{colorizer_mode_enum::COLORIZER_LINEAR_BGRA, "linear-bgra"}, + colorizer_mode_str{colorizer_mode_enum::colorizer_mode_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(colorizer_mode, colorizer_mode_enum) colorizer_stop::colorizer_stop(float val, colorizer_mode mode, color const& _color, std::string const& label) : value_(val) @@ -177,7 +184,7 @@ unsigned raster_colorizer::get_color(float val) const else { stopMode = stops_[stopIdx].get_mode(); - if (stopMode == COLORIZER_INHERIT) + if (stopMode == colorizer_mode_enum::COLORIZER_INHERIT) { stopMode = default_mode_; } @@ -206,7 +213,7 @@ unsigned raster_colorizer::get_color(float val) const switch (stopMode) { - case COLORIZER_LINEAR: { + case colorizer_mode_enum::COLORIZER_LINEAR: { // deal with this separately so we don't have to worry about div0 if (nextStopValue == stopValue) { @@ -228,7 +235,7 @@ unsigned raster_colorizer::get_color(float val) const } } break; - case COLORIZER_LINEAR_RGBA: { + case colorizer_mode_enum::COLORIZER_LINEAR_RGBA: { if (nextStopValue == stopValue) { return stopColor.rgba(); @@ -240,7 +247,7 @@ unsigned raster_colorizer::get_color(float val) const outputColor = color(colorStart + fraction * (colorEnd - colorStart)); } break; - case COLORIZER_LINEAR_BGRA: { + case colorizer_mode_enum::COLORIZER_LINEAR_BGRA: { if (nextStopValue == stopValue) { return stopColor.rgba(); @@ -255,10 +262,10 @@ unsigned raster_colorizer::get_color(float val) const std::swap(outputColor.red_, outputColor.blue_); } break; - case COLORIZER_DISCRETE: + case colorizer_mode_enum::COLORIZER_DISCRETE: outputColor = stopColor; break; - case COLORIZER_EXACT: + case colorizer_mode_enum::COLORIZER_EXACT: default: // approximately equal (within epsilon) if (std::fabs(val - stopValue) < epsilon_) diff --git a/src/renderer_common/pattern_alignment.cpp b/src/renderer_common/pattern_alignment.cpp index 96ac67088..c70fb3c1f 100644 --- a/src/renderer_common/pattern_alignment.cpp +++ b/src/renderer_common/pattern_alignment.cpp @@ -73,7 +73,7 @@ coord pattern_offset(symbolizer_base const& sym, coord reference_position(0, 0); pattern_alignment_enum alignment_type = get(sym, feature, common.vars_); - if (alignment_type == LOCAL_ALIGNMENT) + if (alignment_type == pattern_alignment_enum::LOCAL_ALIGNMENT) { apply_local_alignment apply(common.t_, prj_trans, reference_position.x, reference_position.y); util::apply_visitor(geometry::vertex_processor(apply), feature.get_geometry()); diff --git a/src/renderer_common/render_thunk_extractor.cpp b/src/renderer_common/render_thunk_extractor.cpp index fa10bf9b3..a6756128c 100644 --- a/src/renderer_common/render_thunk_extractor.cpp +++ b/src/renderer_common/render_thunk_extractor.cpp @@ -137,8 +137,11 @@ void render_thunk_extractor::extract_text_thunk(text_render_thunk::helper_ptr&& { double opacity = get(sym, keys::opacity, feature_, common_.vars_, 1.0); composite_mode_e comp_op = get(sym, keys::comp_op, feature_, common_.vars_, src_over); - halo_rasterizer_enum halo_rasterizer = - get(sym, keys::halo_rasterizer, feature_, common_.vars_, HALO_RASTERIZER_FULL); + halo_rasterizer_enum halo_rasterizer = get(sym, + keys::halo_rasterizer, + feature_, + common_.vars_, + halo_rasterizer_enum::HALO_RASTERIZER_FULL); text_render_thunk thunk(std::move(helper), opacity, comp_op, halo_rasterizer); thunks_.emplace_back(std::move(thunk)); diff --git a/src/svg/output/svg_output_attributes.cpp b/src/svg/output/svg_output_attributes.cpp index a3f6ed249..045182887 100644 --- a/src/svg/output/svg_output_attributes.cpp +++ b/src/svg/output/svg_output_attributes.cpp @@ -59,13 +59,13 @@ void path_output_attributes::set_stroke_linecap(line_cap_e stroke_linecap) { switch (stroke_linecap) { - case BUTT_CAP: + case line_cap_enum::BUTT_CAP: stroke_linecap_ = "butt"; break; - case SQUARE_CAP: + case line_cap_enum::SQUARE_CAP: stroke_linecap_ = "square"; break; - case ROUND_CAP: + case line_cap_enum::ROUND_CAP: stroke_linecap_ = "round"; break; default: @@ -77,16 +77,16 @@ void path_output_attributes::set_stroke_linejoin(line_join_e stroke_linejoin) { switch (stroke_linejoin) { - case MITER_JOIN: + case line_join_enum::MITER_JOIN: stroke_linejoin_ = "miter"; break; - case MITER_REVERT_JOIN: + case line_join_enum::MITER_REVERT_JOIN: stroke_linejoin_ = "miter"; break; - case ROUND_JOIN: + case line_join_enum::ROUND_JOIN: stroke_linejoin_ = "round"; break; - case BEVEL_JOIN: + case line_join_enum::BEVEL_JOIN: stroke_linejoin_ = "bevel"; break; default: diff --git a/src/symbolizer_enumerations.cpp b/src/symbolizer_enumerations.cpp index 15a65cc9b..927e48825 100644 --- a/src/symbolizer_enumerations.cpp +++ b/src/symbolizer_enumerations.cpp @@ -23,98 +23,202 @@ #include namespace mapnik { + // stroke -static const char* line_cap_strings[] = {"butt", "square", "round", ""}; +using line_cap_e_str = detail::EnumStringT; +constexpr detail::EnumMapT line_cap_e_map{{ + line_cap_e_str{line_cap_enum::BUTT_CAP, "butt"}, + line_cap_e_str{line_cap_enum::SQUARE_CAP, "square"}, + line_cap_e_str{line_cap_enum::ROUND_CAP, "round"}, + line_cap_e_str{line_cap_enum::line_cap_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(line_cap_e, line_cap_enum) -IMPLEMENT_ENUM(line_cap_e, line_cap_strings) - -static const char* line_join_strings[] = {"miter", "miter-revert", "round", "bevel", ""}; - -IMPLEMENT_ENUM(line_join_e, line_join_strings) +using line_join_e_str = detail::EnumStringT; +constexpr detail::EnumMapT line_join_e_map{{ + line_join_e_str{line_join_enum::MITER_JOIN, "miter"}, + line_join_e_str{line_join_enum::MITER_REVERT_JOIN, "miter-revert"}, + line_join_e_str{line_join_enum::ROUND_JOIN, "round"}, + line_join_e_str{line_join_enum::BEVEL_JOIN, "bevel"}, + line_join_e_str{line_join_enum::line_join_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(line_join_e, line_join_enum) // point symbolizer -static const char* point_placement_strings[] = {"centroid", "interior", ""}; - -IMPLEMENT_ENUM(point_placement_e, point_placement_strings) +using point_placement_e_str = detail::EnumStringT; +constexpr detail::EnumMapT point_placement_e_map{{ + point_placement_e_str{point_placement_enum::CENTROID_POINT_PLACEMENT, "centroid"}, + point_placement_e_str{point_placement_enum::INTERIOR_POINT_PLACEMENT, "interior"}, + point_placement_e_str{point_placement_enum::point_placement_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(point_placement_e, point_placement_enum) // line symbolizer -static const char* line_rasterizer_strings[] = {"full", "fast", ""}; -IMPLEMENT_ENUM(line_rasterizer_e, line_rasterizer_strings) +using line_rasterizer_e_str = detail::EnumStringT; +constexpr detail::EnumMapT line_rasterizer_e_map{{ + line_rasterizer_e_str{line_rasterizer_enum::RASTERIZER_FULL, "full"}, + line_rasterizer_e_str{line_rasterizer_enum::RASTERIZER_FAST, "fast"}, + line_rasterizer_e_str{line_rasterizer_enum::line_rasterizer_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(line_rasterizer_e, line_rasterizer_enum) // markers symbolizer -static const char* marker_placement_strings[] = - {"point", "interior", "line", "vertex-first", "vertex-last", "angled-point", "polylabel", ""}; +using marker_placement_e_str = detail::EnumStringT; +constexpr detail::EnumMapT marker_placement_e_map{{ + marker_placement_e_str{marker_placement_enum::MARKER_POINT_PLACEMENT, "point"}, + marker_placement_e_str{marker_placement_enum::MARKER_INTERIOR_PLACEMENT, "interior"}, + marker_placement_e_str{marker_placement_enum::MARKER_LINE_PLACEMENT, "line"}, + marker_placement_e_str{marker_placement_enum::MARKER_VERTEX_FIRST_PLACEMENT, "vertex-first"}, + marker_placement_e_str{marker_placement_enum::MARKER_VERTEX_LAST_PLACEMENT, "vertex-last"}, + marker_placement_e_str{marker_placement_enum::MARKER_ANGLED_POINT_PLACEMENT, "angled-point"}, + marker_placement_e_str{marker_placement_enum::MARKER_POLYLABEL_PLACEMENT, "polylabel"}, + marker_placement_e_str{marker_placement_enum::marker_placement_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(marker_placement_e, marker_placement_enum) -IMPLEMENT_ENUM(marker_placement_e, marker_placement_strings) - -static const char* marker_multi_policy_strings[] = {"each", "whole", "largest", ""}; - -IMPLEMENT_ENUM(marker_multi_policy_e, marker_multi_policy_strings) +using marker_multi_policy_e_str = detail::EnumStringT; +constexpr detail::EnumMapT marker_multi_policy_e_map{{ + marker_multi_policy_e_str{marker_multi_policy_enum::MARKER_EACH_MULTI, "each"}, + marker_multi_policy_e_str{marker_multi_policy_enum::MARKER_WHOLE_MULTI, "whole"}, + marker_multi_policy_e_str{marker_multi_policy_enum::MARKER_LARGEST_MULTI, "largest"}, + marker_multi_policy_e_str{marker_multi_policy_enum::marker_multi_policy_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(marker_multi_policy_e, marker_multi_policy_enum) // debug symbolizer -static const char* debug_symbolizer_mode_strings[] = {"collision", "vertex", "rings", ""}; - -IMPLEMENT_ENUM(debug_symbolizer_mode_e, debug_symbolizer_mode_strings) +using debug_symbolizer_mode_e_str = detail::EnumStringT; +constexpr detail::EnumMapT debug_symbolizer_mode_e_map{{ + debug_symbolizer_mode_e_str{debug_symbolizer_mode_enum::DEBUG_SYM_MODE_COLLISION, "collision"}, + debug_symbolizer_mode_e_str{debug_symbolizer_mode_enum::DEBUG_SYM_MODE_VERTEX, "vertex"}, + debug_symbolizer_mode_e_str{debug_symbolizer_mode_enum::DEBUG_SYM_MODE_RINGS, "rings"}, + debug_symbolizer_mode_e_str{debug_symbolizer_mode_enum::debug_symbolizer_mode_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(debug_symbolizer_mode_e, debug_symbolizer_mode_enum) // polygon pattern symbolizer -static const char* pattern_alignment_strings[] = {"local", // feature - "global", // map - ""}; - -IMPLEMENT_ENUM(pattern_alignment_e, pattern_alignment_strings) +using pattern_alignment_e_str = detail::EnumStringT; +constexpr detail::EnumMapT pattern_alignment_e_map{{ + pattern_alignment_e_str{pattern_alignment_enum::LOCAL_ALIGNMENT, "local"}, // feature + pattern_alignment_e_str{pattern_alignment_enum::GLOBAL_ALIGNMENT, "global"}, // map + pattern_alignment_e_str{pattern_alignment_enum::pattern_alignment_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(pattern_alignment_e, pattern_alignment_enum) // text -static const char* halo_rasterizer_strings[] = {"full", "fast", ""}; +using halo_rasterizer_e_str = detail::EnumStringT; +constexpr detail::EnumMapT halo_rasterizer_e_map{{ + halo_rasterizer_e_str{halo_rasterizer_enum::HALO_RASTERIZER_FULL, "full"}, + halo_rasterizer_e_str{halo_rasterizer_enum::HALO_RASTERIZER_FAST, "fast"}, + halo_rasterizer_e_str{halo_rasterizer_enum::halo_rasterizer_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(halo_rasterizer_e, halo_rasterizer_enum) -IMPLEMENT_ENUM(halo_rasterizer_e, halo_rasterizer_strings) +using label_placement_e_str = detail::EnumStringT; +constexpr detail::EnumMapT label_placement_e_map{{ + label_placement_e_str{label_placement_enum::POINT_PLACEMENT, "point"}, + label_placement_e_str{label_placement_enum::LINE_PLACEMENT, "line"}, + label_placement_e_str{label_placement_enum::VERTEX_PLACEMENT, "vertex"}, + label_placement_e_str{label_placement_enum::INTERIOR_PLACEMENT, "interior"}, + label_placement_e_str{label_placement_enum::POLYLABEL_PLACEMENT, "polylabel"}, + label_placement_e_str{label_placement_enum::GRID_PLACEMENT, "grid"}, + label_placement_e_str{label_placement_enum::ALTERNATING_GRID_PLACEMENT, "alternating-grid"}, + label_placement_e_str{label_placement_enum::label_placement_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(label_placement_e, label_placement_enum) -static const char* label_placement_strings[] = - {"point", "line", "vertex", "interior", "polylabel", "grid", "alternating-grid", ""}; +using vertical_alignment_e_str = detail::EnumStringT; +constexpr detail::EnumMapT vertical_alignment_e_map{{ + vertical_alignment_e_str{vertical_alignment_enum::V_TOP, "top"}, + vertical_alignment_e_str{vertical_alignment_enum::V_MIDDLE, "middle"}, + vertical_alignment_e_str{vertical_alignment_enum::V_BOTTOM, "bottom"}, + vertical_alignment_e_str{vertical_alignment_enum::V_AUTO, "auto"}, + vertical_alignment_e_str{vertical_alignment_enum::vertical_alignment_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(vertical_alignment_e, vertical_alignment_enum) -IMPLEMENT_ENUM(label_placement_e, label_placement_strings) +using horizontal_alignment_e_str = detail::EnumStringT; +constexpr detail::EnumMapT horizontal_alignment_e_map{{ + horizontal_alignment_e_str{horizontal_alignment_enum::H_LEFT, "left"}, + horizontal_alignment_e_str{horizontal_alignment_enum::H_MIDDLE, "middle"}, + horizontal_alignment_e_str{horizontal_alignment_enum::H_RIGHT, "right"}, + horizontal_alignment_e_str{horizontal_alignment_enum::H_AUTO, "auto"}, + horizontal_alignment_e_str{horizontal_alignment_enum::H_ADJUST, "adjust"}, + horizontal_alignment_e_str{horizontal_alignment_enum::horizontal_alignment_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(horizontal_alignment_e, horizontal_alignment_enum) -static const char* vertical_alignment_strings[] = {"top", "middle", "bottom", "auto", ""}; +using justify_alignment_e_str = detail::EnumStringT; +constexpr detail::EnumMapT justify_alignment_e_map{{ + justify_alignment_e_str{justify_alignment_enum::J_LEFT, "left"}, + justify_alignment_e_str{justify_alignment_enum::J_MIDDLE, "center"}, // not 'middle' in order to match CSS + justify_alignment_e_str{justify_alignment_enum::J_RIGHT, "right"}, + justify_alignment_e_str{justify_alignment_enum::J_AUTO, "auto"}, + justify_alignment_e_str{justify_alignment_enum::justify_alignment_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(justify_alignment_e, justify_alignment_enum) -IMPLEMENT_ENUM(vertical_alignment_e, vertical_alignment_strings) +using text_transform_e_str = detail::EnumStringT; +constexpr detail::EnumMapT text_transform_e_map{{ + text_transform_e_str{text_transform_enum::NONE, "none"}, + text_transform_e_str{text_transform_enum::UPPERCASE, "uppercase"}, + text_transform_e_str{text_transform_enum::LOWERCASE, "lowercase"}, + text_transform_e_str{text_transform_enum::CAPITALIZE, "capitalize"}, + text_transform_e_str{text_transform_enum::REVERSE, "reverse"}, + text_transform_e_str{text_transform_enum::text_transform_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(text_transform_e, text_transform_enum) -static const char* horizontal_alignment_strings[] = {"left", "middle", "right", "auto", "adjust", ""}; +using text_upright_e_str = detail::EnumStringT; +constexpr detail::EnumMapT text_upright_e_map{{ + text_upright_e_str{text_upright_enum::UPRIGHT_AUTO, "auto"}, + text_upright_e_str{text_upright_enum::UPRIGHT_AUTO_DOWN, "auto-down"}, + text_upright_e_str{text_upright_enum::UPRIGHT_LEFT, "left"}, + text_upright_e_str{text_upright_enum::UPRIGHT_RIGHT, "right"}, + text_upright_e_str{text_upright_enum::UPRIGHT_LEFT_ONLY, "left-only"}, + text_upright_e_str{text_upright_enum::UPRIGHT_RIGHT_ONLY, "right-only"}, + text_upright_e_str{text_upright_enum::text_upright_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(text_upright_e, text_upright_enum) -IMPLEMENT_ENUM(horizontal_alignment_e, horizontal_alignment_strings) +using direction_e_str = detail::EnumStringT; +constexpr detail::EnumMapT direction_e_map{{ + direction_e_str{direction_enum::DIRECTION_LEFT, "left"}, + direction_e_str{direction_enum::DIRECTION_RIGHT, "right"}, + direction_e_str{direction_enum::DIRECTION_LEFT_ONLY, "left-only"}, + direction_e_str{direction_enum::DIRECTION_RIGHT_ONLY, "right-only"}, + direction_e_str{direction_enum::DIRECTION_AUTO, "auto"}, + direction_e_str{direction_enum::DIRECTION_AUTO_DOWN, "auto-down"}, + direction_e_str{direction_enum::DIRECTION_UP, "up"}, + direction_e_str{direction_enum::DIRECTION_DOWN, "down"}, + direction_e_str{direction_enum::direction_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(direction_e, direction_enum) -static const char* justify_alignment_strings[] = {"left", - "center", // not 'middle' in order to match CSS - "right", - "auto", - ""}; +using gamma_method_e_str = detail::EnumStringT; +constexpr detail::EnumMapT gamma_method_e_map{{ + gamma_method_e_str{gamma_method_enum::GAMMA_POWER, "power"}, // agg::gamma_power + gamma_method_e_str{gamma_method_enum::GAMMA_LINEAR, "linear"}, // agg::gamma_linear + gamma_method_e_str{gamma_method_enum::GAMMA_NONE, "none"}, // agg::gamma_none + gamma_method_e_str{gamma_method_enum::GAMMA_THRESHOLD, "threshold"}, // agg::gamma_threshold + gamma_method_e_str{gamma_method_enum::GAMMA_MULTIPLY, "multiply"}, // agg::gamma_multiply" + gamma_method_e_str{gamma_method_enum::gamma_method_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(gamma_method_e, gamma_method_enum) -IMPLEMENT_ENUM(justify_alignment_e, justify_alignment_strings) +using line_pattern_e_str = detail::EnumStringT; +constexpr detail::EnumMapT line_pattern_e_map{{ + line_pattern_e_str{line_pattern_enum::LINE_PATTERN_WARP, "warp"}, + line_pattern_e_str{line_pattern_enum::LINE_PATTERN_REPEAT, "repeat"}, + line_pattern_e_str{line_pattern_enum::line_pattern_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(line_pattern_e, line_pattern_enum) -static const char* text_transform_strings[] = {"none", "uppercase", "lowercase", "capitalize", "reverse", ""}; - -IMPLEMENT_ENUM(text_transform_e, text_transform_strings) - -static const char* text_upright_strings[] = {"auto", "auto-down", "left", "right", "left-only", "right-only", ""}; -IMPLEMENT_ENUM(text_upright_e, text_upright_strings) - -static const char* direction_strings[] = - {"left", "right", "left-only", "right-only", "auto", "auto-down", "up", "down", ""}; -IMPLEMENT_ENUM(direction_e, direction_strings) - -static const char* gamma_method_strings[] = {"power", // agg::gamma_power - "linear", // agg::gamma_linear - "none", // agg::gamma_none - "threshold", // agg::gamma_threshold - "multiply", // agg::gamma_multiply", - ""}; - -IMPLEMENT_ENUM(gamma_method_e, gamma_method_strings) - -static const char* line_pattern_strings[] = {"warp", "repeat", ""}; - -IMPLEMENT_ENUM(line_pattern_e, line_pattern_strings) - -static const char* smooth_algorithm_strings[] = {"basic", "adaptive", ""}; - -IMPLEMENT_ENUM(smooth_algorithm_e, smooth_algorithm_strings) +using smooth_algorithm_e_str = detail::EnumStringT; +constexpr detail::EnumMapT smooth_algorithm_e_map{{ + smooth_algorithm_e_str{smooth_algorithm_enum::SMOOTH_ALGORITHM_BASIC, "basic"}, + smooth_algorithm_e_str{smooth_algorithm_enum::SMOOTH_ALGORITHM_ADAPTIVE, "adaptive"}, + smooth_algorithm_e_str{smooth_algorithm_enum::smooth_algorithm_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(smooth_algorithm_e, smooth_algorithm_enum) } // namespace mapnik diff --git a/src/symbolizer_keys.cpp b/src/symbolizer_keys.cpp index 83cc42ba9..6e3372683 100644 --- a/src/symbolizer_keys.cpp +++ b/src/symbolizer_keys.cpp @@ -36,13 +36,10 @@ static const property_meta_type key_meta[const_max_key] = { property_meta_type{"gamma", nullptr, property_types::target_double}, property_meta_type{"gamma-method", nullptr, property_types::target_gamma_method}, property_meta_type{"opacity", nullptr, property_types::target_double}, - property_meta_type{"alignment", - [](enumeration_wrapper e) { - return enumeration( - pattern_alignment_enum(e.value)) - .as_string(); - }, - property_types::target_pattern_alignment}, + property_meta_type{ + "alignment", + [](enumeration_wrapper e) { return pattern_alignment_e(pattern_alignment_enum(e.value)).as_string(); }, + property_types::target_pattern_alignment}, property_meta_type{"offset", nullptr, property_types::target_double}, property_meta_type{"comp-op", [](enumeration_wrapper e) { return *comp_op_to_string(composite_mode_e(e.value)); }, @@ -54,14 +51,10 @@ static const property_meta_type key_meta[const_max_key] = { property_meta_type{"stroke-width", nullptr, property_types::target_double}, property_meta_type{"stroke-opacity", nullptr, property_types::target_double}, property_meta_type{"stroke-linejoin", - [](enumeration_wrapper e) { - return enumeration(line_join_enum(e.value)).as_string(); - }, + [](enumeration_wrapper e) { return line_join_e(line_join_enum(e.value)).as_string(); }, property_types::target_line_join}, property_meta_type{"stroke-linecap", - [](enumeration_wrapper e) { - return enumeration(line_cap_enum(e.value)).as_string(); - }, + [](enumeration_wrapper e) { return line_cap_e(line_cap_enum(e.value)).as_string(); }, property_types::target_line_cap}, property_meta_type{"stroke-gamma", nullptr, property_types::target_double}, property_meta_type{"stroke-gamma-method", nullptr, property_types::target_gamma_method}, @@ -71,12 +64,9 @@ static const property_meta_type key_meta[const_max_key] = { property_meta_type{"geometry-transform", nullptr, property_types::target_transform}, // TODO - should be called 'line-rasterizer' but for back compat with 2.3.x we keep as 'rasterizer' // https://github.com/mapnik/mapnik/issues/2503 - property_meta_type{ - "rasterizer", - [](enumeration_wrapper e) { - return enumeration(line_rasterizer_enum(e.value)).as_string(); - }, - property_types::target_double}, + property_meta_type{"rasterizer", + [](enumeration_wrapper e) { return line_rasterizer_e(line_rasterizer_enum(e.value)).as_string(); }, + property_types::target_double}, property_meta_type{"transform", nullptr, property_types::target_transform}, property_meta_type{"spacing", nullptr, property_types::target_double}, property_meta_type{"spacing-offset", nullptr, property_types::target_double}, @@ -97,50 +87,32 @@ static const property_meta_type key_meta[const_max_key] = { property_meta_type{"mesh-size", nullptr, property_types::target_double}, property_meta_type{"premultiplied", nullptr, property_types::target_bool}, property_meta_type{"smooth", nullptr, property_types::target_double}, - property_meta_type{"smooth-algorithm", - [](enumeration_wrapper e) { - return enumeration( - smooth_algorithm_enum(e.value)) - .as_string(); - }, - property_types::target_smooth_algorithm}, + property_meta_type{ + "smooth-algorithm", + [](enumeration_wrapper e) { return smooth_algorithm_e(smooth_algorithm_enum(e.value)).as_string(); }, + property_types::target_smooth_algorithm}, property_meta_type{"simplify-algorithm", [](enumeration_wrapper e) { return *simplify_algorithm_to_string(simplify_algorithm_e(e.value)); }, property_types::target_simplify_algorithm}, property_meta_type{"simplify", nullptr, property_types::target_double}, - property_meta_type{ - "halo-rasterizer", - [](enumeration_wrapper e) { - return enumeration(halo_rasterizer_enum(e.value)).as_string(); - }, - property_types::target_halo_rasterizer}, + property_meta_type{"halo-rasterizer", + [](enumeration_wrapper e) { return halo_rasterizer_e(halo_rasterizer_enum(e.value)).as_string(); }, + property_types::target_halo_rasterizer}, property_meta_type{"text-placements", nullptr, property_types::target_double}, - property_meta_type{ - "placement", - [](enumeration_wrapper e) { - return enumeration(label_placement_enum(e.value)).as_string(); - }, - property_types::target_placement}, - property_meta_type{"placement", // FIXME - change property name - [](enumeration_wrapper e) { - return enumeration( - marker_placement_enum(e.value)) - .as_string(); - }, - property_types::target_markers_placement}, - property_meta_type{"multi-policy", - [](enumeration_wrapper e) { - return enumeration( - marker_multi_policy_enum(e.value)) - .as_string(); - }, - property_types::target_markers_multipolicy}, + property_meta_type{"placement", + [](enumeration_wrapper e) { return label_placement_e(label_placement_enum(e.value)).as_string(); }, + property_types::target_placement}, property_meta_type{ "placement", // FIXME - change property name - [](enumeration_wrapper e) { - return enumeration(point_placement_enum(e.value)).as_string(); - }, - property_types::target_double}, + [](enumeration_wrapper e) { return marker_placement_e(marker_placement_enum(e.value)).as_string(); }, + property_types::target_markers_placement}, + property_meta_type{ + "multi-policy", + [](enumeration_wrapper e) { return marker_multi_policy_e(marker_multi_policy_enum(e.value)).as_string(); }, + property_types::target_markers_multipolicy}, + property_meta_type{"placement", // FIXME - change property name + [](enumeration_wrapper e) { return point_placement_e(point_placement_enum(e.value)).as_string(); }, + property_types::target_double}, property_meta_type{"colorizer", nullptr, property_types::target_colorizer}, property_meta_type{"halo-transform", nullptr, property_types::target_transform}, property_meta_type{"num-columns", nullptr, property_types::target_integer}, @@ -152,53 +124,33 @@ static const property_meta_type key_meta[const_max_key] = { property_meta_type{"halo-comp-op", [](enumeration_wrapper e) { return *comp_op_to_string(composite_mode_e(e.value)); }, property_types::target_halo_comp_op}, + property_meta_type{"text-transform", + [](enumeration_wrapper e) { return text_transform_e(text_transform_enum(e.value)).as_string(); }, + property_types::target_text_transform}, property_meta_type{ - "text-transform", - [](enumeration_wrapper e) { - return enumeration(text_transform_enum(e.value)).as_string(); - }, - property_types::target_text_transform}, - property_meta_type{"horizontal-alignment", - [](enumeration_wrapper e) { - return enumeration( - horizontal_alignment_enum(e.value)) - .as_string(); - }, - property_types::target_horizontal_alignment}, - property_meta_type{"justify-alignment", - [](enumeration_wrapper e) { - return enumeration( - justify_alignment_enum(e.value)) - .as_string(); - }, - property_types::target_justify_alignment}, - property_meta_type{"vertical-alignment", - [](enumeration_wrapper e) { - return enumeration( - vertical_alignment_enum(e.value)) - .as_string(); - }, - property_types::target_vertical_alignment}, + "horizontal-alignment", + [](enumeration_wrapper e) { return horizontal_alignment_e(horizontal_alignment_enum(e.value)).as_string(); }, + property_types::target_horizontal_alignment}, property_meta_type{ - "upright", - [](enumeration_wrapper e) { - return enumeration(text_upright_enum(e.value)).as_string(); - }, - property_types::target_upright}, + "justify-alignment", + [](enumeration_wrapper e) { return justify_alignment_e(justify_alignment_enum(e.value)).as_string(); }, + property_types::target_justify_alignment}, + property_meta_type{ + "vertical-alignment", + [](enumeration_wrapper e) { return vertical_alignment_e(vertical_alignment_enum(e.value)).as_string(); }, + property_types::target_vertical_alignment}, + property_meta_type{"upright", + [](enumeration_wrapper e) { return text_upright_e(text_upright_enum(e.value)).as_string(); }, + property_types::target_upright}, property_meta_type{"direction", - [](enumeration_wrapper e) { - return enumeration(direction_enum(e.value)).as_string(); - }, + [](enumeration_wrapper e) { return direction_e(direction_enum(e.value)).as_string(); }, property_types::target_direction}, property_meta_type{"avoid-edges", nullptr, property_types::target_bool}, property_meta_type{"font-feature-settings", nullptr, property_types::target_font_feature_settings}, property_meta_type{"extend", nullptr, property_types::target_double}, - property_meta_type{ - "line-pattern", - [](enumeration_wrapper e) { - return enumeration(line_pattern_enum(e.value)).as_string(); - }, - property_types::target_line_pattern}, + property_meta_type{"line-pattern", + [](enumeration_wrapper e) { return line_pattern_e(line_pattern_enum(e.value)).as_string(); }, + property_types::target_line_pattern}, }; diff --git a/src/text/formatting/text.cpp b/src/text/formatting/text.cpp index 6ba205f18..37b971f12 100644 --- a/src/text/formatting/text.cpp +++ b/src/text/formatting/text.cpp @@ -61,16 +61,16 @@ void text_node::apply(evaluated_format_properties_ptr const& p, util::apply_visitor(evaluate(feature, vars), *text_).to_unicode(); switch (p->text_transform) { - case UPPERCASE: + case text_transform_enum::UPPERCASE: text_str.toUpper(); break; - case LOWERCASE: + case text_transform_enum::LOWERCASE: text_str.toLower(); break; - case REVERSE: + case text_transform_enum::REVERSE: text_str.reverse(); break; - case CAPITALIZE: + case text_transform_enum::CAPITALIZE: #if !UCONFIG_NO_BREAK_ITERATION // note: requires BreakIterator support in ICU which is optional text_str.toTitle(nullptr); diff --git a/src/text/placement_finder.cpp b/src/text/placement_finder.cpp index dd127b6b4..e33463113 100644 --- a/src/text/placement_finder.cpp +++ b/src/text/placement_finder.cpp @@ -97,7 +97,7 @@ placement_finder::placement_finder(feature_impl const& feature, , marker_unlocked_(false) , marker_displacement_() , move_dx_(0.0) - , horizontal_alignment_(H_LEFT) + , horizontal_alignment_(horizontal_alignment_enum::H_LEFT) {} bool placement_finder::next_position() @@ -135,23 +135,23 @@ bool placement_finder::next_position() text_upright_e placement_finder::simplify_upright(text_upright_e upright, double angle) const { - if (upright == UPRIGHT_AUTO) + if (upright == text_upright_enum::UPRIGHT_AUTO) { angle = util::normalize_angle(angle); - return std::abs(angle) > util::tau / 4 ? UPRIGHT_LEFT : UPRIGHT_RIGHT; + return std::abs(angle) > util::tau / 4 ? text_upright_enum::UPRIGHT_LEFT : text_upright_enum::UPRIGHT_RIGHT; } - if (upright == UPRIGHT_AUTO_DOWN) + if (upright == text_upright_enum::UPRIGHT_AUTO_DOWN) { angle = util::normalize_angle(angle); - return std::abs(angle) < util::tau / 4 ? UPRIGHT_LEFT : UPRIGHT_RIGHT; + return std::abs(angle) < util::tau / 4 ? text_upright_enum::UPRIGHT_LEFT : text_upright_enum::UPRIGHT_RIGHT; } - if (upright == UPRIGHT_LEFT_ONLY) + if (upright == text_upright_enum::UPRIGHT_LEFT_ONLY) { - return UPRIGHT_LEFT; + return text_upright_enum::UPRIGHT_LEFT; } - if (upright == UPRIGHT_RIGHT_ONLY) + if (upright == text_upright_enum::UPRIGHT_RIGHT_ONLY) { - return UPRIGHT_RIGHT; + return text_upright_enum::UPRIGHT_RIGHT; } return upright; } @@ -270,12 +270,12 @@ bool placement_finder::single_line_placement(vertex_cache& pp, text_upright_e or text_layout const& layout = *layout_ptr; pixel_position align_offset = layout.alignment_offset(); pixel_position const& layout_displacement = layout.displacement(); - double sign = (real_orientation == UPRIGHT_LEFT) ? -1 : 1; + double sign = (real_orientation == text_upright_enum::UPRIGHT_LEFT) ? -1 : 1; // double offset = 0 - (layout_displacement.y + 0.5 * sign * layout.height()); double offset = layout_displacement.y - 0.5 * sign * layout.height(); double adjust_character_spacing = .0; double layout_width = layout.width(); - bool adjust = layout.horizontal_alignment() == H_ADJUST; + bool adjust = layout.horizontal_alignment() == horizontal_alignment_enum::H_ADJUST; if (adjust) { @@ -371,23 +371,30 @@ bool placement_finder::single_line_placement(vertex_cache& pp, text_upright_e or if (upside_down_glyph_count > static_cast(layouts_.text().length() / 2)) { - if (orientation == UPRIGHT_AUTO) + if (orientation == text_upright_enum::UPRIGHT_AUTO) { // Try again with opposite orientation begin.restore(); - return single_line_placement(pp, real_orientation == UPRIGHT_RIGHT ? UPRIGHT_LEFT : UPRIGHT_RIGHT); + return single_line_placement(pp, + real_orientation == text_upright_enum::UPRIGHT_RIGHT + ? text_upright_enum::UPRIGHT_LEFT + : text_upright_enum::UPRIGHT_RIGHT); } // upright==left-only or right-only and more than 50% of characters upside down => no placement - else if (orientation == UPRIGHT_LEFT_ONLY || orientation == UPRIGHT_RIGHT_ONLY) + else if (orientation == text_upright_enum::UPRIGHT_LEFT_ONLY || + orientation == text_upright_enum::UPRIGHT_RIGHT_ONLY) { return false; } } - else if (orientation == UPRIGHT_AUTO_DOWN) + else if (orientation == text_upright_enum::UPRIGHT_AUTO_DOWN) { // Try again with opposite orientation begin.restore(); - return single_line_placement(pp, real_orientation == UPRIGHT_RIGHT ? UPRIGHT_LEFT : UPRIGHT_RIGHT); + return single_line_placement(pp, + real_orientation == text_upright_enum::UPRIGHT_RIGHT + ? text_upright_enum::UPRIGHT_LEFT + : text_upright_enum::UPRIGHT_RIGHT); } box2d label_box; @@ -424,7 +431,7 @@ void placement_finder::path_move_dx(vertex_cache& pp, double dx) double placement_finder::get_spacing(double path_length, double layout_width) const { int num_labels = 1; - if (horizontal_alignment_ != H_ADJUST && text_props_->label_spacing > 0) + if (horizontal_alignment_ != horizontal_alignment_enum::H_ADJUST && text_props_->label_spacing > 0) { num_labels = static_cast(std::floor(path_length / (text_props_->label_spacing * scale_factor_ + layout_width))); diff --git a/src/text/renderer.cpp b/src/text/renderer.cpp index 190c18be0..1c3a37c9f 100644 --- a/src/text/renderer.cpp +++ b/src/text/renderer.cpp @@ -32,22 +32,6 @@ #include #include -#include -MAPNIK_DISABLE_WARNING_PUSH -#include -#include "agg_rendering_buffer.h" -#include "agg_pixfmt_rgba.h" -#include "agg_color_rgba.h" -#include "agg_scanline_u.h" -#include "agg_image_filters.h" -#include "agg_trans_bilinear.h" -#include "agg_span_allocator.h" -#include "agg_image_accessors.h" -#include "agg_span_image_filter_rgba.h" -#include "agg_renderer_base.h" -#include "agg_renderer_scanline.h" -MAPNIK_DISABLE_WARNING_POP - namespace mapnik { text_renderer::text_renderer(halo_rasterizer_e rasterizer, @@ -225,7 +209,7 @@ void agg_text_renderer::render(glyph_positions const& pos) if (!error) { FT_Glyph_Transform(g, &halo_matrix, &start_halo); - if (rasterizer_ == HALO_RASTERIZER_FULL) + if (rasterizer_ == halo_rasterizer_enum::HALO_RASTERIZER_FULL) { stroker_->init(halo_radius); FT_Glyph_Stroke(&g, stroker_->get(), 1); @@ -479,7 +463,7 @@ void grid_text_renderer::render_halo_id(unsigned char* buffer, template grid_text_renderer::grid_text_renderer(pixmap_type& pixmap, composite_mode_e comp_op, double scale_factor) - : text_renderer(HALO_RASTERIZER_FAST, comp_op, src_over, scale_factor) + : text_renderer(halo_rasterizer_enum::HALO_RASTERIZER_FAST, comp_op, src_over, scale_factor) , pixmap_(pixmap) {} diff --git a/src/text/symbolizer_helpers.cpp b/src/text/symbolizer_helpers.cpp index 7cc145edb..6348dc763 100644 --- a/src/text/symbolizer_helpers.cpp +++ b/src/text/symbolizer_helpers.cpp @@ -277,11 +277,11 @@ void base_symbolizer_helper::initialize_points() const switch (how_placed) { - case LINE_PLACEMENT: + case label_placement_enum::LINE_PLACEMENT: point_placement_ = false; return; - case GRID_PLACEMENT: - case ALTERNATING_GRID_PLACEMENT: + case label_placement_enum::GRID_PLACEMENT: + case label_placement_enum::ALTERNATING_GRID_PLACEMENT: point_placement_ = true; // Points for grid placement are generated in text_symbolizer_helper // because base_symbolizer_helper doesn't have the vertex converter. @@ -296,7 +296,7 @@ void base_symbolizer_helper::initialize_points() const for (auto const& geom : geometries_to_process_) { - if (how_placed == VERTEX_PLACEMENT) + if (how_placed == label_placement_enum::VERTEX_PLACEMENT) { using apply_vertex_placement = detail::apply_vertex_placement>; apply_vertex_placement apply(points_, t_, prj_trans_); @@ -317,7 +317,7 @@ void base_symbolizer_helper::initialize_points() const geometry::line_string_vertex_adapter va(line); success = label::middle_point(va, label_x, label_y); } - else if (how_placed == POINT_PLACEMENT || type == geometry::geometry_types::Point) + else if (how_placed == label_placement_enum::POINT_PLACEMENT || type == geometry::geometry_types::Point) { geometry::point pt; if (geometry::centroid(geom, pt)) @@ -335,7 +335,7 @@ void base_symbolizer_helper::initialize_points() const using transform_group_type = geometry::strategy_group; transform_group_type transform_group(ps, vs); geometry::polygon tranformed_poly(geometry::transform(poly, transform_group)); - if (how_placed == INTERIOR_PLACEMENT) + if (how_placed == label_placement_enum::INTERIOR_PLACEMENT) { geometry::point pt; if (geometry::interior(tranformed_poly, scale_factor_, pt)) @@ -343,7 +343,7 @@ void base_symbolizer_helper::initialize_points() const points_.emplace_back(pt.x, pt.y); } } - else if (how_placed == POLYLABEL_PLACEMENT) + else if (how_placed == label_placement_enum::POLYLABEL_PLACEMENT) { double precision = geometry::polylabel_precision(tranformed_poly, scale_factor_); geometry::point pt; @@ -408,7 +408,8 @@ void text_symbolizer_helper::init_converters() if (clip) { label_placement_enum how_placed = text_props_->label_placement; - if (how_placed == GRID_PLACEMENT || how_placed == ALTERNATING_GRID_PLACEMENT) + if (how_placed == label_placement_enum::GRID_PLACEMENT || + how_placed == label_placement_enum::ALTERNATING_GRID_PLACEMENT) { converter_.template set(); } @@ -618,11 +619,11 @@ void text_symbolizer_helper::initialize_points() const { label_placement_enum how_placed = text_props_->label_placement; - if (how_placed == GRID_PLACEMENT) + if (how_placed == label_placement_enum::GRID_PLACEMENT) { initialize_grid_points(); } - else if (how_placed == ALTERNATING_GRID_PLACEMENT) + else if (how_placed == label_placement_enum::ALTERNATING_GRID_PLACEMENT) { initialize_grid_points(); } diff --git a/src/text/text_layout.cpp b/src/text/text_layout.cpp index e091e1429..3be71243a 100644 --- a/src/text/text_layout.cpp +++ b/src/text/text_layout.cpp @@ -466,32 +466,32 @@ void text_layout::shape_text(text_line& line) void text_layout::init_auto_alignment() { - if (valign_ == V_AUTO) + if (valign_ == vertical_alignment_enum::V_AUTO) { if (displacement_.y > 0.0) - valign_ = V_BOTTOM; + valign_ = vertical_alignment_enum::V_BOTTOM; else if (displacement_.y < 0.0) - valign_ = V_TOP; + valign_ = vertical_alignment_enum::V_TOP; else - valign_ = V_MIDDLE; + valign_ = vertical_alignment_enum::V_MIDDLE; } - if (halign_ == H_AUTO) + if (halign_ == horizontal_alignment_enum::H_AUTO) { if (displacement_.x > 0.0) - halign_ = H_RIGHT; + halign_ = horizontal_alignment_enum::H_RIGHT; else if (displacement_.x < 0.0) - halign_ = H_LEFT; + halign_ = horizontal_alignment_enum::H_LEFT; else - halign_ = H_MIDDLE; + halign_ = horizontal_alignment_enum::H_MIDDLE; } - if (jalign_ == J_AUTO) + if (jalign_ == justify_alignment_enum::J_AUTO) { if (displacement_.x > 0.0) - jalign_ = J_LEFT; + jalign_ = justify_alignment_enum::J_LEFT; else if (displacement_.x < 0.0) - jalign_ = J_RIGHT; + jalign_ = justify_alignment_enum::J_RIGHT; else - jalign_ = J_MIDDLE; + jalign_ = justify_alignment_enum::J_MIDDLE; } } @@ -499,20 +499,20 @@ pixel_position text_layout::alignment_offset() const { pixel_position result(0, 0); // if needed, adjust for desired vertical alignment - if (valign_ == V_TOP) + if (valign_ == vertical_alignment_enum::V_TOP) { result.y = -0.5 * height(); // move center up by 1/2 the total height } - else if (valign_ == V_BOTTOM) + else if (valign_ == vertical_alignment_enum::V_BOTTOM) { result.y = 0.5 * height(); // move center down by the 1/2 the total height } // set horizontal position to middle of text - if (halign_ == H_LEFT) + if (halign_ == horizontal_alignment_enum::H_LEFT) { result.x = -0.5 * width(); // move center left by 1/2 the string width } - else if (halign_ == H_RIGHT) + else if (halign_ == horizontal_alignment_enum::H_RIGHT) { result.x = 0.5 * width(); // move center right by 1/2 the string width } @@ -521,11 +521,11 @@ pixel_position text_layout::alignment_offset() const double text_layout::jalign_offset(double line_width) const { - if (jalign_ == J_MIDDLE) + if (jalign_ == justify_alignment_enum::J_MIDDLE) return -(line_width / 2.0); - if (jalign_ == J_LEFT) + if (jalign_ == justify_alignment_enum::J_LEFT) return -(width() / 2.0); - if (jalign_ == J_RIGHT) + if (jalign_ == justify_alignment_enum::J_RIGHT) return (width() / 2.0) - line_width; return 0; } diff --git a/src/text/text_properties.cpp b/src/text/text_properties.cpp index 633fb6e1d..bccd76b29 100644 --- a/src/text/text_properties.cpp +++ b/src/text/text_properties.cpp @@ -252,9 +252,9 @@ void text_symbolizer_properties::add_expressions(expression_set& output) const } text_layout_properties::text_layout_properties() - : halign(enumeration_wrapper(H_AUTO)) - , jalign(enumeration_wrapper(J_AUTO)) - , valign(enumeration_wrapper(V_AUTO)) + : halign(enumeration_wrapper(static_cast(horizontal_alignment_enum::H_AUTO))) + , jalign(enumeration_wrapper(static_cast(justify_alignment_enum::J_AUTO))) + , valign(enumeration_wrapper(static_cast(vertical_alignment_enum::V_AUTO))) {} void text_layout_properties::from_xml(xml_node const& node, fontset_map const& fontsets) @@ -343,7 +343,7 @@ format_properties::format_properties() , fill(color(0, 0, 0)) , halo_fill(color(255, 255, 255)) , halo_radius(0.0) - , text_transform(enumeration_wrapper(NONE)) + , text_transform(enumeration_wrapper(static_cast(text_transform_enum::NONE))) , ff_settings() {} diff --git a/src/tiff_reader.cpp b/src/tiff_reader.cpp index fb8b243a8..4446add71 100644 --- a/src/tiff_reader.cpp +++ b/src/tiff_reader.cpp @@ -104,8 +104,6 @@ int tiff_map_proc(thandle_t, tdata_t*, toff_t*) } } // namespace detail -namespace { - image_reader* create_tiff_reader(std::string const& filename) { #if defined(MAPNIK_MEMORY_MAPPED_FILE) @@ -120,9 +118,10 @@ image_reader* create_tiff_reader2(char const* data, std::size_t size) return new tiff_reader(data, size); } -const bool registered = register_image_reader("tiff", create_tiff_reader); -const bool registered2 = register_image_reader("tiff", create_tiff_reader2); - -} // namespace +void register_tiff_reader() +{ + const bool registered = register_image_reader("tiff", create_tiff_reader); + const bool registered2 = register_image_reader("tiff", create_tiff_reader2); +} } // namespace mapnik diff --git a/src/webp_io.cpp b/src/webp_io.cpp new file mode 100644 index 000000000..53b69bef3 --- /dev/null +++ b/src/webp_io.cpp @@ -0,0 +1,44 @@ +#include + +namespace mapnik { +std::string MAPNIK_DECL webp_encoding_error(WebPEncodingError error) +{ + std::string os; + switch (error) + { + case VP8_ENC_ERROR_OUT_OF_MEMORY: + os = "memory error allocating objects"; + break; + case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY: + os = "memory error while flushing bits"; + break; + case VP8_ENC_ERROR_NULL_PARAMETER: + os = "a pointer parameter is NULL"; + break; + case VP8_ENC_ERROR_INVALID_CONFIGURATION: + os = "configuration is invalid"; + break; + case VP8_ENC_ERROR_BAD_DIMENSION: + os = "picture has invalid width/height"; + break; + case VP8_ENC_ERROR_PARTITION0_OVERFLOW: + os = "partition is bigger than 512k"; + break; + case VP8_ENC_ERROR_PARTITION_OVERFLOW: + os = "partition is bigger than 16M"; + break; + case VP8_ENC_ERROR_BAD_WRITE: + os = "error while flushing bytes"; + break; + case VP8_ENC_ERROR_FILE_TOO_BIG: + os = "file is bigger than 4G"; + break; + default: + mapnik::util::to_string(os, error); + os = "unknown error (" + os + ")"; + break; + } + return os; +} + +} // namespace mapnik diff --git a/src/webp_reader.cpp b/src/webp_reader.cpp index fa85d6dfc..24b942525 100644 --- a/src/webp_reader.cpp +++ b/src/webp_reader.cpp @@ -110,7 +110,6 @@ class webp_reader : public image_reader void init(); }; -namespace { image_reader* create_webp_reader(char const* data, std::size_t size) { return new webp_reader(data, size); @@ -121,10 +120,11 @@ image_reader* create_webp_reader2(std::string const& filename) return new webp_reader(filename); } -const bool registered = register_image_reader("webp", create_webp_reader); -const bool registered2 = register_image_reader("webp", create_webp_reader2); - -} // namespace +void register_webp_reader() +{ + const bool registered = register_image_reader("webp", create_webp_reader); + const bool registered2 = register_image_reader("webp", create_webp_reader2); +} // ctor template diff --git a/src/well_known_srs.cpp b/src/well_known_srs.cpp index d8d30a2c8..2efb7a5d0 100644 --- a/src/well_known_srs.cpp +++ b/src/well_known_srs.cpp @@ -35,10 +35,11 @@ MAPNIK_DISABLE_WARNING_POP #include namespace mapnik { +constexpr const char MAPNIK_GEOGRAPHIC_PROJ_STR[10]{"epsg:4326"}; +extern std::string const MAPNIK_GEOGRAPHIC_PROJ = MAPNIK_GEOGRAPHIC_PROJ_STR; // wgs84 -extern std::string const MAPNIK_GEOGRAPHIC_PROJ = "epsg:4326"; // wgs84 - -extern std::string const MAPNIK_WEBMERCATOR_PROJ = "epsg:3857"; // webmercator +constexpr const char MAPNIK_WEBMERCATOR_PROJ_STR[10]{"epsg:3857"}; +extern std::string const MAPNIK_WEBMERCATOR_PROJ = MAPNIK_WEBMERCATOR_PROJ_STR; // webmercator static const char* well_known_srs_strings[] = {MAPNIK_GEOGRAPHIC_PROJ.c_str(), MAPNIK_WEBMERCATOR_PROJ.c_str(), ""}; @@ -46,11 +47,11 @@ boost::optional is_well_known_srs(std::string const& srs) { if (srs == MAPNIK_GEOGRAPHIC_PROJ) { - return boost::optional(mapnik::WGS_84); + return boost::optional(mapnik::well_known_srs_enum::WGS_84); } else if (srs == MAPNIK_WEBMERCATOR_PROJ) { - return boost::optional(mapnik::WEB_MERC); + return boost::optional(mapnik::well_known_srs_enum::WEB_MERC); } return boost::optional(); } @@ -69,7 +70,13 @@ boost::optional is_known_geographic(std::string const& srs) return boost::optional(); } -IMPLEMENT_ENUM(well_known_srs_e, well_known_srs_strings) +using well_known_srs_e_str = mapnik::detail::EnumStringT; +constexpr detail::EnumMapT well_known_srs_e_map{{ + well_known_srs_e_str{well_known_srs_enum::WGS_84, detail::mapnik_string_view{MAPNIK_GEOGRAPHIC_PROJ_STR}}, + well_known_srs_e_str{well_known_srs_enum::WEB_MERC, MAPNIK_WEBMERCATOR_PROJ_STR}, + well_known_srs_e_str{well_known_srs_enum::well_known_srs_enum_MAX, ""}, +}}; +IMPLEMENT_ENUM(well_known_srs_e, well_known_srs_enum) bool lonlat2merc(double& x, double& y) { diff --git a/src/wkt/CMakeLists.txt b/src/wkt/CMakeLists.txt index bd6332128..7507fd519 100644 --- a/src/wkt/CMakeLists.txt +++ b/src/wkt/CMakeLists.txt @@ -1,10 +1,9 @@ -add_library(wkt STATIC +target_sources(wkt PRIVATE geometry_to_wkt.cpp mapnik_wkt_generator_grammar.cpp wkt_factory.cpp wkt_grammar_x3.cpp ) -add_library(mapnik::wkt ALIAS wkt) target_include_directories(wkt PRIVATE ${MAPNIK_INCLUDE_PATH} @@ -18,16 +17,12 @@ target_link_libraries(wkt PRIVATE mapnik::core) set_target_properties(wkt PROPERTIES POSITION_INDEPENDENT_CODE ON - DEBUG_POSTFIX "${MAPNIK_DEBUG_POSTFIX}" OUTPUT_NAME "mapnikwkt" PREFIX "lib" IMPORT_PREFIX "lib" VERSION ${MAPNIK_VERSION} # see mapnik target for explanation SOVERSION ${MAPNIK_VERSION} - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" ) mapnik_install(wkt) diff --git a/src/xml_tree.cpp b/src/xml_tree.cpp index efce20e6d..2cc8d58f5 100644 --- a/src/xml_tree.cpp +++ b/src/xml_tree.cpp @@ -42,6 +42,7 @@ namespace mapnik { class boolean_type; + template struct name_trait { @@ -74,22 +75,26 @@ DEFINE_NAME_TRAIT(color, "color") DEFINE_NAME_TRAIT(expression_ptr, "expression_ptr") DEFINE_NAME_TRAIT(font_feature_settings, "font-feature-settings") -template -struct name_trait> +template (*F_LOOKUP)()> +struct name_trait> { - using Enum = enumeration; - + using Enum = mapnik::enumeration; static std::string name() { std::string value_list("one of ["); - for (unsigned i = 0; i < Enum::MAX; ++i) + const auto lookup{Enum::lookupMap()}; + for (auto it = lookup.cbegin(); it != lookup.cend(); it++) { - value_list += Enum::get_string(i); - if (i + 1 < Enum::MAX) + value_list += it->second; + if (std::next(it) != lookup.cend()) + { value_list += ", "; + } } - value_list += "]"; - + value_list += ']'; return value_list; } }; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 549357a9d..f275df53f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,5 @@ -find_package(Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS program_options) -find_package(PostgreSQL REQUIRED) +mapnik_find_package(Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS program_options) +mapnik_find_package(PostgreSQL REQUIRED) include(FetchContent) @@ -100,11 +100,7 @@ add_executable(mapnik-test-unit unit/vertex_adapter/transform_path_adapter.cpp unit/vertex_adapter/vertex_adapter.cpp ) -set_target_properties(mapnik-test-unit PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) + target_link_libraries(mapnik-test-unit PUBLIC Catch2::Catch2 mapnik::agg @@ -112,6 +108,7 @@ target_link_libraries(mapnik-test-unit PUBLIC mapnik::json mapnik::wkt PostgreSQL::PostgreSQL + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) # workaround since the "offical" include dir would be file(COPY catch_ext.hpp DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") @@ -119,58 +116,41 @@ file(COPY cleanup.hpp DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") target_include_directories(mapnik-test-unit PRIVATE "${Catch2_SOURCE_DIR}/single_include/catch2" "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") add_executable(agg_rasterizer_integer_overflow_test standalone/agg_rasterizer_integer_overflow_test.cpp) -set_target_properties(agg_rasterizer_integer_overflow_test PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) target_link_libraries(agg_rasterizer_integer_overflow_test PUBLIC Catch2::Catch2 mapnik::mapnik mapnik::agg mapnik::json + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) target_include_directories(agg_rasterizer_integer_overflow_test PRIVATE "${Catch2_SOURCE_DIR}/single_include/catch2" "${CMAKE_CURRENT_BINARY_DIR}") add_executable(datasource_registration_test standalone/datasource_registration_test.cpp) -set_target_properties(datasource_registration_test PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) target_link_libraries(datasource_registration_test PUBLIC Catch2::Catch2 mapnik::mapnik mapnik::agg + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) target_include_directories(datasource_registration_test PRIVATE "${Catch2_SOURCE_DIR}/single_include/catch2" "${CMAKE_CURRENT_BINARY_DIR}") add_executable(font_registration_test standalone/font_registration_test.cpp) -set_target_properties(font_registration_test PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) target_link_libraries(font_registration_test PUBLIC Catch2::Catch2 mapnik::mapnik mapnik::agg mapnik::json + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) target_include_directories(font_registration_test PRIVATE "${Catch2_SOURCE_DIR}/single_include/catch2" "${CMAKE_CURRENT_BINARY_DIR}") -#not workable since boost::filesystem native returns a wstring and the function taskes a std::string add_executable(map_xml_test standalone/map_xml_test.cpp) -set_target_properties(map_xml_test PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) target_link_libraries(map_xml_test PUBLIC Catch2::Catch2 mapnik::mapnik mapnik::agg mapnik::json + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) target_include_directories(map_xml_test PRIVATE "${Catch2_SOURCE_DIR}/single_include/catch2" "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/test/standalone/agg_rasterizer_integer_overflow_test.cpp b/test/standalone/agg_rasterizer_integer_overflow_test.cpp index 9ab9cfd95..05d3556f0 100644 --- a/test/standalone/agg_rasterizer_integer_overflow_test.cpp +++ b/test/standalone/agg_rasterizer_integer_overflow_test.cpp @@ -1,6 +1,7 @@ #define CATCH_CONFIG_MAIN #include "catch.hpp" +#include #include #include #include @@ -22,6 +23,7 @@ const std::string TEST_CASE("agg_rasterizer_integer_overflow") { + mapnik::setup(); SECTION("coordinates_do_not_overflow_and_polygon_is_rendered") { auto expected_color = mapnik::color("white"); diff --git a/test/standalone/datasource_registration_test.cpp b/test/standalone/datasource_registration_test.cpp index 9408aba9d..1492b8dad 100644 --- a/test/standalone/datasource_registration_test.cpp +++ b/test/standalone/datasource_registration_test.cpp @@ -1,6 +1,7 @@ #define CATCH_CONFIG_MAIN #include "catch.hpp" +#include #include #include #include @@ -11,6 +12,7 @@ TEST_CASE("datasource_cache") { + mapnik::setup(); SECTION("registration") { try diff --git a/test/standalone/font_registration_test.cpp b/test/standalone/font_registration_test.cpp index b651d525a..e2ce758a3 100644 --- a/test/standalone/font_registration_test.cpp +++ b/test/standalone/font_registration_test.cpp @@ -1,6 +1,7 @@ #define CATCH_CONFIG_MAIN #include "catch.hpp" +#include #include #include #include @@ -13,6 +14,7 @@ TEST_CASE("font") { + mapnik::setup(); SECTION("registration") { try diff --git a/test/standalone/map_xml_test.cpp b/test/standalone/map_xml_test.cpp index bf0e53253..71c37cc76 100644 --- a/test/standalone/map_xml_test.cpp +++ b/test/standalone/map_xml_test.cpp @@ -1,6 +1,7 @@ #define CATCH_CONFIG_MAIN #include "catch.hpp" +#include #include #include #include @@ -137,14 +138,17 @@ void load_map(mapnik::Map& m, bfs::path const& path) } } // anonymous namespace - +#ifndef MAPNIK_STATIC_PLUGINS const bool registered = mapnik::datasource_cache::instance().register_datasources((bfs::path("plugins") / "input").generic_string()); - +#endif TEST_CASE("map xml I/O") { + mapnik::setup(); +#ifndef MAPNIK_STATIC_PLUGINS // make sure plugins are loaded REQUIRE(registered); +#endif // make the tests silent since we intentially test error conditions that are noisy auto const severity = mapnik::logger::instance().get_severity(); diff --git a/test/unit/datasource/csv.cpp b/test/unit/datasource/csv.cpp index 93724d05e..d9734edca 100644 --- a/test/unit/datasource/csv.cpp +++ b/test/unit/datasource/csv.cpp @@ -85,17 +85,15 @@ mapnik::datasource_ptr get_csv_ds(std::string const& file_name, bool strict = tr TEST_CASE("csv") { using mapnik::util::from_u8string; - std::string csv_plugin("./plugins/input/csv.input"); - if (mapnik::util::exists(csv_plugin)) + + // check the CSV datasource is loaded + const bool have_csv_plugin = mapnik::datasource_cache::instance().plugin_registered("csv"); + if (have_csv_plugin) { // make the tests silent since we intentionally test error conditions that are noisy auto const severity = mapnik::logger::instance().get_severity(); mapnik::logger::instance().set_severity(mapnik::logger::none); - // check the CSV datasource is loaded - const std::vector plugin_names = mapnik::datasource_cache::instance().plugin_names(); - const bool have_csv_plugin = std::find(plugin_names.begin(), plugin_names.end(), "csv") != plugin_names.end(); - SECTION("CSV I/O errors") { std::string filename = "does_not_exist.csv"; @@ -125,83 +123,77 @@ TEST_CASE("csv") { for (auto create_index : {false, true}) { - if (have_csv_plugin) - { - std::vector broken; - add_csv_files("test/data/csv/fails", broken); - add_csv_files("test/data/csv/warns", broken); - broken.emplace_back("test/data/csv/fails/does_not_exist.csv"); + std::vector broken; + add_csv_files("test/data/csv/fails", broken); + add_csv_files("test/data/csv/warns", broken); + broken.emplace_back("test/data/csv/fails/does_not_exist.csv"); - for (auto const& path : broken) + for (auto const& path : broken) + { + bool require_fail = true; + if (create_index) { - bool require_fail = true; - if (create_index) + int ret = create_disk_index(path); + int ret_posix = (ret >> 8) & 0x000000ff; + INFO(ret); + INFO(ret_posix); + require_fail = (boost::iends_with(path, "feature_id_counting.csv")) ? false : true; + if (!require_fail) { - int ret = create_disk_index(path); - int ret_posix = (ret >> 8) & 0x000000ff; - INFO(ret); - INFO(ret_posix); - require_fail = (boost::iends_with(path, "feature_id_counting.csv")) ? false : true; - if (!require_fail) - { - REQUIRE(mapnik::util::exists(path + ".index")); - } - } - INFO(path); - if (require_fail) - { - REQUIRE_THROWS(get_csv_ds(path)); - } - else - { - CHECK(bool(get_csv_ds(path))); - } - if (mapnik::util::exists(path + ".index")) - { - CHECK(mapnik::util::remove(path + ".index")); + REQUIRE(mapnik::util::exists(path + ".index")); } } + INFO(path); + if (require_fail) + { + REQUIRE_THROWS(get_csv_ds(path)); + } + else + { + CHECK(bool(get_csv_ds(path))); + } + if (mapnik::util::exists(path + ".index")) + { + CHECK(mapnik::util::remove(path + ".index")); + } } } } // END SECTION SECTION("good files") { - if (have_csv_plugin) - { - std::vector good; - add_csv_files("test/data/csv", good); - add_csv_files("test/data/csv/warns", good); + std::vector good; + add_csv_files("test/data/csv", good); + add_csv_files("test/data/csv/warns", good); - for (auto const& path : good) + for (auto const& path : good) + { + // cleanup in the case of a failed previous run + if (mapnik::util::exists(path + ".index")) { - // cleanup in the case of a failed previous run + mapnik::util::remove(path + ".index"); + } + for (auto create_index : {false, true}) + { + if (create_index) + { + int ret = create_disk_index(path); + int ret_posix = (ret >> 8) & 0x000000ff; + INFO(ret); + INFO(ret_posix); + if (!boost::iends_with(path, + "more_headers_than_column_values.csv")) // mapnik-index won't create + // *.index for 0 features + { + CHECK(mapnik::util::exists(path + ".index")); + } + } + auto ds = get_csv_ds(path, false); + // require a non-null pointer returned + REQUIRE(bool(ds)); if (mapnik::util::exists(path + ".index")) { - mapnik::util::remove(path + ".index"); - } - for (auto create_index : {false, true}) - { - if (create_index) - { - int ret = create_disk_index(path); - int ret_posix = (ret >> 8) & 0x000000ff; - INFO(ret); - INFO(ret_posix); - if (!boost::iends_with(path, - "more_headers_than_column_values.csv")) // mapnik-index won't create - // *.index for 0 features - { - CHECK(mapnik::util::exists(path + ".index")); - } - } - auto ds = get_csv_ds(path, false); - // require a non-null pointer returned - REQUIRE(bool(ds)); - if (mapnik::util::exists(path + ".index")) - { - CHECK(mapnik::util::remove(path + ".index")); - } + CHECK(mapnik::util::remove(path + ".index")); } } } diff --git a/test/unit/datasource/gdal.cpp b/test/unit/datasource/gdal.cpp index e7d13b3dc..e83cd5a52 100644 --- a/test/unit/datasource/gdal.cpp +++ b/test/unit/datasource/gdal.cpp @@ -31,8 +31,8 @@ namespace { mapnik::datasource_ptr get_gdal_ds(std::string const& file_name, boost::optional band) { - std::string gdal_plugin("./plugins/input/gdal.input"); - if (!mapnik::util::exists(gdal_plugin)) + const bool have_gdal_plugin = mapnik::datasource_cache::instance().plugin_registered("gdal"); + if (!have_gdal_plugin) { return mapnik::datasource_ptr(); } diff --git a/test/unit/datasource/geobuf.cpp b/test/unit/datasource/geobuf.cpp index 82859851c..4d371ced6 100644 --- a/test/unit/datasource/geobuf.cpp +++ b/test/unit/datasource/geobuf.cpp @@ -37,8 +37,8 @@ TEST_CASE("Geobuf") { - std::string geobuf_plugin("./plugins/input/geobuf.input"); - if (mapnik::util::exists(geobuf_plugin)) + const bool have_geobuf_plugin = mapnik::datasource_cache::instance().plugin_registered("geobuf"); + if (have_geobuf_plugin) { SECTION("Point") { diff --git a/test/unit/datasource/geojson.cpp b/test/unit/datasource/geojson.cpp index 528c0263b..308e51cff 100644 --- a/test/unit/datasource/geojson.cpp +++ b/test/unit/datasource/geojson.cpp @@ -81,8 +81,8 @@ void iterate_over_features(mapnik::featureset_ptr features) TEST_CASE("geojson") { - std::string geojson_plugin("./plugins/input/geojson.input"); - if (mapnik::util::exists(geojson_plugin)) + const bool have_geojson_plugin = mapnik::datasource_cache::instance().plugin_registered("geojson"); + if (have_geojson_plugin) { SECTION("GeoJSON I/O errors") { diff --git a/test/unit/datasource/ogr.cpp b/test/unit/datasource/ogr.cpp index c6bfc8bb9..8441ecc55 100644 --- a/test/unit/datasource/ogr.cpp +++ b/test/unit/datasource/ogr.cpp @@ -28,12 +28,12 @@ #include #include #include -#include +#include TEST_CASE("ogr") { - std::string geojson_plugin("./plugins/input/ogr.input"); - if (mapnik::util::exists(geojson_plugin)) + const bool have_ogr_plugin = mapnik::datasource_cache::instance().plugin_registered("ogr"); + if (have_ogr_plugin) { SECTION("ogr point feature") { diff --git a/test/unit/datasource/shapeindex.cpp b/test/unit/datasource/shapeindex.cpp index 45aaa2334..76881235b 100644 --- a/test/unit/datasource/shapeindex.cpp +++ b/test/unit/datasource/shapeindex.cpp @@ -98,8 +98,8 @@ int create_shapefile_index(std::string const& filename, bool index_parts, bool s TEST_CASE("invalid shapeindex") { - std::string shape_plugin("./plugins/input/shape.input"); - if (mapnik::util::exists(shape_plugin)) + const bool have_shape_plugin = mapnik::datasource_cache::instance().plugin_registered("shape"); + if (have_shape_plugin) { SECTION("Invalid index") { @@ -141,8 +141,8 @@ TEST_CASE("invalid shapeindex") TEST_CASE("shapeindex") { - std::string shape_plugin("./plugins/input/shape.input"); - if (mapnik::util::exists(shape_plugin)) + const bool have_shape_plugin = mapnik::datasource_cache::instance().plugin_registered("shape"); + if (have_shape_plugin) { SECTION("Index") { diff --git a/test/unit/numerics/enumeration.cpp b/test/unit/numerics/enumeration.cpp index 1f425e8ea..f4ba2f3a3 100644 --- a/test/unit/numerics/enumeration.cpp +++ b/test/unit/numerics/enumeration.cpp @@ -6,7 +6,7 @@ TEST_CASE("enumeration") { - mapnik::line_cap_e e(mapnik::ROUND_CAP); + mapnik::line_cap_e e(mapnik::line_cap_enum::ROUND_CAP); CHECK(e.as_string() == "round"); // note: test the << operator, which calls `as_string` internally // is not used in mapnik, but kept for back compat diff --git a/test/unit/run.cpp b/test/unit/run.cpp index 8bf68870c..94836d7ed 100644 --- a/test/unit/run.cpp +++ b/test/unit/run.cpp @@ -2,6 +2,7 @@ #include "catch.hpp" #include +#include #include #include #include @@ -20,6 +21,7 @@ int main(int argc, char** argv) session.cli(cli); int result = session.applyCommandLine(argc, argv); + mapnik::setup(); if (!plugin_path.empty()) { if (!mapnik::util::exists(plugin_path)) diff --git a/test/unit/symbolizer/marker_placement_vertex_last.cpp b/test/unit/symbolizer/marker_placement_vertex_last.cpp index 418b449dc..1ee9f22b6 100644 --- a/test/unit/symbolizer/marker_placement_vertex_last.cpp +++ b/test/unit/symbolizer/marker_placement_vertex_last.cpp @@ -27,7 +27,7 @@ TEST_CASE("marker placement vertex last") 0, false, false, - DIRECTION_AUTO, + direction_enum::DIRECTION_AUTO, 1.0}; placement_type placement(va, detector, params); @@ -54,7 +54,7 @@ TEST_CASE("marker placement vertex last") 0, false, false, - DIRECTION_AUTO, + direction_enum::DIRECTION_AUTO, 1.0}; placement_type placement(va, detector, params); @@ -89,7 +89,7 @@ TEST_CASE("marker placement vertex last") 0, false, false, - DIRECTION_AUTO, + direction_enum::DIRECTION_AUTO, 1.0}; placement_type placement(va, detector, params); @@ -128,7 +128,7 @@ TEST_CASE("marker placement vertex last") 0, false, false, - DIRECTION_AUTO, + direction_enum::DIRECTION_AUTO, 1.0}; placement_type placement(va, detector, params); diff --git a/test/unit/symbolizer/markers_point_placement.cpp b/test/unit/symbolizer/markers_point_placement.cpp index 61f87a564..7c7cd807a 100644 --- a/test/unit/symbolizer/markers_point_placement.cpp +++ b/test/unit/symbolizer/markers_point_placement.cpp @@ -27,7 +27,7 @@ TEST_CASE("marker placement point") 0, false, false, - DIRECTION_AUTO, + direction_enum::DIRECTION_AUTO, 1.0}; placement_type placement(va, detector, params); @@ -54,7 +54,7 @@ TEST_CASE("marker placement point") 0, false, false, - DIRECTION_AUTO, + direction_enum::DIRECTION_AUTO, 1.0}; placement_type placement(va, detector, params); @@ -89,7 +89,7 @@ TEST_CASE("marker placement point") 0, false, false, - DIRECTION_AUTO, + direction_enum::DIRECTION_AUTO, 1.0}; placement_type placement(va, detector, params); @@ -124,7 +124,7 @@ TEST_CASE("marker placement point") 0, false, false, - DIRECTION_AUTO, + direction_enum::DIRECTION_AUTO, 1.0}; placement_type placement(va, detector, params); diff --git a/test/unit/symbolizer/symbolizer_test.cpp b/test/unit/symbolizer/symbolizer_test.cpp index 847409ea2..daad679f9 100644 --- a/test/unit/symbolizer/symbolizer_test.cpp +++ b/test/unit/symbolizer/symbolizer_test.cpp @@ -12,13 +12,13 @@ TEST_CASE("symbolizer") { try { - marker_multi_policy_enum policy_in = MARKER_WHOLE_MULTI; - REQUIRE(policy_in == MARKER_WHOLE_MULTI); + marker_multi_policy_enum policy_in = marker_multi_policy_enum::MARKER_WHOLE_MULTI; + REQUIRE(policy_in == marker_multi_policy_enum::MARKER_WHOLE_MULTI); markers_symbolizer sym; put(sym, keys::markers_multipolicy, policy_in); REQUIRE(sym.properties.count(keys::markers_multipolicy) == static_cast(1)); marker_multi_policy_enum policy_out = get(sym, keys::markers_multipolicy); - REQUIRE(policy_out == MARKER_WHOLE_MULTI); + REQUIRE(policy_out == marker_multi_policy_enum::MARKER_WHOLE_MULTI); } catch (std::exception const& ex) { diff --git a/test/visual/CMakeLists.txt b/test/visual/CMakeLists.txt index 3e7ee4919..0c0c306fc 100644 --- a/test/visual/CMakeLists.txt +++ b/test/visual/CMakeLists.txt @@ -4,17 +4,13 @@ add_executable(mapnik-test-visual runner.cpp run.cpp ) -set_target_properties(mapnik-test-visual PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib" -) target_link_libraries(mapnik-test-visual PRIVATE Catch2::Catch2 Boost::program_options Boost::filesystem mapnik::mapnik mapnik::agg + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) # needed for cleanup.hpp target_include_directories(mapnik-test-visual PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") diff --git a/test/visual/run.cpp b/test/visual/run.cpp index 846ef6d1c..a352f2c34 100644 --- a/test/visual/run.cpp +++ b/test/visual/run.cpp @@ -23,6 +23,7 @@ #include "runner.hpp" #include "config.hpp" +#include #include #include @@ -166,6 +167,7 @@ int main(int argc, char** argv) return 1; } + mapnik::setup(); #ifdef MAPNIK_LOG std::string log_level(vm["log"].as()); log_levels_map::const_iterator level_iter = log_levels.find(log_level); diff --git a/utils/geometry_to_wkb/CMakeLists.txt b/utils/geometry_to_wkb/CMakeLists.txt index 77cc6ea60..96d888178 100644 --- a/utils/geometry_to_wkb/CMakeLists.txt +++ b/utils/geometry_to_wkb/CMakeLists.txt @@ -1,9 +1,8 @@ add_executable(geometry_to_wkb main.cpp) -target_link_libraries(geometry_to_wkb PRIVATE mapnik::mapnik) - -set_target_properties(geometry_to_wkb PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" +target_link_libraries(geometry_to_wkb PRIVATE + mapnik::mapnik + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) mapnik_install_utility(geometry_to_wkb) diff --git a/utils/geometry_to_wkb/main.cpp b/utils/geometry_to_wkb/main.cpp index a31ffc93a..4cb2a3d1c 100644 --- a/utils/geometry_to_wkb/main.cpp +++ b/utils/geometry_to_wkb/main.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -40,6 +41,7 @@ int main(int argc, char** argv) std::cerr << "Geometry to WKB converter\n"; + mapnik::setup(); mapnik::datasource_cache::instance().register_datasources("/opt/mapnik/lib/mapnik/input/"); std::string filename(argv[1]); diff --git a/utils/mapnik-index/CMakeLists.txt b/utils/mapnik-index/CMakeLists.txt index 00c20c1e7..111ac934e 100644 --- a/utils/mapnik-index/CMakeLists.txt +++ b/utils/mapnik-index/CMakeLists.txt @@ -11,10 +11,7 @@ target_link_libraries(mapnik-index PRIVATE mapnik::json mapnik::wkt Boost::program_options -) - -set_target_properties(mapnik-index PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) mapnik_install_utility(mapnik-index) diff --git a/utils/mapnik-index/mapnik-index.cpp b/utils/mapnik-index/mapnik-index.cpp index b7956607a..c95e001a6 100644 --- a/utils/mapnik-index/mapnik-index.cpp +++ b/utils/mapnik-index/mapnik-index.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,7 @@ int main(int argc, char** argv) { // using namespace mapnik; namespace po = boost::program_options; + mapnik::setup(); bool verbose = false; bool validate_features = false; unsigned int depth = DEFAULT_DEPTH; diff --git a/utils/mapnik-render/CMakeLists.txt b/utils/mapnik-render/CMakeLists.txt index 49bda1eb1..d148e36e5 100644 --- a/utils/mapnik-render/CMakeLists.txt +++ b/utils/mapnik-render/CMakeLists.txt @@ -5,10 +5,7 @@ add_executable(mapnik-render mapnik-render.cpp) target_link_libraries(mapnik-render PRIVATE mapnik::mapnik Boost::program_options -) - -set_target_properties(mapnik-render PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) mapnik_install_utility(mapnik-render) diff --git a/utils/mapnik-render/mapnik-render.cpp b/utils/mapnik-render/mapnik-render.cpp index 02afc8e0f..1a05a7795 100644 --- a/utils/mapnik-render/mapnik-render.cpp +++ b/utils/mapnik-render/mapnik-render.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -21,6 +22,8 @@ int main(int argc, char** argv) { namespace po = boost::program_options; + mapnik::setup(); + bool verbose = false; bool auto_open = false; int return_value = 0; diff --git a/utils/ogrindex/CMakeLists.txt b/utils/ogrindex/CMakeLists.txt index e3d18f098..fe9593137 100644 --- a/utils/ogrindex/CMakeLists.txt +++ b/utils/ogrindex/CMakeLists.txt @@ -1,9 +1,8 @@ add_executable(ogrindex ogrindex.cpp) -target_link_libraries(ogrindex PRIVATE mapnik::mapnik) - -set_target_properties(ogrindex PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" +target_link_libraries(ogrindex PRIVATE + mapnik::mapnik + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) mapnik_install_utility(ogrindex) diff --git a/utils/ogrindex/ogrindex.cpp b/utils/ogrindex/ogrindex.cpp index 0fe3978b4..5c955837f 100644 --- a/utils/ogrindex/ogrindex.cpp +++ b/utils/ogrindex/ogrindex.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -60,6 +61,7 @@ int main(int argc, char** argv) double ratio = DEFAULT_RATIO; vector ogr_files; + mapnik::setup(); try { po::options_description desc("ogrindex utility"); diff --git a/utils/pgsql2sqlite/CMakeLists.txt b/utils/pgsql2sqlite/CMakeLists.txt index 116dd9c35..3657b31ae 100644 --- a/utils/pgsql2sqlite/CMakeLists.txt +++ b/utils/pgsql2sqlite/CMakeLists.txt @@ -1,6 +1,6 @@ -find_package(Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS program_options) -find_package(SQLite3 REQUIRED) -find_package(PostgreSQL REQUIRED) +mapnik_find_package(Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS program_options) +mapnik_find_package(SQLite3 REQUIRED) +mapnik_find_package(PostgreSQL REQUIRED) add_executable(pgsql2sqlite main.cpp @@ -13,10 +13,7 @@ target_link_libraries(pgsql2sqlite PRIVATE PostgreSQL::PostgreSQL Boost::program_options mapnik::mapnik -) - -set_target_properties(pgsql2sqlite PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) mapnik_install_utility(pgsql2sqlite) diff --git a/utils/pgsql2sqlite/main.cpp b/utils/pgsql2sqlite/main.cpp index c87692090..9ab101485 100644 --- a/utils/pgsql2sqlite/main.cpp +++ b/utils/pgsql2sqlite/main.cpp @@ -24,6 +24,7 @@ #include "pgsql2sqlite.hpp" #include #include +#include #include "connection_manager.hpp" #include @@ -46,6 +47,7 @@ int main(int argc, char** argv) po::options_description desc("Postgresql/PostGIS to SQLite3 converter\n Options"); std::string usage = "usage: pgsql2sqlite --dbname db --table planet_osm_line --file osm.sqlite --query \"select * " "from planet_osm_line\""; + mapnik::setup(); try { // clang-format off diff --git a/utils/shapeindex/CMakeLists.txt b/utils/shapeindex/CMakeLists.txt index 520b11d4d..e0e1d93d9 100644 --- a/utils/shapeindex/CMakeLists.txt +++ b/utils/shapeindex/CMakeLists.txt @@ -8,10 +8,7 @@ target_include_directories(shapeindex PRIVATE ../../plugins/input/shape) target_link_libraries(shapeindex PRIVATE Boost::program_options mapnik::mapnik -) - -set_target_properties(shapeindex PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) mapnik_install_utility(shapeindex) diff --git a/utils/shapeindex/shapeindex.cpp b/utils/shapeindex/shapeindex.cpp index f310a572c..6602257e1 100644 --- a/utils/shapeindex/shapeindex.cpp +++ b/utils/shapeindex/shapeindex.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,7 @@ int main(int argc, char** argv) double ratio = DEFAULT_RATIO; std::vector shape_files; + mapnik::setup(); try { po::options_description desc("shapeindex utility"); diff --git a/utils/svg2png/CMakeLists.txt b/utils/svg2png/CMakeLists.txt index 7d6e4b657..e2afca177 100644 --- a/utils/svg2png/CMakeLists.txt +++ b/utils/svg2png/CMakeLists.txt @@ -8,10 +8,7 @@ target_link_libraries(svg2png PRIVATE Boost::program_options mapnik::mapnik mapnik::agg -) - -set_target_properties(svg2png PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}" + ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?) ) mapnik_install_utility(svg2png) diff --git a/utils/svg2png/svg2png.cpp b/utils/svg2png/svg2png.cpp index 34aaacee8..7a9d378a1 100644 --- a/utils/svg2png/svg2png.cpp +++ b/utils/svg2png/svg2png.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -179,6 +180,7 @@ int main(int argc, char** argv) bool strict = false; int status = 0; std::vector svg_files; + mapnik::setup(); mapnik::logger::instance().set_severity(mapnik::logger::error); double scale_factor; double opacity;