ext/h3/src/CMakeLists.txt in h3-3.6.2 vs ext/h3/src/CMakeLists.txt in h3-3.7.1

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright 2017-2019 Uber Technologies, Inc. +# Copyright 2017-2020 Uber Technologies, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # @@ -13,10 +13,11 @@ # limitations under the License. cmake_minimum_required(VERSION 3.1) set(H3_PREFIX "" CACHE STRING "Prefix for exported symbols") +set(H3_ALLOC_PREFIX "" CACHE STRING "Prefix for allocation functions") # Needed due to CMP0042 set(CMAKE_MACOSX_RPATH 1) # H3 doesn't export selected symbols right now set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) @@ -32,11 +33,12 @@ option(BUILD_BENCHMARKS "Build benchmarking applications." ON) option(BUILD_FILTERS "Build filter applications." ON) option(BUILD_GENERATORS "Build code generation applications." ON) if(WIN32) - set(SHELL PowerShell -Command) + # Use bash (usually from Git for Windows) for piping results + set(SHELL bash -c) set(EXECUTABLE_OUTPUT_PATH bin) set(LIBRARY_OUTPUT_PATH bin) else() set(SHELL sh -c) @@ -105,10 +107,11 @@ src/h3lib/lib/bbox.c src/h3lib/lib/polygon.c src/h3lib/lib/h3Index.c src/h3lib/lib/vec2d.c src/h3lib/lib/vec3d.c + src/h3lib/lib/vertex.c src/h3lib/lib/linkedGeo.c src/h3lib/lib/localij.c src/h3lib/lib/geoCoord.c src/h3lib/lib/h3UniEdge.c src/h3lib/lib/mathExtensions.c @@ -141,11 +144,11 @@ src/apps/filters/kRing.c src/apps/filters/hexRange.c src/apps/testapps/testVertexGraph.c src/apps/testapps/testCompact.c src/apps/testapps/testPolyfill.c - src/apps/testapps/testPolyfill_GH136.c + src/apps/testapps/testPolyfillReported.c src/apps/testapps/testPentagonIndexes.c src/apps/testapps/testKRing.c src/apps/testapps/testH3ToGeoBoundary.c src/apps/testapps/testH3ToParent.c src/apps/testapps/testH3Index.c @@ -160,76 +163,102 @@ src/apps/testapps/testH3GetFaces.c src/apps/testapps/testGeoCoord.c src/apps/testapps/testHexRing.c src/apps/testapps/testH3SetToVertexGraph.c src/apps/testapps/testBBox.c + src/apps/testapps/testVertex.c src/apps/testapps/testPolygon.c src/apps/testapps/testVec2d.c src/apps/testapps/testVec3d.c src/apps/testapps/testH3UniEdge.c + src/apps/testapps/testH3UniEdgeExhaustive.c src/apps/testapps/testLinkedGeo.c src/apps/testapps/mkRandGeo.c src/apps/testapps/testH3Api.c src/apps/testapps/testH3SetToLinkedGeo.c src/apps/testapps/testH3ToLocalIj.c src/apps/testapps/testH3ToLocalIjExhaustive.c src/apps/testapps/testH3Distance.c src/apps/testapps/testH3DistanceExhaustive.c src/apps/testapps/testH3Line.c src/apps/testapps/testH3LineExhaustive.c + src/apps/testapps/testH3CellArea.c + src/apps/testapps/testH3CellAreaExhaustive.c src/apps/testapps/testCoordIj.c src/apps/testapps/testCoordIjk.c + src/apps/testapps/testH3Memory.c src/apps/miscapps/h3ToGeoBoundaryHier.c src/apps/miscapps/h3ToGeoHier.c src/apps/miscapps/generateBaseCellNeighbors.c + src/apps/miscapps/generatePentagonDirectionFaces.c src/apps/miscapps/generateNumHexagons.c src/apps/miscapps/generateFaceCenterPoint.c src/apps/miscapps/h3ToHier.c src/apps/benchmarks/benchmarkPolyfill.c src/apps/benchmarks/benchmarkPolygon.c src/apps/benchmarks/benchmarkH3SetToLinkedGeo.c src/apps/benchmarks/benchmarkKRing.c src/apps/benchmarks/benchmarkH3Line.c + src/apps/benchmarks/benchmarkH3UniEdge.c src/apps/benchmarks/benchmarkH3Api.c) set(ALL_SOURCE_FILES ${LIB_SOURCE_FILES} ${APP_SOURCE_FILES} ${OTHER_SOURCE_FILES}) set(UNCONFIGURED_API_HEADER src/h3lib/include/h3api.h.in) set(CONFIGURED_API_HEADER src/h3lib/include/h3api.h) configure_file(${UNCONFIGURED_API_HEADER} ${CONFIGURED_API_HEADER}) -set(INSTALL_TARGETS h3) +set(INSTALL_TARGETS) -# Build the H3 library -add_library(h3 ${LIB_SOURCE_FILES} ${CONFIGURED_API_HEADER}) +function(add_h3_library name h3_alloc_prefix_override) + add_library(${name} ${LIB_SOURCE_FILES} ${CONFIGURED_API_HEADER}) -target_compile_options(h3 PRIVATE ${H3_COMPILE_FLAGS}) -target_link_libraries(h3 PRIVATE ${H3_LINK_FLAGS}) + target_compile_options(${name} PRIVATE ${H3_COMPILE_FLAGS}) + target_link_libraries(${name} PRIVATE ${H3_LINK_FLAGS}) -find_library(M_LIB m) -if(M_LIB) - target_link_libraries(h3 PUBLIC ${M_LIB}) -endif() + find_library(M_LIB m) + if(M_LIB) + target_link_libraries(${name} PUBLIC ${M_LIB}) + endif() -if(BUILD_SHARED_LIBS) - set_target_properties(h3 PROPERTIES SOVERSION ${H3_SOVERSION}) -endif() + if(BUILD_SHARED_LIBS) + set_target_properties(${name} PROPERTIES SOVERSION ${H3_SOVERSION}) + endif() -target_compile_definitions(h3 PUBLIC H3_PREFIX=${H3_PREFIX}) -if(have_alloca) - target_compile_definitions(h3 PUBLIC H3_HAVE_ALLOCA) -endif() -if(have_vla) - target_compile_definitions(h3 PUBLIC H3_HAVE_VLA) -endif() -target_include_directories(h3 PUBLIC - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/h3lib/include> - $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/h3lib/include>) + target_compile_definitions(${name} PUBLIC H3_PREFIX=${H3_PREFIX}) + set(has_alloc_prefix NO) + if(h3_alloc_prefix_override) + set(has_alloc_prefix YES) + target_compile_definitions(${name} PUBLIC H3_ALLOC_PREFIX=${h3_alloc_prefix_override}) + elseif(H3_ALLOC_PREFIX) + set(has_alloc_prefix YES) + target_compile_definitions(${name} PUBLIC H3_ALLOC_PREFIX=${H3_ALLOC_PREFIX}) + endif() + # Mac OSX defaults to not looking up undefined symbols dynamically, + # so enable that explicitly. + if(has_alloc_prefix AND APPLE) + target_link_libraries(${name} PRIVATE "-undefined dynamic_lookup") + endif() + if(have_alloca) + target_compile_definitions(${name} PUBLIC H3_HAVE_ALLOCA) + endif() + if(have_vla) + target_compile_definitions(${name} PUBLIC H3_HAVE_VLA) + endif() + target_include_directories(${name} PUBLIC + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/h3lib/include> + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/h3lib/include>) +endfunction() + +# Build the H3 library +add_h3_library(h3 "") + # Automatic code formatting -find_program(CLANG_FORMAT_PATH clang-format) +# Give preference to clang-format-9 +find_program(CLANG_FORMAT_PATH NAMES clang-format-9 clang-format) cmake_dependent_option( ENABLE_FORMAT "Enable running clang-format before compiling" ON "CLANG_FORMAT_PATH" OFF) if(ENABLE_FORMAT) # Format @@ -364,10 +393,11 @@ endif() if(BUILD_GENERATORS) # Code generation add_h3_executable(generateBaseCellNeighbors src/apps/miscapps/generateBaseCellNeighbors.c ${APP_SOURCE_FILES}) + add_h3_executable(generatePentagonDirectionFaces src/apps/miscapps/generatePentagonDirectionFaces.c ${APP_SOURCE_FILES}) add_h3_executable(generateNumHexagons src/apps/miscapps/generateNumHexagons.c ${APP_SOURCE_FILES}) add_h3_executable(generateFaceCenterPoint src/apps/miscapps/generateFaceCenterPoint.c ${APP_SOURCE_FILES}) # Miscellaneous testing applications - generating random data add_h3_executable(mkRandGeo src/apps/testapps/mkRandGeo.c ${APP_SOURCE_FILES}) @@ -397,10 +427,41 @@ COMMAND lcov --rc lcov_branch_coverage=1 --directory '${CMAKE_CURRENT_BINARY_DIR}' --zerocounters COMMENT "Zeroing counters" ) endif() + add_h3_library(h3WithTestAllocators test_prefix_) + + macro(add_h3_memory_test name srcfile) + # Like other test code, but these need to be linked against + # a different copy of the H3 library which has known intercepted + # allocator functions. + add_executable(${ARGV} ${APP_SOURCE_FILES}) + + if(TARGET ${name}) + target_link_libraries(${name} PUBLIC h3WithTestAllocators) + target_include_directories(${name} PUBLIC + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/apps/applib/include>) + target_compile_options(${name} PRIVATE ${H3_COMPILE_FLAGS}) + target_link_libraries(${name} PRIVATE ${H3_LINK_FLAGS}) + endif() + + math(EXPR test_number "${test_number}+1") + + add_test(NAME ${name}_test${test_number} COMMAND ${TEST_WRAPPER} "$<TARGET_FILE:${name}>") + + if(ENABLE_COVERAGE) + add_custom_target(${name}_coverage${test_number} + COMMAND ${name} > /dev/null + COMMENT "Running ${name}_coverage${test_number}" + ) + + add_dependencies(coverage ${name}_coverage${test_number}) + add_dependencies(${name}_coverage${test_number} clean-coverage) + endif() + endmacro() + macro(add_h3_test_common name srcfile) # need to actually make the test target if(NOT TARGET ${name}) add_h3_executable(${name} ${srcfile} ${APP_SOURCE_FILES}) endif() @@ -424,15 +485,11 @@ endmacro() macro(add_h3_test_with_file name srcfile argfile) add_h3_test_common(${name} ${srcfile}) # add a special command (so we don't need to read the test file from the test program) - if(WIN32) - set(dump_command "Get-Content") - else() - set(dump_command "cat") - endif() + set(dump_command "cat") add_test(NAME ${name}_test${test_number} COMMAND ${SHELL} "${dump_command} ${argfile} | ${TEST_WRAPPER_STR} $<TARGET_FILE:${name}>") if(PRINT_TEST_FILES) @@ -469,11 +526,10 @@ add_dependencies(${name}_coverage${test_number} clean-coverage) endif() endmacro() # Add each individual test - file(GLOB all_centers tests/inputfiles/bc*centers.txt) foreach(file ${all_centers}) add_h3_test_with_file(testH3ToGeo src/apps/testapps/testH3ToGeo.c ${file}) endforeach() @@ -505,21 +561,23 @@ add_h3_test(testH3Api src/apps/testapps/testH3Api.c) add_h3_test(testH3SetToLinkedGeo src/apps/testapps/testH3SetToLinkedGeo.c) add_h3_test(testH3SetToVertexGraph src/apps/testapps/testH3SetToVertexGraph.c) add_h3_test(testLinkedGeo src/apps/testapps/testLinkedGeo.c) add_h3_test(testPolyfill src/apps/testapps/testPolyfill.c) - add_h3_test(testPolyfill_GH136 src/apps/testapps/testPolyfill_GH136.c) + add_h3_test(testPolyfillReported src/apps/testapps/testPolyfillReported.c) add_h3_test(testVertexGraph src/apps/testapps/testVertexGraph.c) add_h3_test(testH3UniEdge src/apps/testapps/testH3UniEdge.c) add_h3_test(testGeoCoord src/apps/testapps/testGeoCoord.c) add_h3_test(testBBox src/apps/testapps/testBBox.c) + add_h3_test(testVertex src/apps/testapps/testVertex.c) add_h3_test(testPolygon src/apps/testapps/testPolygon.c) add_h3_test(testVec2d src/apps/testapps/testVec2d.c) add_h3_test(testVec3d src/apps/testapps/testVec3d.c) add_h3_test(testH3ToLocalIj src/apps/testapps/testH3ToLocalIj.c) add_h3_test(testH3Distance src/apps/testapps/testH3Distance.c) add_h3_test(testH3Line src/apps/testapps/testH3Line.c) + add_h3_test(testH3CellArea src/apps/testapps/testH3CellArea.c) add_h3_test(testCoordIj src/apps/testapps/testCoordIj.c) add_h3_test(testCoordIjk src/apps/testapps/testCoordIjk.c) add_h3_test(testBaseCells src/apps/testapps/testBaseCells.c) add_h3_test(testPentagonIndexes src/apps/testapps/testPentagonIndexes.c) @@ -527,14 +585,18 @@ add_h3_test_with_arg(testH3NeighborRotations src/apps/testapps/testH3NeighborRotations.c 1) add_h3_test_with_arg(testH3NeighborRotations src/apps/testapps/testH3NeighborRotations.c 2) # The "Exhaustive" part of the test name is used by the test-fast to exclude these files. # test-fast exists so that Travis CI can run Valgrind on tests without taking a very long time. + add_h3_test(testH3UniEdgeExhaustive src/apps/testapps/testH3UniEdgeExhaustive.c) add_h3_test(testH3ToLocalIjExhaustive src/apps/testapps/testH3ToLocalIjExhaustive.c) add_h3_test(testH3LineExhaustive src/apps/testapps/testH3LineExhaustive.c) add_h3_test(testH3DistanceExhaustive src/apps/testapps/testH3DistanceExhaustive.c) + add_h3_test(testH3CellAreaExhaustive src/apps/testapps/testH3CellAreaExhaustive.c) + add_h3_memory_test(testH3Memory src/apps/testapps/testH3Memory.c) + add_custom_target(test-fast COMMAND ctest -E Exhaustive) endif() if(BUILD_BENCHMARKS) # Benchmarks @@ -547,10 +609,11 @@ endmacro() add_h3_benchmark(benchmarkH3Api src/apps/benchmarks/benchmarkH3Api.c) add_h3_benchmark(benchmarkKRing src/apps/benchmarks/benchmarkKRing.c) add_h3_benchmark(benchmarkH3Line src/apps/benchmarks/benchmarkH3Line.c) + add_h3_benchmark(benchmarkH3UniEdge src/apps/benchmarks/benchmarkH3UniEdge.c) add_h3_benchmark(benchmarkH3SetToLinkedGeo src/apps/benchmarks/benchmarkH3SetToLinkedGeo.c) add_h3_benchmark(benchmarkPolyfill src/apps/benchmarks/benchmarkPolyfill.c) add_h3_benchmark(benchmarkPolygon src/apps/benchmarks/benchmarkPolygon.c) endif() @@ -569,10 +632,14 @@ set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") set(namespace "${PROJECT_NAME}::") +# TODO: Unclear why this is needed to get the libh3 Debian package to build correctly +# with shared libraries. +set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "libh3") + # Include module with fuction 'write_basic_package_version_file' include(CMakePackageConfigHelpers) # Configure '<PROJECT-NAME>ConfigVersion.cmake' # Use: @@ -597,10 +664,18 @@ # * headers can be included by C++ code `#include <h3/h3api.h>` # Installing the library and filters system-wide. install( TARGETS ${INSTALL_TARGETS} EXPORT "${TARGETS_EXPORT_NAME}" + RUNTIME DESTINATION "bin" + COMPONENT h3 +) + +install( + TARGETS h3 + EXPORT "${TARGETS_EXPORT_NAME}" + COMPONENT libh3 LIBRARY DESTINATION "lib" ARCHIVE DESTINATION "lib" RUNTIME DESTINATION "bin" INCLUDES DESTINATION "${include_install_dir}" ) @@ -609,22 +684,47 @@ # * src/h3lib/include/h3api.h -> <prefix>/include/h3/h3api.h # Only the h3api.h header is needed by applications using H3. install( FILES "${CMAKE_CURRENT_BINARY_DIR}/src/h3lib/include/h3api.h" DESTINATION "${include_install_dir}/h3" + COMPONENT libh3-dev ) # Config # * <prefix>/lib/cmake/h3/h3Config.cmake # * <prefix>/lib/cmake/h3/h3ConfigVersion.cmake install( FILES "${project_config}" "${version_config}" DESTINATION "${config_install_dir}" + COMPONENT libh3-dev ) # Config # * <prefix>/lib/cmake/h3/h3Targets.cmake install( EXPORT "${TARGETS_EXPORT_NAME}" NAMESPACE "${namespace}" DESTINATION "${config_install_dir}" + COMPONENT libh3-dev ) + +# Debian package build +set(CPACK_DEB_COMPONENT_INSTALL 1) +set(CPACK_GENERATOR "DEB") +set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT") +# set(CPACK_DEBIAN_PACKAGE_MAINTAINER "TEST PACKAGE") # Required +set(CPACK_PACKAGE_HOMEPAGE_URL "https://www.h3geo.org") +set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE") +set(CPACK_DEBIAN_LIBH3_PACKAGE_DEPENDS "libc6 (>= 2.27)") +set(CPACK_DEBIAN_LIBH3-DEV_PACKAGE_DEPENDS "libh3 (= ${H3_VERSION})") +set(CPACK_DEBIAN_H3_PACKAGE_DEPENDS "libc6 (>= 2.27), libh3 (= ${H3_VERSION})") +set(CPACK_DEBIAN_LIBH3_DESCRIPTION "Library files for the H3 hexagonal discrete global grid system.") +set(CPACK_DEBIAN_LIBH3-DEV_DESCRIPTION "Development files and headers for the H3 hexagonal discrete global grid system.") +set(CPACK_DEBIAN_H3_DESCRIPTION "UNIX style filter (command line) tools for the H3 hexagonal discrete global grid system.") +set(CPACK_DEBIAN_LIBH3_PACKAGE_NAME "libh3") +set(CPACK_DEBIAN_LIBH3-DEV_PACKAGE_NAME "libh3-dev") +set(CPACK_DEBIAN_H3_PACKAGE_NAME "h3") +set(CPACK_DEBIAN_LIBH3_PACKAGE_SECTION "libs") +set(CPACK_DEBIAN_LIBH3-DEV_PACKAGE_SECTION "libdevel") +set(CPACK_DEBIAN_H3_PACKAGE_SECTION "science") + +include(CPack)