-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
134 lines (116 loc) · 3.87 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.12)
project(
kassert
DESCRIPTION "Assertion library for KaMPIng"
LANGUAGES CXX
)
# include guard to prevent duplicate targets when including this project as a subdirectory
if (TARGET kassert)
return()
endif ()
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# folder support for IDEs
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# this has to be enabled in the main CMakeLists file
include(CTest)
# find Doxygen
find_package(Doxygen)
if (DOXYGEN_FOUND)
if (DOXYGEN_VERSION VERSION_LESS "1.9.2")
message(
WARNING
"Doxygen must be version 1.9.2 or newer. Documentation may not be displayed correctly and CI may not pass even if checks pass locally."
)
endif ()
add_custom_target(
docs
COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_SOURCE_DIR}/docs/Doxyfile
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Generating Documentation"
VERBATIM
)
else ()
message(STATUS "Doxygen not found, not building docs")
endif ()
endif ()
# Require out-of-source builds
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
if (EXISTS "${LOC_PATH}")
message(
FATAL_ERROR
"You cannot build in a source directory (or any directory with a CMakeLists.txt file). Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles."
)
endif ()
option(KASSERT_WARNINGS_ARE_ERRORS OFF)
option(KASSERT_BUILD_TESTS OFF)
add_subdirectory(extern)
# Dummy target without any compile definitions -- used for unit tests only
add_library(kassert_base INTERFACE)
target_include_directories(kassert_base INTERFACE include)
# set C++ standard to C++17
target_compile_features(kassert_base INTERFACE cxx_std_17)
list(
APPEND
KASSERT_WARNING_FLAGS
"-Wall"
"-Wextra"
"-Wconversion"
"-Wnon-virtual-dtor"
"-Woverloaded-virtual"
"-Wshadow"
"-Wsign-conversion"
"-Wundef"
"-Wunreachable-code"
"-Wunused"
)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
list(
APPEND
KASSERT_WARNING_FLAGS
"-Wcast-align"
"-Wnull-dereference"
"-Wpedantic"
"-Wextra-semi"
"-Wno-gnu-zero-variadic-macro-arguments"
)
endif ()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
list(
APPEND
KASSERT_WARNING_FLAGS
"-Wcast-align"
"-Wnull-dereference"
"-Wpedantic"
"-Wnoexcept"
"-Wsuggest-attribute=const"
"-Wsuggest-attribute=noreturn"
"-Wsuggest-override"
)
endif ()
# OFF by default.
if (KASSERT_WARNINGS_ARE_ERRORS)
list(APPEND KASSERT_WARNING_FLAGS "-Werror")
endif ()
# Actual library target with compile definitions
add_library(kassert INTERFACE)
target_link_libraries(kassert INTERFACE kassert_base)
if (NOT DEFINED KASSERT_EXCEPTION_MODE OR KASSERT_EXCEPTION_MODE EQUAL 1)
message(STATUS "Exception mode enabled.")
target_compile_definitions(kassert INTERFACE -DKASSERT_EXCEPTION_MODE)
else ()
message(STATUS "Exception mode disabled.")
endif ()
# The assertion level controls which assertions are enabled during runtime. Assertion levels can be set explicitly using
# the -DKASSERT_ASSERTION_LEVEL=... flag.
if (NOT DEFINED KASSERT_ASSERTION_LEVEL)
message(WARNING "Assertion level no set. Default to level 0.")
set(KASSERT_ASSERTION_LEVEL 0)
else ()
message(STATUS "Assertion level set to ${KASSERT_ASSERTION_LEVEL}.")
endif ()
target_compile_definitions(kassert INTERFACE -DKASSERT_ASSERTION_LEVEL=${KASSERT_ASSERTION_LEVEL})
add_library(kassert::kassert ALIAS kassert)
# Testing and examples are only built if this is the main project or if KASSERT_BUILD_TESTS is set (OFF by default)
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR KASSERT_BUILD_TESTS)
add_subdirectory(tests)
endif ()