-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
127 lines (101 loc) · 4.64 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
# Copyright: (C) 2017 iCub Facility, Istituto Italiano di Tecnologia
# Copy Policy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
cmake_minimum_required(VERSION 3.5)
project(ihmc-ors-yarp)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Find YARP
set(YARP_REQUIRED_VERSION 2.3.70)
find_package(YARP REQUIRED)
if(${YARP_VERSION} VERSION_LESS ${YARP_REQUIRED_VERSION})
message(FATAL_ERROR "YARP version ${YARP_VERSION} not sufficient, at least version ${YARP_REQUIRED_VERSION} is required.")
endif()
if (NOT YARP_HAS_MATH_LIB)
message(FATAL_ERROR "YARP was found, but no libYARP_math was detected, please recompile yarp")
endif()
# Find fastcdr to build messages generated by fastrtpsgen
find_package(fastcdr REQUIRED)
# Find Asio and Threads, both required for opening sockets from C++
find_package(Asio REQUIRED)
# .idl generated messages require C++11
set(CMAKE_CXX_STANDARD 11)
#
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Add a target that regenerate the messages contained in the idl directory
# This target needs to be manually run, because in general we expect to
# commit the generated files to avoid depending on Java
add_custom_target(idl-regenerate-cxx)
# TODO(traversaro) : check if fastrtpsgen exist and is in the PATH
set(IDL_FILES idl/robotFeedback.idl
idl/robotDesired.idl)
foreach(IDL_FILE ${IDL_FILES})
add_custom_command(TARGET idl-regenerate-cxx
COMMAND fastrtpsgen -replace -d ${CMAKE_CURRENT_SOURCE_DIR}/autogenerated ${CMAKE_CURRENT_SOURCE_DIR}/${IDL_FILE}
COMMENT "Generating cxx files from ${IDL_FILE}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endforeach()
# Generate a static library of the generated IDL messages
# TODO(traversaro): This will fail as soon as a new message is added to IDL_FILES
set(IDL_GENERATED_FILES)
foreach(IDL_FILE ${IDL_FILES})
set(IDL_FILENAME ${IDL_FILE})
string(REGEX REPLACE "idl/" ""
IDL_FILENAME ${IDL_FILENAME})
string(REGEX REPLACE ".idl" ""
IDL_FILENAME ${IDL_FILENAME})
list(APPEND IDL_GENERATED_FILES autogenerated/${IDL_FILENAME}.cxx)
endforeach()
add_library(idl_messages STATIC ${IDL_GENERATED_FILES})
target_link_libraries(idl_messages PRIVATE fastcdr)
target_include_directories(idl_messages INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/autogenerated)
# Add the yarp device that interacts with YARP motor interface via C++
# and with IHMC-ORS software with DDS .idl messages
set(BUILD_SHARED_LIBS ON)
yarp_configure_plugins_installation(ihmc-ors-yarp)
set(YARP_DEVICE_NAME bridge_ihmc_ors)
yarp_prepare_plugin(${YARP_DEVICE_NAME} TYPE yarp::dev::BridgeIHMCORS
INCLUDE BridgeIHMCORS.h
CATEGORY device
DEFAULT ON
ADVANCED)
if(ENABLE_${YARP_DEVICE_NAME})
yarp_add_plugin(${YARP_DEVICE_NAME}
src/BridgeIHMCORS.cpp
src/BridgeIHMCORS.h)
target_include_directories(${YARP_DEVICE_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
# There seems to be an issue with the Asio::Asio imported target
target_include_directories(${YARP_DEVICE_NAME} PRIVATE ${Asio_INCLUDE_DIRS})
target_link_libraries(${YARP_DEVICE_NAME} YARP::YARP_OS
YARP::YARP_dev
YARP::YARP_init
YARP::YARP_sig
YARP::YARP_math
idl_messages
fastcdr)
yarp_install(FILES src/${YARP_DEVICE_NAME}.ini
COMPONENT runtime
DESTINATION ${YARP_PLUGIN_MANIFESTS_INSTALL_DIR})
if(MSVC)
target_compile_definitions(${YARP_DEVICE_NAME} _USE_MATH_DEFINES)
endif()
yarp_install(TARGETS ${YARP_DEVICE_NAME}
COMPONENT Runtime
LIBRARY DESTINATION ${YARP_DYNAMIC_PLUGINS_INSTALL_DIR}
ARCHIVE DESTINATION ${YARP_STATIC_PLUGINS_INSTALL_DIR})
endif()
# Add simple example of UDP socket
option(BUILD_EXAMPLE_SOCKET "Enable compilation of a simple UDP socket example" FALSE)
if (BUILD_EXAMPLE_SOCKET)
add_executable(testSocket examples/testSocket.cpp)
target_include_directories(testSocket PRIVATE ${Asio_INCLUDE_DIRS})
target_link_libraries(testSocket fastcdr
idl_messages)
endif()
# Add tests
option(BUILD_TESTING "Create tests using CMake" OFF)
if(BUILD_TESTING)
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()
# Add the "uninstall" target
include(AddUninstallTarget)