Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
191 lines (150 loc) · 6.04 KB
/
Copy pathCMakeLists.txt
File metadata and controls
191 lines (150 loc) · 6.04 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
cmake_minimum_required(VERSION 3.4.3 FATAL_ERROR)
project(cpp-tutor)
set(CMAKE_CXX_STANDARD 14 CACHE STRING "")
# APPEND COMPILER FLAGS
# =====================
# Note that warnings are _expected_:
# * the code deliberately doesn't follow the best coding practices, but
# instead focuses on highlighting corner cases which indeed trigger warnings
# * as part of the tutorial, compiler diagnostics (and indeed warnings) are
# used to identify problematic code
# For this reason we don't want to suppress or fix any warninga and we don't
# use `-Werror` (or /WX for MSVC). Also, don't use `-Wall` as that would
# enable too many checks.
set(cpp-tutor_COMPILER_OPTIONS_CLANG -fcolor-diagnostics)
set(cpp-tutor_COMPILER_OPTIONS_GNU -fdiagnostics-color=always)
set(cpp-tutor_COMPILER_OPTIONS_MSVC)
# ADD THE ADDRESS SANITIZER BUILD TYPE
# ====================================
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel asan"
FORCE)
set(CMAKE_C_FLAGS_ASAN
"-fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g"
CACHE STRING "Flags used by the C compiler during AddressSanitizer builds."
FORCE)
set(CMAKE_CXX_FLAGS_ASAN
"-fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g"
CACHE STRING "Flags used by the C++ compiler during AddressSanitizer builds."
FORCE)
# TARGETS AND THE CORRESPONDING SOURCE FILES
# ==============================================
set(cppTutor_EXECUTABLES
cppTutorUT
strings_1
strings_2
strings_3
pointers
smart_pointers
strings_pool
deep_vs_shallow
memory_block
rvalue_vs_lvalue
type_casting
const_vs_constexpr
rvo
auto_vs_decltype
noexcept
override_final
null_vs_nullptr
static_assert
delete_vs_default
init_stack_vs_global_vars
init_aggregate
init_types_of
init_brace_elision
init_list_gotchas
)
set(cppTutorUT_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/strings_reverse.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/strings_pool.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/cpp_tutor_ut_main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/tests_strings.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/tests_strings_pool.cpp
${CMAKE_CURRENT_SOURCE_DIR}/googletest/googletest/src/gtest-all.cc)
set(strings_1_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/strings_reverse.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/strings_1_main.cpp)
set(strings_2_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/strings_2_main.cpp)
set(strings_3_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/strings_3_main.cpp)
set(pointers_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/pointers_main.cpp)
set(smart_pointers_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/smart_pointers_main.cpp)
set(strings_pool_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/strings_pool_main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/strings_pool.cpp)
set(deep_vs_shallow_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/deep_vs_shallow.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/deep_vs_shallow_main.cpp)
set(memory_block_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/memory_block.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/memory_block_main.cpp)
set(rvalue_vs_lvalue_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/rvalue_vs_lvalue_main.cpp)
set(type_casting_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/type_casting_main.cpp)
set(const_vs_constexpr_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/const_vs_constexpr_main.cpp)
set(rvo_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/rvo_main.cpp)
set(auto_vs_decltype_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/auto_vs_decltype_main.cpp)
set(noexcept_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/noexcept_main.cpp)
set(override_final_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/override_final_main.cpp)
set(null_vs_nullptr_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/null_vs_nullptr_main.cpp)
set(static_assert_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/static_assert_main.cpp)
set(delete_vs_default_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/delete_vs_default_main.cpp)
set(init_stack_vs_global_vars_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/init_stack_vs_global_vars_main.cpp)
set(init_aggregate_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/init_aggregate_main.cpp)
set(init_brace_elision_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/init_brace_elision_main.cpp)
set(init_types_of_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/init_types_of_main.cpp)
set(init_list_gotchas_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/init_list_gotchas_main.cpp)
# EXECUTABLES AND THE INCLUDE DIRECTORIES FOR TARGETS
# ===================================================
foreach( executable ${cppTutor_EXECUTABLES} )
add_executable( ${executable}
${${executable}_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/src/cppt_tools.cpp
)
target_include_directories(${executable} PRIVATE SYSTEM
${PROJECT_BINARY_DIR}/include/
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_compile_options(${executable} PRIVATE
"$<$<CXX_COMPILER_ID:Clang>:${cpp-tutor_COMPILER_OPTIONS_CLANG}>"
"$<$<CXX_COMPILER_ID:AppleClang>:${cpp-tutor_COMPILER_OPTIONS_CLANG}>"
"$<$<CXX_COMPILER_ID:GNU>:${cpp-tutor_COMPILER_OPTIONS_GNU}>"
"$<$<CXX_COMPILER_ID:MSVC>:${cpp-tutor_COMPILER_OPTIONS_MSVC}>")
endforeach()
# EXTRA SET-UP FOR UNIT TESTS
# ===========================
target_include_directories(cppTutorUT PRIVATE SYSTEM
${CMAKE_CURRENT_SOURCE_DIR}/googletest/googletest/
${CMAKE_CURRENT_SOURCE_DIR}/googletest/googletest/include
)
if(UNIX)
target_link_libraries(cppTutorUT PRIVATE pthread)
endif()
# CONFIGURE THE CPP_TUTOR.H HEADER FILE
# =====================================
option(MEMORY_LEAK "Use the implementation exhibiting memory leaks" OFF)
option(COMPILATION_ERROR "Enable code that leads to compilation errors" OFF)
option(DANGLING_REF_OR_PTR "Enable code that leads to dandling refs/ptrs" OFF)
option(RUNTIME_ERROR "Enable code that leads to run-time errors (e.g. UB)." OFF)
configure_file(
${PROJECT_SOURCE_DIR}/include/cppt_ag.hpp.in
${PROJECT_BINARY_DIR}/include/cppt_ag.hpp
)