|
1 | | -cmake_minimum_required(VERSION 3.0.0) |
2 | | -project(delaunator VERSION 0.1.0) |
| 1 | +cmake_minimum_required(VERSION 3.8) |
| 2 | +project(delaunator VERSION 0.2.0) |
3 | 3 | set (CMAKE_CXX_STANDARD 14) |
4 | | -if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/includes") |
5 | | - execute_process(COMMAND bash "-c" "(cd ${CMAKE_CURRENT_SOURCE_DIR} && ./fetch-includes.sh)") |
| 4 | +set(CMAKE_CXX_STANDARD_REQUIRED on) |
| 5 | +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 6 | + |
| 7 | +include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mason.cmake) |
| 8 | + |
| 9 | +option(WERROR "Add -Werror flag to build (turns warnings into errors)" ON) |
| 10 | + |
| 11 | +# configure optimization |
| 12 | +if (CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 13 | + set(OPTIMIZATION_FLAGS "-O0 -DDEBUG") |
| 14 | + message("-- Configuring debug build") |
| 15 | +else() |
| 16 | + set(OPTIMIZATION_FLAGS "-O3 -DNDEBUG") |
| 17 | + message("-- Configuring release build") |
| 18 | +endif() |
| 19 | + |
| 20 | +# Enable extra warnings to adhere to https://github.com/mapbox/cpp/issues/37 |
| 21 | +set(DESIRED_WARNINGS "-Wall -Wextra -Wconversion -Wunreachable-code -Wuninitialized -pedantic-errors -Wold-style-cast -Wno-error=unused-variable -Wshadow -Wfloat-equal -Weffc++") |
| 22 | +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 23 | + set(DESIRED_WARNINGS "${DESIRED_WARNINGS} -Wmost") |
6 | 24 | endif() |
7 | 25 |
|
8 | | -#delaunator |
9 | | -add_library(delaunator src/delaunator.cpp) |
10 | | -target_include_directories (delaunator PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/rapidjson/include") |
11 | | -target_include_directories (delaunator PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/prettyprint") |
| 26 | +# Note: -D_GLIBCXX_USE_CXX11_ABI=0 is needed to support mason packages that are precompiled libs |
| 27 | +# Currently we only depend on a header only library, but this will help avoid issues when more libs are added via mason |
| 28 | +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZATION_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0 ${DESIRED_WARNINGS}") |
| 29 | + |
| 30 | +if (WERROR) |
| 31 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") |
| 32 | +endif() |
| 33 | + |
| 34 | +# mason_use is a mason function within the mason.cmake file and provides ready-to-go vars, like "STATIC_LIBS" and "INCLUDE_DIRS" |
| 35 | +mason_use(catch VERSION 2.4.0 HEADER_ONLY) |
| 36 | +include_directories(SYSTEM ${MASON_PACKAGE_catch_INCLUDE_DIRS}) |
| 37 | + |
| 38 | +mason_use(rapidjson VERSION 1.1.0 HEADER_ONLY) |
| 39 | +include_directories(SYSTEM ${MASON_PACKAGE_rapidjson_INCLUDE_DIRS}) |
| 40 | + |
| 41 | +mason_use(benchmark VERSION 1.2.0) |
| 42 | +include_directories(SYSTEM ${MASON_PACKAGE_benchmark_INCLUDE_DIRS}) |
12 | 43 |
|
13 | | -#delaunator |
14 | | -add_library(json-helpers src/json-helpers.cpp) |
15 | | -target_include_directories (json-helpers PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/rapidjson/include") |
| 44 | +include_directories("${PROJECT_SOURCE_DIR}/include") |
16 | 45 |
|
17 | | -#delaunator-test |
18 | | -add_executable(delaunator-test src/delaunator-test.cpp) |
19 | | -target_link_libraries(delaunator-test delaunator) |
20 | | -target_include_directories (delaunator-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/catch/single_include/catch2") |
21 | | -target_link_libraries(delaunator-test json-helpers) |
| 46 | +file(GLOB TEST_SOURCES test/*.cpp) |
| 47 | +add_executable(unit-tests ${TEST_SOURCES}) |
22 | 48 |
|
23 | | -#benchmark |
24 | | -add_executable(benchmark src/benchmark.cpp) |
25 | | -target_link_libraries(benchmark delaunator) |
26 | | -target_link_libraries(benchmark json-helpers) |
| 49 | +# libbenchmark.a supports threads and therefore needs pthread support |
| 50 | +find_package(Threads REQUIRED) |
| 51 | +file(GLOB BENCH_SOURCES bench/*.cpp) |
| 52 | +add_executable(bench-tests ${BENCH_SOURCES}) |
27 | 53 |
|
| 54 | +#examples |
| 55 | +add_executable(triangulate-geojson examples/triangulate_geojson.cpp) |
| 56 | +add_executable(basic examples/basic.cpp) |
28 | 57 |
|
29 | | -#triangulate |
30 | | -add_executable(triangulate src/triangulate.cpp) |
31 | | -target_include_directories (triangulate PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/rapidjson/include") |
32 | | -target_include_directories (triangulate PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/prettyprint") |
33 | | -target_link_libraries(triangulate delaunator) |
34 | | -target_link_libraries(triangulate json-helpers) |
35 | 58 |
|
| 59 | +# link benchmark static library to the bench-tests binary so the bench tests know where to find the benchmark impl code |
| 60 | +target_link_libraries(bench-tests ${MASON_PACKAGE_benchmark_STATIC_LIBS} ${CMAKE_THREAD_LIBS_INIT}) |
36 | 61 |
|
37 | 62 | set(CPACK_PROJECT_NAME ${PROJECT_NAME}) |
38 | 63 | set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) |
0 commit comments