-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
238 lines (187 loc) · 6.35 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
### This file is an adaptation derived from
### github.com/francofusco/template-cmake-project/blob/main/CMakeLists.txt
### Original Author: Franco FUSCO
### Source: github.com/francofusco/template-cmake-project
cmake_minimum_required(VERSION 3.19.4)
project(pendule_pi VERSION 1.0.0)
# Allow using colors in messages. Use with parsimony ;)
include(cmake/colors.cmake)
#######################
# LOCATE DEPENDENCIES #
#######################
# locate dependencies with a custom function
function(find_package_custom pkg)
find_package(${pkg} QUIET)
if(${${pkg}_FOUND})
message(STATUS "${pkg}: ${Green}found${ColourReset}")
else()
set(ALL_DEPENDENCIES_FOUND FALSE PARENT_SCOPE)
message(STATUS "${pkg}: ${Yellow}not found${ColourReset}")
endif()
endfunction()
# Scan all dependecies
set(ALL_DEPENDENCIES_FOUND TRUE)
message(STATUS "Looking for build dependencies")
find_package_custom(pigpio)
find_package_custom(digital_filters)
find_package_custom(yaml-cpp)
# warn the user if code will not be built
if(NOT ${ALL_DEPENDENCIES_FOUND})
message(STATUS "${Yellow}Some dependecies were not found. Only pendule_cpp will be built!${ColourReset}")
endif()
if(${ALL_DEPENDENCIES_FOUND})
##############
# pendule_pi #
##############
add_library(${PROJECT_NAME}
src/pendule_pi/joystick.cpp
src/pendule_pi/pigpio.cpp
src/pendule_pi/switch.cpp
src/pendule_pi/motor.cpp
src/pendule_pi/encoder.cpp
src/pendule_pi/pendule.cpp
)
target_include_directories(${PROJECT_NAME}
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_link_libraries(${PROJECT_NAME}
PUBLIC pigpio::pigpio
PUBLIC pthread
)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_compile_options(${PROJECT_NAME} PRIVATE -O0)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
target_compile_definitions(${PROJECT_NAME} PUBLIC PENDULE_PI_DEBUG_ENABLED)
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
target_compile_options(${PROJECT_NAME} PRIVATE -O2)
# If and when Eigen will be used :P
# target_compile_definitions(${PROJECT_NAME} PRIVATE -DEIGEN_NO_DEBUG)
endif()
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
############
# BINARIES #
############
# Reset all pins in high impedance mode
add_executable(reset_gpio src/bin/reset_gpio.cpp)
target_link_libraries(reset_gpio ${PROJECT_NAME})
# Record linear motions (useful for identification)
add_executable(log_motion src/bin/log_motion.cpp)
target_link_libraries(log_motion ${PROJECT_NAME})
# Record angular motions (useful for identification)
add_executable(log_rotation src/bin/log_rotation.cpp)
target_link_libraries(log_rotation ${PROJECT_NAME})
# Swingup + linearized control
add_executable(demo src/bin/demo.cpp)
target_link_libraries(demo ${PROJECT_NAME} digital_filters::digital_filters)
# TEMP
add_executable(demo_zmq src/bin/demo_zmq.cpp)
target_link_libraries(demo_zmq ${PROJECT_NAME} digital_filters::digital_filters zmq zmqpp yaml-cpp)
# TEMP
add_executable(yaml_test src/bin/yaml_test.cpp)
target_link_libraries(yaml_test yaml-cpp)
add_executable(low_level_interface src/bin/low_level_interface.cpp)
target_link_libraries(low_level_interface
${PROJECT_NAME}
digital_filters::digital_filters
zmq
zmqpp
yaml-cpp
)
endif(${ALL_DEPENDENCIES_FOUND})
##############
# C++ bridge #
##############
# C++ bridge to the low-level interface
add_library(pendule_cpp src/pendule_pi/pendule_cpp.cpp)
target_include_directories(pendule_cpp
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_link_libraries(pendule_cpp zmq zmqpp)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_compile_options(pendule_cpp PRIVATE -O0)
target_compile_options(pendule_cpp PRIVATE -Wall)
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
target_compile_options(pendule_cpp PRIVATE -O2)
endif()
target_compile_features(pendule_cpp PUBLIC cxx_std_17)
###########
# INSTALL #
###########
include(GNUInstallDirs)
# Install binaries
if(${ALL_DEPENDENCIES_FOUND})
install(
TARGETS
reset_gpio
log_motion
log_rotation
demo
DESTINATION bin
)
endif(${ALL_DEPENDENCIES_FOUND})
# Install the libraries
set(LIBS_TO_INSTALL pendule_cpp)
if(${ALL_DEPENDENCIES_FOUND})
list(APPEND LIBS_TO_INSTALL ${PROJECT_NAME})
endif(${ALL_DEPENDENCIES_FOUND})
install(
TARGETS ${LIBS_TO_INSTALL}
DESTINATION lib
EXPORT ${PROJECT_NAME}Targets
)
# Copy all headers from the "include" folder
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}
DESTINATION include
)
# Install the "Targets" file as well.
install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION lib/cmake/${PROJECT_NAME}
)
# Helpers to create the "package config" files.
include(CMakePackageConfigHelpers)
# Create the "Config.cmake" file (to allow "find_package"-ing this project).
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "lib/cmake/example"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
# Generate the version file associated to the "Config.cmake" file.
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}"
COMPATIBILITY AnyNewerVersion
)
# Install the configuration file.
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION lib/cmake/${PROJECT_NAME}
)
# Make the project usable from the build directory as well.
export(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake"
)
# add the possibility tu run 'make uninstall' to remove files added via 'make install'
# NOTE: this will remove files only, and not their parent directories.
# WARNING: this will work only if you do not play around the installed targets manually,
# and if you do not change the install destination.
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake
IMMEDIATE @ONLY
)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake")
#########################
# DOXYGEN DOCUMENTATION #
#########################
add_subdirectory(doc)