From 56a35455450aa63a2e9842b761c42d77cdfca9e9 Mon Sep 17 00:00:00 2001 From: Cameron Sheikholeslami Date: Wed, 18 Dec 2019 11:03:25 -0600 Subject: [PATCH] Making more modern cmake, including install target for easier inclusion into other projects. Also making the mason stuff optional as source data is either unavailable or requires proper credentials. --- CMakeLists.txt | 111 +++++++++++++++++++++++++------------- delaunatorConfig.cmake.in | 5 ++ 2 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 delaunatorConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index c7c8f72..c3925e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ option(WERROR "Add -Werror flag to build (turns warnings into errors)" ON) option(BENCHMARK_BIG_O "Calculate Big O in benchmark" OFF) option(BENCHMARK_100M "Run against 100M points" OFF) option(BENCHMARK_10M "Run against 100M points" OFF) +option(BUILD_BENCH_TEST "Use Mason" OFF) # configure optimization if (CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -20,6 +21,10 @@ else() message("-- Configuring release build") endif() +# Set relative install directories +set(INSTALL_INCLUDE_DIR "include") +set(INSTALL_CMAKE_DIR "lib${LIB_SUFFIX}/cmake/delaunator") + # Enable extra warnings to adhere to https://github.com/mapbox/cpp/issues/37 set(DESIRED_WARNINGS "-Wall -Wextra -Wconversion -Wunreachable-code -Wuninitialized -pedantic-errors -Wold-style-cast -Wno-error=unused-variable -Wshadow -Wfloat-equal -Weffc++") if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") @@ -34,45 +39,77 @@ if (WERROR) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") endif() -# mason_use is a mason function within the mason.cmake file and provides ready-to-go vars, like "STATIC_LIBS" and "INCLUDE_DIRS" -mason_use(catch VERSION 2.4.0 HEADER_ONLY) -include_directories(SYSTEM ${MASON_PACKAGE_catch_INCLUDE_DIRS}) - -mason_use(rapidjson VERSION 1.1.0 HEADER_ONLY) -include_directories(SYSTEM ${MASON_PACKAGE_rapidjson_INCLUDE_DIRS}) - -mason_use(benchmark VERSION 1.2.0) -include_directories(SYSTEM ${MASON_PACKAGE_benchmark_INCLUDE_DIRS}) - -include_directories("${PROJECT_SOURCE_DIR}/include") - -file(GLOB TEST_SOURCES test/*.cpp) -add_executable(unit-tests ${TEST_SOURCES}) - -# libbenchmark.a supports threads and therefore needs pthread support -find_package(Threads REQUIRED) -file(GLOB BENCH_SOURCES bench/*.cpp) -add_executable(bench-tests ${BENCH_SOURCES}) -if(BENCHMARK_BIG_O) - message("-- BENCHMARK_BIG_O=1") - target_compile_definitions(bench-tests PUBLIC BENCHMARK_BIG_O=1) +if (BUILD_BENCH_TEST) + # mason_use is a mason function within the mason.cmake file and provides ready-to-go vars, like "STATIC_LIBS" and "INCLUDE_DIRS" + mason_use(catch VERSION 2.4.0 HEADER_ONLY) + include_directories(SYSTEM ${MASON_PACKAGE_catch_INCLUDE_DIRS}) + + mason_use(rapidjson VERSION 1.1.0 HEADER_ONLY) + include_directories(SYSTEM ${MASON_PACKAGE_rapidjson_INCLUDE_DIRS}) + + mason_use(benchmark VERSION 1.2.0) + include_directories(SYSTEM ${MASON_PACKAGE_benchmark_INCLUDE_DIRS}) + include_directories("${PROJECT_SOURCE_DIR}/include") + + file(GLOB TEST_SOURCES test/*.cpp) + add_executable(unit-tests ${TEST_SOURCES}) + + # libbenchmark.a supports threads and therefore needs pthread support + find_package(Threads REQUIRED) + file(GLOB BENCH_SOURCES bench/*.cpp) + add_executable(bench-tests ${BENCH_SOURCES}) + if(BENCHMARK_BIG_O) + message("-- BENCHMARK_BIG_O=1") + target_compile_definitions(bench-tests PUBLIC BENCHMARK_BIG_O=1) + endif() + if(BENCHMARK_100M) + message("-- BENCHMARK_100M=1") + target_compile_definitions(bench-tests PUBLIC BENCHMARK_100M=1) + endif() + if(BENCHMARK_10M) + message("-- BENCHMARK_10M=1") + target_compile_definitions(bench-tests PUBLIC BENCHMARK_10M=1) + endif() + + #examples + add_executable(triangulate-geojson examples/triangulate_geojson.cpp) + add_executable(basic examples/basic.cpp) + + # link benchmark static library to the bench-tests binary so the bench tests know where to find the benchmark impl code + target_link_libraries(bench-tests ${MASON_PACKAGE_benchmark_STATIC_LIBS} ${CMAKE_THREAD_LIBS_INIT}) endif() -if(BENCHMARK_100M) - message("-- BENCHMARK_100M=1") - target_compile_definitions(bench-tests PUBLIC BENCHMARK_100M=1) -endif() -if(BENCHMARK_10M) - message("-- BENCHMARK_10M=1") - target_compile_definitions(bench-tests PUBLIC BENCHMARK_10M=1) -endif() - -#examples -add_executable(triangulate-geojson examples/triangulate_geojson.cpp) -add_executable(basic examples/basic.cpp) - -# link benchmark static library to the bench-tests binary so the bench tests know where to find the benchmark impl code -target_link_libraries(bench-tests ${MASON_PACKAGE_benchmark_STATIC_LIBS} ${CMAKE_THREAD_LIBS_INIT}) +add_library(delaunator INTERFACE) +target_include_directories(delaunator + INTERFACE + $ + $) + +install(TARGETS delaunator + EXPORT delaunatorTargets) + +add_library(delaunator::delaunator ALIAS delaunator) + + # Generate the cmake config and cmake config-version file: +include(CMakePackageConfigHelpers) + +configure_package_config_file( + "${delaunator_SOURCE_DIR}/delaunatorConfig.cmake.in" + "${delaunator_BINARY_DIR}/delaunatorConfig.cmake" + INSTALL_DESTINATION ${INSTALL_CMAKE_DIR} + PATH_VARS INSTALL_INCLUDE_DIR) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) + +install(EXPORT delaunatorTargets + NAMESPACE delaunator:: + DESTINATION "${INSTALL_CMAKE_DIR}") + +install( + FILES "${delaunator_BINARY_DIR}/delaunatorConfig.cmake" + DESTINATION "${INSTALL_CMAKE_DIR}" ) + +install( + FILES "${delaunator_SOURCE_DIR}/include/delaunator.hpp" + DESTINATION "${INSTALL_INCLUDE_DIR}" ) diff --git a/delaunatorConfig.cmake.in b/delaunatorConfig.cmake.in new file mode 100644 index 0000000..7c3dc1e --- /dev/null +++ b/delaunatorConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/delaunatorTargets.cmake") + +set_and_check(delaunator_INCLUDE_DIR "@PACKAGE_INSTALL_INCLUDE_DIR@") \ No newline at end of file