-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
134 lines (100 loc) · 3.4 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
cmake_minimum_required(VERSION 3.14)
# Detect if the project is the root or being bundled.
if(NOT DEFINED PROJECT_NAME)
set(IS_ROOT_PROJECT ON)
endif()
# Project information.
project(
dcmt-cpp
VERSION 1.0.0
LANGUAGES CXX)
# CPM (https://github.com/TheLartians/CPM.cmake).
set(CPM_DOWNLOAD_VERSION 0.27.3)
include(cmake/get_cpm.cmake)
# Root project settings.
if(IS_ROOT_PROJECT)
include(CTest)
set(PROJECT_CONFIG_LIB "${PROJECT_NAME}_private_config")
add_library(${PROJECT_CONFIG_LIB} INTERFACE)
# Additional compiler flags for testing.
set(CMAKE_CXX_EXTENSIONS OFF)
include(CheckCXXCompilerFlag)
macro(TRY_CXX_COMPILER_FLAG flag var)
check_cxx_compiler_flag(${flag} ${var})
if(${var})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endif()
endmacro()
function(check_cxx_compiler_and_linker_flag flag var)
set(separated_flags ${flag})
# cmake-lint: disable=E1120
separate_arguments(separated_flags)
# cmake-lint: disable=C0103
set(CMAKE_REQUIRED_LINK_OPTIONS ${separated_flags})
check_cxx_compiler_flag(${flag} ${var})
endfunction()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
try_cxx_compiler_flag("-Wall -Wextra" CXX_HAS_WARN_ALL_AND_EXTRA_FLAG)
try_cxx_compiler_flag("-Wshadow" CXX_HAS_WARN_SHADOW_FLAG)
endif()
# Benchmarking.
option(BUILD_BENCHMARKING "Build benchmarks" OFF)
# Document generation.
option(BUILD_DOCUMENTS "Build documents" ON)
if(BUILD_DOCUMENTS)
find_package(Doxygen)
if(DOXYGEN_FOUND)
add_subdirectory(docs)
else()
message(WARNING "Building documents requires Doxygen")
endif()
endif()
# Code coverage.
option(USE_CODE_COVERAGE "Enable coverage reporting" OFF)
if(USE_CODE_COVERAGE)
check_cxx_compiler_and_linker_flag("-O0 -g -coverage" CXX_HAS_COVERAGE_FLAG)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
if(CXX_HAS_COVERAGE_FLAG)
target_compile_options(${PROJECT_CONFIG_LIB} INTERFACE -O0 -g -coverage)
target_link_options(${PROJECT_CONFIG_LIB} INTERFACE -coverage)
else()
message(WARNING "Coverage reporting is not supported by the compiler")
endif()
else()
message(WARNING "Coverage reporting requires GCC or LLVM/Clang")
endif()
endif()
# Compiler sanitizers.
option(USE_SANITIZER "Enable compiler sanitizers" OFF)
if(USE_SANITIZER)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
check_cxx_compiler_and_linker_flag(
"-O0 -g -fsanitize=address,undefined -fno-omit-frame-pointer"
CXX_HAS_SANITIZER_FLAG)
if(CXX_HAS_SANITIZER_FLAG)
target_compile_options(
${PROJECT_CONFIG_LIB} INTERFACE -O0 -g -fsanitize=address,undefined
-fno-omit-frame-pointer)
target_link_options(${PROJECT_CONFIG_LIB} INTERFACE
-fsanitize=address,undefined)
else()
message(WARNING "Compiler sanitizers are not supported by the compiler")
endif()
else()
message(WARNING "Compiler sanitizers require GCC or LLVM/Clang")
endif()
endif()
# Clang-Tidy.
option(USE_CLANG_TIDY "Enable Clang-Tidy" OFF)
if(USE_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY clang-tidy)
endif()
endif()
# Source code.
add_subdirectory(src)
if(IS_ROOT_PROJECT AND BUILD_TESTING)
add_subdirectory(tests EXCLUDE_FROM_ALL)
endif()
if(IS_ROOT_PROJECT AND BUILD_BENCHMARKING)
add_subdirectory(benches)
endif()