-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
187 lines (165 loc) · 4.22 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
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
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
project(
SOLO12_SDK
VERSION 0.1.0
LANGUAGES CXX
)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
option(DEBUG_BUILD "Build everything in debug mode" ON)
option(BUILD_TESTS "Build tests" OFF) # we have no tests yet
option(BUILD_EXAMPLES "Build examples" ON)
option(USE_SINGLE_PRECISION "Use single precision floats" OFF)
option(DRY_BUILD "Build without building masterboard sdk for debug" OFF)
if(WIN32) # force dry build because masterboard sdk cannot be compiled on w*ndows
message("You are on w*ndows, forcing dry build")
set(DRY_BUILD ON)
set(BUILD_EXAMPLES OFF)
endif()
message("Build Examples -> ${BUILD_EXAMPLES}")
#* where to look for the project header and source files
set(INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include)
set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
set(TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/test)
set(EXAMPLE_DIR ${CMAKE_CURRENT_LIST_DIR}/examples)
#* tests, examples, benchmarks to compile
set(TEST_NAMES
)
set(EXAMPLE_NAMES
example
example_pd
example_imu_data_collection
)
#* source files
file(GLOB_RECURSE MASTER_BOARD_SRC CONFIGURE_DEPENDS "${SRC_DIR}/master_board_sdk/*.cpp")
file(GLOB_RECURSE COMMANDER_SRC CONFIGURE_DEPENDS "${SRC_DIR}/commander/*.cpp")
#* set up output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/data)
#* project compile options
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_compile_options(
-fdiagnostics-color=always #* colored debug output
-fmessage-length=0 #* disable line wrapping (default=72 char)
-Wall #* all warnings
-Wextra #* more warnings
-Wpedantic #* more warnings
)
if(DEBUG_BUILD)
add_compile_options(
-g #* debug symbols
-O0 #* no optimization, -Og may work better with some debuggers
)
else()
add_compile_options(
-O3 #* release optimization
)
endif()
if(USE_SINGLE_PRECISION)
add_compile_options(-DUSE_SINGLE_PRECISION) #* use single precision floats
endif()
if(DRY_BUILD)
add_compile_options(-DDRY_BUILD) #* use single precision floats
endif()
#*************#
#* Libraries *#
#*************#
if(NOT DRY_BUILD)
add_library(master_board SHARED
${MASTER_BOARD_SRC}
)
target_link_libraries(master_board pthread)
target_include_directories(
master_board PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
endif()
#***************#
#* Executables *#
#***************#g
add_executable(
main
${COMMANDER_SRC}
)
target_include_directories(
main PRIVATE
${INCLUDE_DIR}
${matrix_rw_SOURCE_DIR}/include
${rt_timer_SOURCE_DIR}/include
${cxxopts_SOURCE_DIR}/include
)
# target_link_libraries(
# main
# ${CURSES_LIBRARIES}
# )
target_compile_options(
main PRIVATE
)
if(NOT DRY_BUILD)
target_link_libraries(
main
master_board
)
endif()
#***********#
#* Testing *#
#***********#
if(BUILD_TESTS)
enable_testing()
foreach(ELEMENT ${TEST_NAMES})
add_executable(
${ELEMENT}
${TEST_DIR}/${ELEMENT}.cpp
)
target_include_directories(
${ELEMENT} PRIVATE
${INCLUDE_DIR}
${matrix_rw_SOURCE_DIR}/include
${rt_timer_SOURCE_DIR}/include
)
target_compile_options(
${ELEMENT} PRIVATE
)
add_test(
NAME ${ELEMENT}
COMMAND ${ELEMENT}
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
endforeach(ELEMENT ${TEST_NAMES})
endif()
#************#
#* Examples *#
#************#
if(BUILD_EXAMPLES)
foreach(ELEMENT ${EXAMPLE_NAMES})
add_executable(
${ELEMENT}
${EXAMPLE_DIR}/${ELEMENT}.cpp
)
target_include_directories(
${ELEMENT} PRIVATE
${INCLUDE_DIR}
)
target_compile_options(
${ELEMENT} PRIVATE
)
target_link_libraries(
${ELEMENT} master_board
)
endforeach(ELEMENT ${EXAMPLE_NAMES})
endif()
#**************************#
#* Executable permissions *#
#**************************#
#if(NOT DEBUG_BUILD)
add_custom_command(
TARGET main
POST_BUILD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND scripts/set_permissions.sh
)
#endif()
endif()