-
Notifications
You must be signed in to change notification settings - Fork 162
/
CMakeLists.txt
287 lines (249 loc) · 7.6 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
cmake_minimum_required(VERSION 3.11)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(libfranka_VERSION 0.15.0)
project(libfranka
VERSION ${libfranka_VERSION}
LANGUAGES CXX
)
option(BUILD_DOCUMENTATION "Build documentation" OFF)
option(SKIP_CXX_BUILD "Skips the c++ build" OFF)
if(BUILD_DOCUMENTATION)
add_subdirectory(doc)
if(SKIP_CXX_BUILD)
return()
endif()
endif()
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Set a default build type if none was specified
set(DEFAULT_BUILD_TYPE "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
if(MSVC)
add_compile_options(/W0)
else()
add_compile_options(-Wall -Wextra)
endif()
set(THIRDPARTY_SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty" CACHE PATH
"Directory for third-party sources")
## Dependencies
find_package(Poco REQUIRED COMPONENTS Net Foundation)
find_package(Eigen3 REQUIRED)
find_package(pinocchio REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
## Build options
option(STRICT "Treat warnings as errors" OFF)
if(STRICT)
if(MSVC)
add_compile_options(/WX)
else()
add_compile_options(-Werror)
endif()
endif()
option(BUILD_COVERAGE "Build with code coverage" OFF)
if(BUILD_COVERAGE)
add_compile_options(--coverage)
# Unfortunately, there is no add_link_options...
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
endif()
## Load dependencies
include(FetchFMT)
## Submodules
add_subdirectory(common)
## Library
add_library(franka SHARED
src/active_control.cpp
src/active_motion_generator.cpp
src/active_torque_control.cpp
src/control_loop.cpp
src/control_tools.cpp
src/control_types.cpp
src/duration.cpp
src/errors.cpp
src/exception.cpp
src/gripper.cpp
src/gripper_state.cpp
src/library_downloader.cpp
src/library_loader.cpp
src/load_calculations.cpp
src/lowpass_filter.cpp
src/model.cpp
src/model_library.cpp
src/network.cpp
src/rate_limiting.cpp
src/robot.cpp
src/robot_impl.cpp
src/robot_state.cpp
src/vacuum_gripper.cpp
src/vacuum_gripper_state.cpp
src/robot_model.cpp
src/logging/cout_logging_sink.cpp
src/logging/logger.cpp
src/logging/robot_state_log.cpp
src/logging/robot_state_logger.cpp
)
add_library(Franka::Franka ALIAS franka)
set_target_properties(franka PROPERTIES
WINDOWS_EXPORT_ALL_SYMBOLS ON
VERSION ${libfranka_VERSION}
SOVERSION ${libfranka_VERSION_MAJOR}.${libfranka_VERSION_MINOR} # Use minor version while we're at 0.x
EXPORT_NAME Franka
)
target_compile_features(franka INTERFACE
cxx_attribute_deprecated
cxx_constexpr
cxx_defaulted_functions
cxx_deleted_functions
cxx_generalized_initializers
cxx_noexcept
cxx_uniform_initialization
)
if(MSVC)
target_compile_definitions(franka PUBLIC
_USE_MATH_DEFINES # for M_PI in cmath
NOMINMAX # avoid conflict with std::min
)
endif()
target_include_directories(franka PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(franka PRIVATE
Poco::Foundation
Poco::Net
Eigen3::Eigen3
Threads::Threads
pinocchio::pinocchio
)
target_link_libraries(franka PUBLIC
libfranka-common
fmt::fmt
)
## Installation
include(GNUInstallDirs)
set(INSTALL_CMAKE_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/Franka)
install(TARGETS franka libfranka-common
EXPORT FrankaTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY include/ common/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
USE_SOURCE_PERMISSIONS
)
export(EXPORT FrankaTargets
NAMESPACE Franka::
FILE ${CMAKE_CURRENT_BINARY_DIR}/FrankaTargets.cmake
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FrankaConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(cmake/FrankaConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/FrankaConfig.cmake
INSTALL_DESTINATION ${INSTALL_CMAKE_CONFIG_DIR}
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/FrankaConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/FrankaConfigVersion.cmake
DESTINATION ${INSTALL_CMAKE_CONFIG_DIR}
)
install(EXPORT FrankaTargets
NAMESPACE Franka::
DESTINATION ${INSTALL_CMAKE_CONFIG_DIR}
)
## Subprojects
# Ignore find_package(Franka) in subprojects.
set(FRANKA_IS_FOUND TRUE)
option(BUILD_TESTS "Build tests" ON)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
option(BUILD_EXAMPLES "Build example code" ON)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
## Packaging
set(CPACK_PACKAGE_VENDOR "Franka Robotics GmbH")
set(CPACK_GENERATOR "DEB;TGZ")
set(CPACK_PACKAGE_VERSION ${libfranka_VERSION})
set(CPACK_SYSTEM_NAME ${CMAKE_HOST_SYSTEM_PROCESSOR})
# Debian versions require a dash
set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}-1)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Franka Robotics GmbH")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libpoco-dev, libfmt-dev, libeigen3-dev")
set(CPACK_DEBIAN_PACKAGE_CONFLICTS "ros-kinetic-libfranka, ros-melodic-libfranka, ros-noetic-libfranka, ros-foxy-libfranka, ros-humble-libfranka")
include(CPack)
## Tools
file(GLOB_RECURSE SOURCES
src/*.cpp
examples/*.cpp
common/*.cpp
)
file(GLOB_RECURSE HEADERS
include/*.h
src/*.h
examples/*.h
common/*.h
)
file(GLOB_RECURSE TEST_FILES
test/*.h
test/*.cpp
)
file(GLOB_RECURSE TIDY_IGNORED_FILES
src/libfcimodels.h
)
find_program(CLANG_FORMAT_PROG clang-format DOC "'clang-format' executable")
if(CLANG_FORMAT_PROG)
add_custom_target(format
COMMAND ${CLANG_FORMAT_PROG} -i ${SOURCES} ${HEADERS} ${TEST_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Formatting source code with clang-format"
VERBATIM
)
add_custom_target(check-format
COMMAND scripts/format-check.sh ${CLANG_FORMAT_PROG} -output-replacements-xml ${SOURCES} ${HEADERS} ${TEST_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Checking code formatting with clang-format"
VERBATIM
)
else(CLANG_FORMAT_PROG)
MESSAGE(WARNING "Could not find clang-format")
endif()
find_program(CLANG_TIDY_PROG clang-tidy DOC "'clang-tidy' executable")
if(CLANG_TIDY_PROG)
# Build JSON string for clang-tidy's line filter
set(TIDY_FILES ${SOURCES} ${HEADERS})
foreach(ignored_file ${TIDY_IGNORED_FILES})
list(REMOVE_ITEM TIDY_FILES ${ignored_file})
endforeach()
string(REPLACE ";" "\"},{\"name\":\"" TIDY_LINE_FILTER "${TIDY_FILES}")
set(TIDY_LINE_FILTER "[{\"name\":\"${TIDY_LINE_FILTER}\"}]")
add_custom_target(tidy
COMMAND ${CLANG_TIDY_PROG} -p=${CMAKE_BINARY_DIR}
-line-filter=${TIDY_LINE_FILTER} ${SOURCES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Running clang-tidy"
VERBATIM
)
add_custom_target(check-tidy
COMMAND scripts/fail-on-output.sh ${CLANG_TIDY_PROG} -p=${CMAKE_BINARY_DIR}
-line-filter=${TIDY_LINE_FILTER} ${SOURCES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Running clang-tidy"
VERBATIM
)
else(CLANG_TIDY_PROG)
MESSAGE(WARNING "Could not find clang-tidy")
endif()