-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
105 lines (91 loc) · 3.55 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
cmake_minimum_required(VERSION 3.0.0)
project(unit_tests VERSION 1.0.0)
macro(add_compiler_flags)
foreach(flag ${ARGV})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endforeach()
endmacro()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compiler_flags(-std=c++17)
add_compiler_flags(-fstrict-aliasing)
add_compiler_flags(-fvisibility=hidden)
add_compiler_flags(-pedantic)
add_compiler_flags(-pedantic-errors)
add_compiler_flags(-Werror)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compiler_flags(-Wall)
add_compiler_flags(-Warray-bounds)
add_compiler_flags(-Wcast-align)
add_compiler_flags(-Wcast-qual)
add_compiler_flags(-Wconversion)
add_compiler_flags(-Wctor-dtor-privacy)
add_compiler_flags(-Wdisabled-optimization)
add_compiler_flags(-Weffc++)
add_compiler_flags(-Wextra)
add_compiler_flags(-fdiagnostics-show-option)
add_compiler_flags(-Wfloat-equal)
add_compiler_flags(-Wformat=2)
## add_compiler_flags(-Winline)
add_compiler_flags(-Wlogical-op)
add_compiler_flags(-Wmissing-declarations)
add_compiler_flags(-Wmissing-include-dirs)
add_compiler_flags(-Wnoexcept)
add_compiler_flags(-Wnon-virtual-dtor)
add_compiler_flags(-Wold-style-cast)
add_compiler_flags(-Woverloaded-virtual)
add_compiler_flags(-Wpointer-arith)
add_compiler_flags(-Wredundant-decls)
add_compiler_flags(-Wshadow)
add_compiler_flags(-Wsign-conversion)
## add_compiler_flags(-Wstrict-overflow=5)
## add_compiler_flags(-Wswitch-default)
add_compiler_flags(-Wswitch-enum)
add_compiler_flags(-Wwrite-strings)
add_compiler_flags(-Wundef)
add_compiler_flags(-Wunreachable-code)
add_compiler_flags(-Wunused)
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
add_compiler_flags(-Wdouble-promotion)
add_compiler_flags(-Wtrampolines)
add_compiler_flags(-Wuseless-cast)
add_compiler_flags(-Wvector-operation-performance)
add_compiler_flags(-Wzero-as-null-pointer-constant)
endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
add_compiler_flags(-Wduplicated-cond)
add_compiler_flags(-Wnull-dereference)
add_compiler_flags(-Wshift-overflow=2)
endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
add_compiler_flags(-Walloc-zero)
add_compiler_flags(-Walloca)
add_compiler_flags(-Wduplicated-branches)
endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
add_compiler_flags(-Wcast-align=strict)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compiler_flags(-Weverything)
add_compiler_flags(-Wno-c++98-compat)
add_compiler_flags(-Wno-c++98-compat-pedantic)
add_compiler_flags(-Wno-padded)
add_compiler_flags(-Wno-unused-macros)
endif()
if(MSVC)
add_compiler_flags(/std:c++latest)
add_compiler_flags(/permissive-)
add_compiler_flags(/Wall)
add_compiler_flags(/WX)
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Og -g -DDEBUG" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG" CACHE STRING "" FORCE)
include_directories("../include") ## usflib include directory
include_directories("include") ## unit_tests include directory
file(GLOB_RECURSE user_source "source/*.cpp" "../include/*.hpp" "include/*.hpp")
enable_testing()
add_executable(unit_tests ${user_source})
add_test(NAME unit_tests COMMAND unit_tests)