forked from tttapa/Control-Surface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
137 lines (106 loc) · 4.75 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
135
136
137
cmake_minimum_required(VERSION 3.10)
################################################################################
# Enable ccache if available
################################################################################
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
################################################################################
# Set the C++ standard to C++14
################################################################################
set(CMAKE_CXX_STANDARD 14)
project(Control_Surface)
################################################################################
# Add Google Test
################################################################################
add_subdirectory(googletest)
include_directories(${gmock_SOURCE_DIR}/include)
include_directories(${gtest_SOURCE_DIR}/include)
include(GoogleTest)
enable_testing()
################################################################################
# Change the default output directories
################################################################################
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
################################################################################
# Set the compiler options
################################################################################
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} \
-Wmissing-include-dirs")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Wall -Wextra -Werror \
-fdiagnostics-show-option \
-Wdouble-promotion \
-Wswitch-default -Wswitch-enum -Wimplicit-fallthrough \
-Wuninitialized \
-Wno-double-promotion \
-Wno-missing-braces \
-pedantic -pedantic-errors")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-Wall -Wextra -Werror")
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb3 -O0")
set(CMAKE_C_FLAGS_DEBUG "-ggdb3 -O0")
set(CMAKE_CXX_FLAGS_ASAN "-g3 -O0 -fsanitize=address")
set(CMAKE_C_FLAGS_ASAN "-g3 -O0 -fsanitize=address")
set(CMAKE_CXX_FLAGS_RELEASE "-Os")
set(CMAKE_C_FLAGS_RELEASE "-Os")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Os -ggdb3")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -ggdb3")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Winconsistent-missing-override \
-Wno-gnu-zero-variadic-macro-arguments")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Wsuggest-override")
endif()
# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) # LTO
################################################################################
# Enable coverage information
################################################################################
set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_DEBUG} \
-fprofile-arcs -ftest-coverage \
-fsanitize=address")
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} \
-fprofile-arcs -ftest-coverage \
-fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "-fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
################################################################################
# Build the source files and tests
################################################################################
add_subdirectory(gtest-wrappers)
add_subdirectory(mock)
add_subdirectory(src)
add_subdirectory(test)
################################################################################
# Custom targets for documentation
################################################################################
add_custom_target(export_documentation ./export.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/doxygen/scripts)
# Add XBM target
add_custom_target(xbm
python3 ${CMAKE_CURRENT_LIST_DIR}/src/Display/Bitmaps/Scripts/XBM-export.py
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/docs/Doxygen)
# Add export documentation target
add_custom_target(documentation
rm -rf html && ./scripts/examples.py && doxygen
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/doxygen
DEPENDS xbm)
# Add coverage target
if (CMAKE_BUILD_TYPE STREQUAL "Coverage")
add_custom_target(coverage
${CMAKE_CURRENT_LIST_DIR}/scripts/coverage.sh ${CMAKE_CXX_COMPILER_ID}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
# Custom test targets
add_custom_target(check tests
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin/
DEPENDS tests)
add_custom_target(arduino ./build-arduino-examples.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/scripts)
add_custom_target(arduino_ci ./build-arduino-examples-ci.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/scripts)