-
Notifications
You must be signed in to change notification settings - Fork 14
/
CMakeLists.txt
419 lines (352 loc) · 9.13 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
cmake_minimum_required(VERSION 2.8.3)
set(_YPSPUR_MAJOR_VERSION 1)
set(_YPSPUR_MINOR_VERSION 22)
set(_YPSPUR_PATCH_VERSION 5)
if(${CMAKE_MAJOR_VERSION} LESS 3)
# DARN_IT: CMake 2 should be supported until April, 2019 (Ubuntu Trusty EOL)
cmake_policy(VERSION 2.8.3)
project(ypspur)
set(YPSPUR_MAJOR_VERSION ${_YPSPUR_MAJOR_VERSION})
set(YPSPUR_MINOR_VERSION ${_YPSPUR_MINOR_VERSION})
set(YPSPUR_PATCH_VERSION ${_YPSPUR_PATCH_VERSION})
set(PROJECT_VERSION ${_YPSPUR_MAJOR_VERSION}.${_YPSPUR_MINOR_VERSION}.${_YPSPUR_PATCH_VERSION})
message(WARNING "[deprecated] CMake 2 will be obsoleted in yp-spur build at April, 2019")
else()
cmake_policy(VERSION 3.0)
project(ypspur VERSION ${_YPSPUR_MAJOR_VERSION}.${_YPSPUR_MINOR_VERSION}.${_YPSPUR_PATCH_VERSION})
endif()
set(CVF_VERSION ${PROJECT_VERSION})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
set(YP_VENDOR_NAME "OpenSpur.org")
set(YP_PRODUCT_NAME "Yamabico Project - Spur")
set(YP_PROTOCOL_NAME "YPP:11:05")
set(YP_PARAMS_DIR "robot-params")
option(USE_SSM "Compile with SSM if available." ON)
include(GetGitRevision)
get_git_revision()
set(PROJECT_VERSION_REV "${PROJECT_VERSION} (${GIT_REVISION_SHORT})")
# Find dependencies
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(THREAD_LIBRARIES "")
if(THREADS_HAVE_PTHREAD_ARG)
set(THREAD_LIBRARIES -pthread ${THREAD_LIBRARIES})
endif(THREADS_HAVE_PTHREAD_ARG)
if(CMAKE_THREAD_LIBS_INIT)
set(THREAD_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${THREAD_LIBRARIES})
endif(CMAKE_THREAD_LIBS_INIT)
find_package(PkgConfig)
if(PKGCONFIG_FOUND)
set(HAVE_PKG_CONFIG 1)
endif(PKGCONFIG_FOUND)
if(USE_SSM)
find_package(SSM)
endif(USE_SSM)
find_package(Readline)
if(READLINE_FOUND)
add_definitions(-DHAVE_LIBREADLINE=1)
endif(READLINE_FOUND)
include(CheckFunctionExists)
check_function_exists(longjmp HAVE_LONGJMP)
check_function_exists(siglongjmp HAVE_SIGLONGJMP)
check_function_exists(clock_nanosleep HAVE_CLOCK_NANOSLEEP)
check_function_exists(nanosleep HAVE_NANOSLEEP)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/include/config.h
)
add_definitions(-DHAVE_CONFIG_H=1)
find_package(GTest)
# Set include dirs
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/auxlib
${CMAKE_CURRENT_SOURCE_DIR}/auxlib/formula-calc/include
)
if(SSM_FOUND)
include_directories(
${SSM_INCLUDE_DIRS}
)
endif(SSM_FOUND)
if(READLINE_FOUND)
include_directories(
${READLINE_INCLUDE_DIRS}
)
endif(READLINE_FOUND)
# Static link options
option(ENABLE_ALL_STATIC "Static link libgcc and libstdc++." OFF)
set(TARGET_STATIC_POSTFIX "")
if(ENABLE_ALL_STATIC)
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc")
set(CMAKE_SHARED_LINKER_FLAGS "-static-libgcc")
set(TARGET_STATIC_POSTFIX "-static")
endif(ENABLE_ALL_STATIC)
# Compile flags
if(CMAKE_VERSION VERSION_LESS "3.12")
if(HAVE_LONGJMP)
add_definitions(-DHAVE_LONGJMP)
endif()
if(HAVE_SIGLONGJMP)
add_definitions(-DHAVE_SIGLONGJMP)
endif()
if(HAVE_CLOCK_NANOSLEEP)
add_definitions(-DHAVE_CLOCK_NANOSLEEP)
endif()
if(HAVE_NANOSLEEP)
add_definitions(-DHAVE_NANOSLEEP)
endif()
if(HAVE_SSM)
add_definitions(-DHAVE_SSM)
endif()
else()
if(HAVE_LONGJMP)
add_compile_definitions(HAVE_LONGJMP)
endif()
if(HAVE_SIGLONGJMP)
add_compile_definitions(HAVE_SIGLONGJMP)
endif()
if(HAVE_CLOCK_NANOSLEEP)
add_compile_definitions(HAVE_CLOCK_NANOSLEEP)
endif()
if(HAVE_NANOSLEEP)
add_compile_definitions(HAVE_NANOSLEEP)
endif()
if(HAVE_SSM)
add_compile_definitions(HAVE_SSM)
endif()
endif()
# Add subdirectories
add_subdirectory(auxlib)
add_subdirectory(samples)
# Enable gtest
if(GTEST_FOUND)
enable_testing()
add_executable(param_load_test
test/param_load.cpp
src/adinput.c
src/communication.c
src/odometry.c
src/param.c
src/serial.c
src/ssm_spur_handler.c
src/utility.c
src/yprintf.c
)
target_link_libraries(param_load_test
${GTEST_LIBRARIES}
${THREAD_LIBRARIES}
carte2d${TARGET_STATIC_POSTFIX}
formula-calc${TARGET_STATIC_POSTFIX}
)
add_test(YPSpurParamTest param_load_test)
add_executable(e2e_test
test/e2e.cpp
)
add_dependencies(e2e_test
ypspur-coordinator
ypspur
)
target_link_libraries(e2e_test
${GTEST_LIBRARIES}
${THREAD_LIBRARIES}
ypspur
)
if(CMAKE_VERSION VERSION_LESS "3.1")
set_property(TARGET e2e_test PROPERTY COMPILE_OPTIONS "-std=c++11")
else()
set_property(TARGET e2e_test PROPERTY CXX_STANDARD 11)
endif()
add_test(E2ETest e2e_test ${CMAKE_SOURCE_DIR}/test/)
endif(GTEST_FOUND)
# Build coordinator and utilities
add_executable(ypspur-coordinator
src/adinput.c
src/command_aux.c
src/command.c
src/command_get.c
src/command_joint.c
src/command_param.c
src/command_run.c
src/command_set.c
src/communication.c
src/control_motion.c
src/control_vehicle.c
src/ipcommunication.c
src/msq.win32.c
src/odometry.c
src/param.c
src/ping.c
src/serial.c
src/ssm_spur_handler.c
src/utility.c
src/ypprotocol.c
src/yprintf.c
src/ypspur-coordinator.c
)
target_link_libraries(ypspur-coordinator
carte2d${TARGET_STATIC_POSTFIX} formula-calc${TARGET_STATIC_POSTFIX} m ${THREAD_LIBRARIES}
)
if(SSM_FOUND)
target_link_libraries(ypspur-coordinator
odomssm${TARGET_STATIC_POSTFIX}
${SSM_LIBRARIES}
)
endif(SSM_FOUND)
if(WIN32)
target_link_libraries(ypspur-coordinator wsock32 ws2_32)
endif(WIN32)
add_executable(ypspur-free
src/ypspur-free.c
)
target_link_libraries(ypspur-free
ypspur${TARGET_STATIC_POSTFIX}
)
add_executable(ypspur-interpreter
src/ypspur-interpreter.c
)
target_link_libraries(ypspur-interpreter
ypspur${TARGET_STATIC_POSTFIX}
${READLINE_LIBRARIES}
)
# Build libraries
set(YPSPUR_LIBRARY_VERSION 14.2.0)
set(YPSPUR_LIBRARY_SOVERSION 14)
set(YPSPUR_PUBLIC_HEADERS
include/ypspur.h
include/ypparam.h
)
set(YPSPUR_MD_PUBLIC_HEADERS
include/ypspur-md.h
include/ypparam.h
)
add_library(ypspur SHARED
src/libypspur.c
src/libypspur-md.c
src/ipcommunication.c
src/msq.win32.c
src/yprintf.c
src/utility.c
)
add_library(ypspur-comm SHARED
src/communication.c
)
if(WIN32)
target_link_libraries(ypspur wsock32 ws2_32)
endif(WIN32)
set_target_properties(ypspur PROPERTIES
IMPORT_SUFFIX "_import.lib"
VERSION ${YPSPUR_LIBRARY_VERSION}
SOVERSION ${YPSPUR_LIBRARY_SOVERSION}
PUBLIC_HEADER "${YPSPUR_PUBLIC_HEADERS}"
)
add_library(ypspur-static STATIC
src/libypspur.c
src/libypspur-md.c
src/ipcommunication.c
src/msq.win32.c
src/yprintf.c
src/utility.c
)
if(WIN32)
target_link_libraries(ypspur-static wsock32 ws2_32)
endif(WIN32)
set_target_properties(ypspur-static PROPERTIES
OUTPUT_NAME "ypspur"
PUBLIC_HEADER "${YPSPUR_PUBLIC_HEADERS}"
)
add_library(ypspur-md SHARED
src/libypspur-md.c
src/ipcommunication.c
src/msq.win32.c
src/yprintf.c
src/utility.c
)
if(WIN32)
target_link_libraries(ypspur-md wsock32 ws2_32)
endif(WIN32)
set_target_properties(ypspur-md PROPERTIES
IMPORT_SUFFIX "_import.lib"
VERSION ${YPSPUR_LIBRARY_VERSION}
SOVERSION ${YPSPUR_LIBRARY_SOVERSION}
PUBLIC_HEADER "${YPSPUR_MD_PUBLIC_HEADERS}"
)
add_library(ypspur-md-static STATIC
src/libypspur-md.c
src/ipcommunication.c
src/msq.win32.c
src/yprintf.c
src/utility.c
)
if(WIN32)
target_link_libraries(ypspur-md-static wsock32 ws2_32)
endif(WIN32)
set_target_properties(ypspur-md-static PROPERTIES
OUTPUT_NAME "ypspur-md"
PUBLIC_HEADER "${YPSPUR_MD_PUBLIC_HEADERS}"
)
# Install
install(TARGETS
ypspur-coordinator
ypspur
ypspur-comm
ypspur-static
ypspur-md
ypspur-md-static
ypspur-free
ypspur-interpreter
EXPORT YPSpurExport
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include
)
install(FILES include/yp-spur.h
DESTINATION include
)
install(FILES include/communication.h
DESTINATION include/ypspur
)
if(SSM_FOUND)
install(DIRECTORY
include/ssmtype
DESTINATION include
)
endif(SSM_FOUND)
# Generate package config and install
install(EXPORT YPSpurExport
DESTINATION share/ypspur/cmake/
FILE YPSpurTargets.cmake
)
set(YPSPUR_INCLUDE_DIRS include)
set(YPSPUR_CMAKE_DIR share/ypspur/cmake)
include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/ypspur-config.cmake.in
${PROJECT_BINARY_DIR}/cmake/ypspur/ypspur-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/ypspur
PATH_VARS YPSPUR_CMAKE_DIR YPSPUR_INCLUDE_DIRS
)
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/cmake/ypspur/ypspur-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(
FILES
${PROJECT_BINARY_DIR}/cmake/ypspur/ypspur-config.cmake
${PROJECT_BINARY_DIR}/cmake/ypspur/ypspur-config-version.cmake
package.xml
DESTINATION share/ypspur/
)
# Generate pkgconfig file and install
configure_file(ypspur.pc.in
${PROJECT_BINARY_DIR}/ypspur.pc @ONLY
)
set(
PKGCONFIG_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/pkgconfig
CACHE PATH "Install directory of pkgconfig file"
)
install(
FILES
${PROJECT_BINARY_DIR}/ypspur.pc
DESTINATION ${PKGCONFIG_INSTALL_DIR}
)