forked from frankaemika/libfranka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
224 lines (194 loc) · 5.99 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
cmake_minimum_required(VERSION 3.4)
project(libfranka
VERSION 0.1.0
LANGUAGES CXX
)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_compile_options(-Wall -Wextra)
set(THIRDPARTY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/3rdparty" CACHE PATH
"Directory for third-party sources")
## Dependencies
# Don't forget to adjust cmake/FrankaConfig.cmake.in
# when making changes here.
find_package(Poco REQUIRED COMPONENTS Net Foundation)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
## Build options
option(STRICT "Treat warnings as errors" OFF)
if(STRICT)
add_compile_options(-Werror)
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()
## Submodules
add_subdirectory(common)
## Library
add_library(franka SHARED
src/control_loop.cpp
src/control_types.cpp
src/duration.cpp
src/errors.cpp
src/gripper.cpp
src/gripper_state.cpp
src/library_downloader.cpp
src/library_loader.cpp
src/model.cpp
src/model_library.cpp
src/network.cpp
src/robot.cpp
src/robot_impl.cpp
src/robot_state.cpp
)
add_library(Franka::Franka ALIAS franka)
set_target_properties(franka PROPERTIES
VERSION ${libfranka_VERSION}
SOVERSION ${libfranka_VERSION_MAJOR}
EXPORT_NAME Franka
)
target_include_directories(franka PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(franka PUBLIC Poco::Net Poco::Foundation Threads::Threads)
target_link_libraries(franka PRIVATE libfranka-common)
## Installation
include(GNUInstallDirs)
set(INSTALL_CMAKE_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/Franka)
install(TARGETS franka
EXPORT FrankaTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
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}
)
configure_file(cmake/FindPoco.cmake
${CMAKE_CURRENT_BINARY_DIR}/FindPoco.cmake
COPYONLY
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/FindPoco.cmake
${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.
macro(find_package)
if(NOT "${ARGV0}" STREQUAL Franka)
_find_package(${ARGV})
endif()
endmacro()
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()
option(BUILD_DOCUMENTATION "Build documentation" OFF)
if(BUILD_DOCUMENTATION)
add_subdirectory(doc)
endif()
## Packaging
set(CPACK_PACKAGE_VENDOR "Franka Emika GmbH")
set(CPACK_GENERATOR "DEB;TGZ")
set(CPACK_PACKAGE_VERSION ${libfranka_VERSION})
set(CPACK_SYSTEM_NAME ${CMAKE_HOST_SYSTEM_PROCESSOR})
# Debian
find_program(DPKG_PROG dpkg DOC "'dpkg' executable")
if(DPKG_PROG)
execute_process(COMMAND ${DPKG_PROG} --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Change system name to use the correct architecture in file name
set(CPACK_SYSTEM_NAME ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
endif()
# Debian versions require a dash
set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}-1)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Franka Emika GmbH")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libpoco-dev")
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
)
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
)
endif()