Skip to content

Commit 1031379

Browse files
committed
Change to gtest.
1 parent fe537d9 commit 1031379

File tree

208 files changed

+80322
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+80322
-104
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ mason_packages
1515
.toolchain
1616
.mason
1717
local.env
18-
xcode-project
18+
xcode-project
19+
build
20+
.*.sw*

CMakeLists.txt

Lines changed: 17 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,29 @@
11
cmake_minimum_required(VERSION 3.8)
22
project(delaunator VERSION 0.4.0)
3-
set (CMAKE_CXX_STANDARD 14)
4-
set(CMAKE_CXX_STANDARD_REQUIRED on)
5-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
63

7-
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mason.cmake)
4+
set(ROOT_DIR ${PROJECT_SOURCE_DIR})
85

9-
option(WERROR "Add -Werror flag to build (turns warnings into errors)" ON)
10-
option(BENCHMARK_BIG_O "Calculate Big O in benchmark" OFF)
11-
option(BENCHMARK_100M "Run against 100M points" OFF)
12-
option(BENCHMARK_10M "Run against 100M points" OFF)
6+
#
7+
# Must be first.
8+
#
9+
include(${ROOT_DIR}/cmake/common.cmake NO_POLICY_SCOPE)
1310

14-
# configure optimization
15-
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
16-
set(OPTIMIZATION_FLAGS "-O0 -DDEBUG")
17-
message("-- Configuring debug build")
18-
else()
19-
set(OPTIMIZATION_FLAGS "-O3 -DNDEBUG")
20-
message("-- Configuring release build")
21-
endif()
11+
include(CTest)
12+
include(FeatureSummary)
2213

23-
# Enable extra warnings to adhere to https://github.com/mapbox/cpp/issues/37
24-
set(DESIRED_WARNINGS "-Wall -Wextra -Wconversion -Wunreachable-code -Wuninitialized -pedantic-errors -Wold-style-cast -Wno-error=unused-variable -Wshadow -Wfloat-equal -Weffc++")
25-
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
26-
set(DESIRED_WARNINGS "${DESIRED_WARNINGS} -Wmost")
27-
endif()
14+
include(${D_CMAKE_DIR}/options.cmake)
15+
include(${D_CMAKE_DIR}/gtest.cmake)
2816

29-
# Note: -D_GLIBCXX_USE_CXX11_ABI=0 is needed to support mason packages that are precompiled libs
30-
# Currently we only depend on a header only library, but this will help avoid issues when more libs are added via mason
31-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZATION_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0 ${DESIRED_WARNINGS}")
17+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${D_BIN_DIR})
3218

33-
if (WERROR)
34-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
35-
endif()
19+
add_library(delaunator include/delaunator.cpp)
20+
d_target_compile_settings(delaunator)
3621

37-
# mason_use is a mason function within the mason.cmake file and provides ready-to-go vars, like "STATIC_LIBS" and "INCLUDE_DIRS"
38-
mason_use(catch VERSION 2.4.0 HEADER_ONLY)
39-
include_directories(SYSTEM ${MASON_PACKAGE_catch_INCLUDE_DIRS})
40-
41-
mason_use(rapidjson VERSION 1.1.0 HEADER_ONLY)
42-
include_directories(SYSTEM ${MASON_PACKAGE_rapidjson_INCLUDE_DIRS})
43-
44-
mason_use(benchmark VERSION 1.2.0)
45-
include_directories(SYSTEM ${MASON_PACKAGE_benchmark_INCLUDE_DIRS})
46-
47-
include_directories("${PROJECT_SOURCE_DIR}/include")
48-
49-
file(GLOB TEST_SOURCES test/*.cpp)
50-
set(TEST_SOURCES ${TEST_SOURCES} include/delaunator.cpp)
51-
add_executable(unit-tests ${TEST_SOURCES})
52-
53-
file(GLOB TEST_SOURCES test-header-only/*.cpp)
54-
add_executable(header-only-unit-tests ${TEST_SOURCES})
55-
56-
# libbenchmark.a supports threads and therefore needs pthread support
57-
find_package(Threads REQUIRED)
58-
file(GLOB BENCH_SOURCES bench/*.cpp)
59-
set(BENCH_SOURCES ${BENCH_SOURCES} include/delaunator.cpp)
60-
add_executable(bench-tests ${BENCH_SOURCES})
61-
if(BENCHMARK_BIG_O)
62-
message("-- BENCHMARK_BIG_O=1")
63-
target_compile_definitions(bench-tests PUBLIC BENCHMARK_BIG_O=1)
64-
endif()
65-
if(BENCHMARK_100M)
66-
message("-- BENCHMARK_100M=1")
67-
target_compile_definitions(bench-tests PUBLIC BENCHMARK_100M=1)
68-
endif()
69-
if(BENCHMARK_10M)
70-
message("-- BENCHMARK_10M=1")
71-
target_compile_definitions(bench-tests PUBLIC BENCHMARK_10M=1)
72-
endif()
22+
add_subdirectory(test)
7323

7424
#examples
75-
add_executable(triangulate-geojson examples/triangulate_geojson.cpp include/delaunator.cpp)
76-
add_executable(basic examples/basic.cpp include/delaunator.cpp)
77-
78-
79-
# link benchmark static library to the bench-tests binary so the bench tests know where to find the benchmark impl code
80-
target_link_libraries(bench-tests ${MASON_PACKAGE_benchmark_STATIC_LIBS} ${CMAKE_THREAD_LIBS_INIT})
25+
#add_executable(triangulate-geojson examples/triangulate_geojson.cpp include/delaunator.cpp)
26+
#add_executable(basic examples/basic.cpp include/delaunator.cpp)
8127

82-
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
83-
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
28+
#set(CPACK_PROJECT_NAME ${PROJECT_NAME})
29+
#set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})

cmake/bench.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
file(GLOB BENCH_SOURCE bench/*.cpp)
2+
3+
option(BENCHMARK_BIG_O "Calculate Big O in benchmark" OFF)
4+
option(BENCHMARK_100M "Run against 100M points" OFF)
5+
option(BENCHMARK_10M "Run against 100M points" OFF)
6+
set(BENCH_SOURCES ${BENCH_SOURCES} include/delaunator.cpp)
7+
add_executable(bench-tests ${BENCH_SOURCES})
8+
if(BENCHMARK_BIG_O)
9+
message("-- BENCHMARK_BIG_O=1")
10+
target_compile_definitions(bench-tests PUBLIC BENCHMARK_BIG_O=1)
11+
endif()
12+
if(BENCHMARK_100M)
13+
message("-- BENCHMARK_100M=1")
14+
target_compile_definitions(bench-tests PUBLIC BENCHMARK_100M=1)
15+
endif()
16+
if(BENCHMARK_10M)
17+
message("-- BENCHMARK_10M=1")
18+
target_compile_definitions(bench-tests PUBLIC BENCHMARK_10M=1)
19+
endif()

cmake/common.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# To reduce typing.
3+
#
4+
set(CDIR "${CMAKE_CURRENT_LIST_DIR}")
5+
6+
#
7+
# This must be first.
8+
#
9+
include(${CDIR}/directories.cmake)
10+
11+
#
12+
# This must come before macros, but I don't understand why the policies
13+
# apply to the macros rather than the invocation of the macros.
14+
#
15+
#include(${CDIR}/policies.cmake NO_POLICY_SCOPE)
16+
include(${CDIR}/compiler_options.cmake)

cmake/compiler_options.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(CMAKE_CXX_STANDARD 11)
2+
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
3+
if (WIN32)
4+
include (${CMAKE_CURRENT_LIST_DIR}/win32_compiler_options.cmake)
5+
else()
6+
include (${CMAKE_CURRENT_LIST_DIR}/unix_compiler_options.cmake)
7+
endif()

cmake/directories.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if(NOT ROOT_DIR)
2+
message(FATAL_ERROR "ROOT_DIR must be set in top-level CMakeLists.txt")
3+
endif()
4+
set(D_SRC_DIR ${ROOT_DIR}/include)
5+
set(D_INCLUDE_DIR ${ROOT_DIR}/include)
6+
set(D_BIN_DIR ${CMAKE_BINARY_DIR}/bin)
7+
set(D_CMAKE_DIR ${ROOT_DIR}/cmake)
8+
set(D_GTEST_DIR ${ROOT_DIR}/gtest)
9+
set(D_GTEST_INCLUDE_DIR ${ROOT_DIR}/gtest/include)
10+

cmake/gtest.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if (MSVC)
2+
# Since tests link CRT dynamically (/MD[d]), require gtest to
3+
#link dynamically too (default is /MT[d])
4+
option(gtest_force_shared_crt "Always use shared Visual C++ run-time DLL" ON)
5+
endif()
6+
7+
set(GOOGLETEST_VERSION 1.10.0)
8+
add_subdirectory(gtest)
9+

cmake/options.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
option(WITH_TESTS
2+
"Choose if delaunator tests should be built" TRUE)
3+
add_feature_info("Unit tests" WITH_TESTS "Delaunator unit tests")

cmake/test.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
file(GLOB TEST_SOURCES ${DEL_TEST_DIR}/*.cpp)
2+
add_executable(unit-tests ${TEST_SOURCES})
3+
4+
file(GLOB TEST_SOURCES test-header-only/*.cpp)
5+
add_executable(header-only-unit-tests ${TEST_SOURCES})

cmake/unix_compiler_options.cmake

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function(d_target_compile_settings target)
2+
if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
3+
#
4+
# VERSION_GREATER_EQUAL doesn't come until cmake 3.7
5+
#
6+
if (NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 7.0)
7+
target_compile_options(${target} PRIVATE
8+
-Wno-implicit-fallthrough
9+
-Wno-int-in-bool-context
10+
-Wno-dangling-else
11+
-Wno-noexcept-type
12+
)
13+
endif()
14+
set(PDAL_COMPILER_GCC 1)
15+
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
16+
set(PDAL_COMPILER_CLANG 1)
17+
else()
18+
message(FATAL_ERROR "Unsupported C++ compiler")
19+
endif()
20+
21+
target_compile_options(${target} PRIVATE
22+
${PDAL_CXX_STANDARD}
23+
-Wall
24+
-Wextra
25+
-Wpointer-arith
26+
-Wcast-align
27+
-Wcast-qual
28+
-Wno-error=parentheses
29+
-Wno-error=cast-qual
30+
-Wredundant-decls
31+
32+
-Wno-unused-parameter
33+
-Wno-unused-variable
34+
-Wno-long-long
35+
-Wno-unknown-pragmas
36+
-Wno-deprecated-declarations
37+
)
38+
if (PDAL_COMPILER_CLANG)
39+
target_compile_options(${target} PRIVATE
40+
-Wno-unknown-warning-option
41+
)
42+
endif()
43+
endfunction()

0 commit comments

Comments
 (0)