-
Notifications
You must be signed in to change notification settings - Fork 21
/
CMakeLists.txt
196 lines (165 loc) · 6.36 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
####################################################################
# cmake support for KUKA's Fast Robot Interface (FRI) client library
####################################################################
cmake_minimum_required(VERSION 3.18)
project(FRIClient VERSION 1.0.0
DESCRIPTION "KUKA's Fast Robot Interface client library."
LANGUAGES C CXX)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type." FORCE)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Disable specific warnings (we cannot change these, KUKA has to fix them in their SDK)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format-security -Wno-parentheses")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format-security -Wno-parentheses")
endif()
######################
# variable definitions
######################
set(FRIClient_SDK_NAME "FRI-Client-SDK_Cpp")
option(BUILD_FRI_APPS "Build FRIClient example applications" OFF)
#########################################
# extract the FRIClient from the zip file
#########################################
file(ARCHIVE_EXTRACT
INPUT ${CMAKE_CURRENT_SOURCE_DIR}/${FRIClient_SDK_NAME}.zip
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}
)
#######################
# find library versions
#######################
# try to find nanopb version
file(GLOB NANOPB_HEADER_PATH ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/nanopb-*/pb.h)
file(READ ${NANOPB_HEADER_PATH} NANOPB_HEADER)
string(REGEX MATCH "NANOPB_VERSION nanopb-([0-9]*).([0-9]*).([0-9]*)" _ ${NANOPB_HEADER})
set(NANOPB_VERSION_MAJOR ${CMAKE_MATCH_1})
set(NANOPB_VERSION_MINOR ${CMAKE_MATCH_2})
set(NANOPB_VERSION_PATCH ${CMAKE_MATCH_3})
set(NANOPB_VERSION ${NANOPB_VERSION_MAJOR}.${NANOPB_VERSION_MINOR}.${NANOPB_VERSION_PATCH})
message("Found nanopb of version: " ${NANOPB_VERSION})
# #13: Windows support
# if (MSVC)
# set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# endif()
# try to find FRIClient version
file(READ ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/include/friClientIf.h FRI_CLIENT_IF_HEADER)
string(REGEX MATCH "version \\{([0-9]+)\\.([0-9]+)" _ ${FRI_CLIENT_IF_HEADER})
set(FRI_CLIENT_VERSION_MAJOR ${CMAKE_MATCH_1})
set(FRI_CLIENT_VERSION_MINOR ${CMAKE_MATCH_2})
set(FRI_CLIENT_VERSION ${FRI_CLIENT_VERSION_MAJOR}.${FRI_CLIENT_VERSION_MINOR})
if (NOT FRI_CLIENT_VERSION STREQUAL "1.15")
message(FATAL_ERROR "Expected FRIClient version 1.15, found: " ${FRI_CLIENT_VERSION})
endif()
message("Found FRIClient of version: " ${FRI_CLIENT_VERSION})
# create version header
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/friClientVersion.h.in ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/include/friClientVersion.h
)
#################################
# define FRIClient library target
#################################
message(STATUS "Configuring FRIClient version ${FRI_CLIENT_VERSION}")
file(GLOB_RECURSE NANOPB_SOURCES RELATIVE ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/nanopb-${NANOPB_VERSION}/*.c
)
file(GLOB_RECURSE FRI_SOURCES RELATIVE ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/base/*.cpp
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/client_lbr/*.cpp
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/client_trafo/*.cpp
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/connection/*.cpp
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf/*.cpp
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf/*.c
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf_gen/*.pb.c
)
add_library(FRIClient SHARED
${FRI_SOURCES}
${NANOPB_SOURCES}
)
add_library(FRIClient::FRIClient ALIAS FRIClient) # alias for anyone adding this as a submodule
target_include_directories(FRIClient
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/include>
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/base
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/nanopb-${NANOPB_VERSION}
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf_gen
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf
)
if(MSVC)
target_compile_options(FRIClient
PRIVATE
-DPB_SYSTEM_HEADER="pb_syshdr_win.h"
-DPB_FIELD_16BIT
-DWIN32
-DHAVE_STDINT_H
-DHAVE_STDBOOL_H
)
else()
target_compile_options(FRIClient
PRIVATE
-Wall
-O2
-DHAVE_SOCKLEN_T
-DPB_SYSTEM_HEADER="pb_syshdr.h"
-DPB_FIELD_16BIT
-DHAVE_STDINT_H
-DHAVE_STDDEF_H
-DHAVE_STDBOOL_H
-DHAVE_STDLIB_H
-DHAVE_STRING_H
)
endif()
#################
# install targets
#################
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/FRIClientConfigVersion.cmake"
VERSION ${FRI_CLIENT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(TARGETS FRIClient
EXPORT FRIClientTargets
LIBRARY DESTINATION lib
INCLUDES DESTINATION include
)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/include/
DESTINATION include
)
install(EXPORT FRIClientTargets
FILE FRIClientConfig.cmake
NAMESPACE FRIClient::
DESTINATION lib/cmake/FRIClient
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FRIClientConfigVersion.cmake
DESTINATION lib/cmake/FRIClient
)
################
# build examples
################
if (BUILD_FRI_APPS)
function(build_fri_example NAME)
file(GLOB_RECURSE ${NAME}_SOURCES RELATIVE ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/example/${NAME}/*.cpp
)
add_executable(${NAME}App
${${NAME}_SOURCES}
)
target_include_directories(${NAME}App
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/example/${NAME}
)
target_link_libraries(${NAME}App
PRIVATE
FRIClient
)
endfunction()
build_fri_example(IOAccess)
build_fri_example(LBRJointSineOverlay)
build_fri_example(LBRTorqueSineOverlay)
build_fri_example(LBRWrenchSineOverlay)
build_fri_example(SimulatedTransformationProvider)
build_fri_example(TransformationProvider)
endif(BUILD_FRI_APPS)