-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
114 lines (96 loc) · 4.13 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
cmake_minimum_required (VERSION 3.2)
project (booleval)
option (BOOLEVAL_BUILD_TESTS "Build tests" ON)
option (BOOLEVAL_BUILD_EXAMPLES "Build examples" ON)
option (BOOLEVAL_BUILD_BENCHMARK "Build benchmark" OFF)
# Compile in release mode by default
if (NOT CMAKE_BUILD_TYPE)
message (STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
set (CMAKE_BUILD_TYPE RelWithDebInfo)
else (NOT CMAKE_BUILD_TYPE)
message (STATUS "Using specified '${CMAKE_BUILD_TYPE}' build type.")
endif (NOT CMAKE_BUILD_TYPE)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
# Compilation flags
if (MSVC)
# Don't always use Wall, since VC's /Wall is too verbose.
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /O2")
else ()
option (BOOLEVAL_ENABLE_COVERAGE "Enable code coverage reporting" OFF)
if (BOOLEVAL_ENABLE_COVERAGE)
message (STATUS "Code coverage reporting is enabled.")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wpedantic -O0 --coverage")
else ()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wpedantic -O3")
endif ()
endif ()
# Build output checks
option (LIBBOOLEVAL_BUILD_SHARED "Build libbooleval as a shared library." ON)
if (LIBBOOLEVAL_BUILD_SHARED)
message (
STATUS
"Build will generate a shared library. "
"Use LIBBOOLEVAL_BUILD_SHARED=0 to perform a static build"
)
set (LIBBOOLEVAL_TYPE SHARED)
# Automatically create a .def file with all symbols found
# in the input .obj files for a SHARED library on Windows.
set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
else (LIBBOOLEVAL_BUILD_SHARED)
message (STATUS "Build will generate a static library.")
set (LIBBOOLEVAL_TYPE STATIC)
add_definitions ("-DBOOLEVAL_STATIC=1")
endif (LIBBOOLEVAL_BUILD_SHARED)
# The version number
set (BOOLEVAL_VERSION_MAJOR 1)
set (BOOLEVAL_VERSION_MINOR 1)
set (BOOLEVAL_VERSION_PATCH 0)
set (LIBBOOLEVAL_VERSION "${BOOLEVAL_VERSION_MAJOR}.${BOOLEVAL_VERSION_MINOR}")
include (ExternalProject)
if (NOT CMAKE_INSTALL_LIBDIR)
set (CMAKE_INSTALL_LIBDIR lib)
endif ()
if (BOOLEVAL_BUILD_EXAMPLES)
message (STATUS "Examples have been enabled")
add_subdirectory (examples)
endif ()
if (BOOLEVAL_BUILD_TESTS)
# Only include googletest if the git submodule has been fetched
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt")
# Enable tests and add the test directory
message (STATUS "Tests have been enabled")
set (GOOGLETEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
set (GOOGLETEST_INCLUDE ${GOOGLETEST_ROOT}/googletest/include)
set (GOOGLETEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest)
set (GOOGLETEST_LIBRARY ${GOOGLETEST_BINARY_DIR}/googletest)
if (${LIBBOOLEVAL_TYPE} MATCHES SHARED)
set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif (${LIBBOOLEVAL_TYPE} MATCHES SHARED)
enable_testing ()
add_subdirectory (googletest)
add_subdirectory (tests)
else ()
message (STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it")
endif ()
endif ()
if (BOOLEVAL_BUILD_BENCHMARK)
# Only include googlebench if the git submodule has been fetched
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googlebench/CMakeLists.txt")
# Enable benchmark and add the benchmark directory
message (STATUS "Benchmark has been enabled")
set (GOOGLEBENCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/googlebench)
set (GOOGLEBENCH_INCLUDE ${GOOGLEBENCH_ROOT}/googlebench/include)
set (GOOGLEBENCH_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/googlebench)
set (GOOGLEBENCH_LIBRARY ${GOOGLEBENCH_BINARY_DIR}/googlebench)
set (BENCHMARK_ENABLE_GTEST_TESTS OFF)
if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DNDEBUG)
endif()
add_subdirectory (googlebench)
add_subdirectory (benchmark)
else ()
message (STATUS "googlebench git submodule is absent. Run `git submodule init && git submodule update` to get it")
endif ()
endif ()