forked from eboasson/i11eperf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
229 lines (218 loc) · 9.43 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
#
# Copyright(c) 2021 ADLINK Technology Limited and others
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v. 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
# v. 1.0 which is available at
# http://www.eclipse.org/org/documents/edl-v10.php.
#
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#
project(i11eperf LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.17) # not sure what version is actually required
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(default_build_type "RelWithDebInfo")
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()
# Note: "brew --prefix" stuff is for macOS, YMMV
#
# -- to build FastDDS --
#
# mkdir -p eProsima/src
# cd eProsima
# curl -O https://raw.githubusercontent.com/eProsima/Fast-DDS/master/fastrtps.repos
# vcs import src < fastrtps.repos
# colcon build --merge-install --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH="`brew --prefix`;`brew --prefix openssl`"
# (cd src/fastddsgen && ./gradlew assemble)
#
# -- to build OpenDDS --
#
# git clone https://github.com/objectcomputing/OpenDDS.git
# cd OpenDDS
# ./configure --prefix=$PWD/install --optimize --no-debug
# bash -c '. setenv.sh && make all install'
#
# -- to configure --
# CMAKE_PREFIX_PATH will need adjusting
# fastddsgen may be in a different place
#
# cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH="$HOME/C/cdds/CC/install;$HOME/C/cxx/CC/install;$HOME/C/iceoryx/install;$HOME/adlink/eProsima/install;$HOME/adlink/OpenDDS/install;`brew --prefix`;`brew --prefix openssl`" ..
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
option(KEEP_ALL "Use KEEP_ALL history" ON)
option(BATCHING "Enable batching (Cyclone)" OFF)
option(SHM "Enable use of shared memory (FastDDS)" ON)
set(DATATYPE "a1024" CACHE STRING "Data type to use")
set(SLEEP_MS 0 CACHE STRING "ms to sleep between two pubs")
if(KEEP_ALL)
add_compile_definitions(HISTORY=KEEP_ALL)
else()
add_compile_definitions(HISTORY=10)
endif()
if(BATCHING)
add_compile_definitions(BATCHING=1)
else()
add_compile_definitions(BATCHING=0)
endif()
if(SHM)
add_compile_definitions(SHM=1)
else()
add_compile_definitions(SHM=0)
endif()
add_compile_definitions(DATATYPE=${DATATYPE})
add_compile_definitions(SLEEP_MS=${SLEEP_MS})
### Cyclone DDS / C -- copy IDL file to avoid name clash with fastddsgen output
find_package(CycloneDDS QUIET)
if(CycloneDDS_FOUND)
message(STATUS "CycloneDDS found")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/i11eperf_a.idl
COMMAND ${CMAKE_COMMAND} -E copy
ARGS ${CMAKE_SOURCE_DIR}/idl/i11eperf.idl ${CMAKE_CURRENT_BINARY_DIR}/i11eperf_a.idl
DEPENDS ${CMAKE_SOURCE_DIR}/idl/i11eperf.idl)
idlc_generate(TARGET i11eperf_a FILES ${CMAKE_CURRENT_BINARY_DIR}/i11eperf_a.idl)
add_executable(apub src/apub.c)
add_executable(asub src/asub.c)
target_compile_definitions(apub PUBLIC CYCLONEDDS)
target_compile_definitions(asub PUBLIC CYCLONEDDS)
target_link_libraries(apub i11eperf_a CycloneDDS::ddsc)
target_link_libraries(asub i11eperf_a CycloneDDS::ddsc)
add_custom_target(roudi_toml ALL)
add_custom_command(
TARGET roudi_toml POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_LIST_DIR}/roudi.toml
${CMAKE_CURRENT_BINARY_DIR}/roudi.toml)
else()
message(STATUS "CycloneDDS not found")
endif()
### Cyclone DDS / C++
find_package(CycloneDDS-CXX QUIET)
if(CycloneDDS-CXX_FOUND)
message(STATUS "CycloneDDS C++ binding found")
idlcxx_generate(TARGET i11eperf_c FILES idl/i11eperf.idl)
add_executable(cpub src/cpub.cpp)
add_executable(csub src/csub.cpp)
add_executable(clpub src/clpub.cpp)
add_executable(clsub src/clsub.cpp)
target_compile_definitions(cpub PUBLIC CYCLONEDDS)
target_compile_definitions(csub PUBLIC CYCLONEDDS)
target_compile_definitions(clpub PUBLIC CYCLONEDDS)
target_compile_definitions(clsub PUBLIC CYCLONEDDS)
target_link_libraries(cpub i11eperf_c CycloneDDS-CXX::ddscxx)
target_link_libraries(csub i11eperf_c CycloneDDS-CXX::ddscxx)
target_link_libraries(clpub i11eperf_c CycloneDDS-CXX::ddscxx)
target_link_libraries(clsub i11eperf_c CycloneDDS-CXX::ddscxx)
else()
message(STATUS "CycloneDDS C++ binding not found")
endif()
### Fast-DDS
find_package(fastrtps QUIET)
if(fastrtps_FOUND)
message(STATUS "Fast-DDS found")
# Assuming FastDDS was built using colcon as described in the Fast-DDS docs
# we can make a reasonable guess at the location of fastddsgen
# (this is with or without the "--merge-install" option of colcon)
find_file(fastddsgen fastddsgen HINTS
${fastrtps_DIR}/../../../../../src/fastddsgen/scripts
${fastrtps_DIR}/../../../../src/fastddsgen/scripts)
if(fastddsgen STREQUAL "fastddsgen-NOTFOUND")
message(WARNING "Fast-DDS found, but fastddsgen not found, skipping Fast-DDS.
fastrtps_DIR = ${fastrtps_DIR}
try cmake -Dfastddsgen=PATH-TO-FASTDDSGEN")
else()
set(fidlgen i11eperf.cxx i11eperf.h i11eperfPubSubTypes.cxx i11eperfPubSubTypes.h)
list(TRANSFORM fidlgen PREPEND "${CMAKE_CURRENT_BINARY_DIR}/")
add_custom_command(
OUTPUT ${fidlgen}
COMMAND "${fastddsgen}"
ARGS -replace "${CMAKE_CURRENT_LIST_DIR}/idl/i11eperf.idl"
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/idl/i11eperf.idl")
add_library(i11eperf_f STATIC ${fidlgen})
target_include_directories(i11eperf_f PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${fastrtps_INCLUDE_DIR}" "${fastcdr_INCLUDE_DIR}")
add_executable(fpub src/fpub.cpp src/fcommon.cpp i11eperf.h)
add_executable(fsub src/fsub.cpp src/fcommon.cpp i11eperf.h)
target_compile_definitions(fpub PUBLIC FASTDDS)
target_compile_definitions(fsub PUBLIC FASTDDS)
target_link_libraries(fpub i11eperf_f fastrtps fastcdr foonathan_memory)
target_link_libraries(fsub i11eperf_f fastrtps fastcdr foonathan_memory)
endif()
else()
message(STATUS "Fast-DDS not found")
endif()
### OpenDDS
#
# - may need to use C++98 because on macOS at least the generated code depends on
# some template that in the OpenDDS binaries comes from the __1 namespace (I
# guess that's TR1), but that the application expects to come from the std
# namespace when built with C++11 or later
#
# - interoperability is really problematic ...
# - DCPSRTISerialization is needed
# - If you have a lot of patience and you enable tracing on the Cyclone side
# (presumably because it slows down things a bit) it works
# - FastDDS with OpenDDS results in "failed to deserialize data payload for SPDP"
# errors from OpenDDS
# - -Gxtypes-complete: following XTypes 7.6.3.2.1:
# "The field complete.typeid_with_size shall contain the COMPLETE Hash
# TypeIdentifier of the TopicType and the serialized size of the associated
# TypeObject."
# Cyclone DDS requires that both MINIMAL and COMPLETE type identifiers are
# present, or neither are. OpenDDS requires an IDL compiler option for that.
# - -Ddata_representation=::OpenDDS::data_representation: OpenDDS IDL compiler
# gives an error for @data_representation defined in XTypes 7.3.1.2.1.15 but
# has a seemingly equivalent thing in an OpenDDS module
find_package(OpenDDS QUIET)
if(OPENDDS_FOUND)
message(STATUS "OpenDDS found")
add_library(i11eperf_o)
#set_property(TARGET i11eperf_o PROPERTY CXX_STANDARD 98)
OPENDDS_TARGET_SOURCES(i11eperf_o idl/i11eperf.idl OPENDDS_IDL_OPTIONS
-Gxtypes-complete
-Ddata_representation=::OpenDDS::data_representation)
target_link_libraries(i11eperf_o OpenDDS::Dcps)
add_executable(opub src/opub.cpp)
add_executable(osub src/osub.cpp)
#set_property(TARGET opub PROPERTY CXX_STANDARD 98)
#set_property(TARGET osub PROPERTY CXX_STANDARD 98)
target_compile_definitions(opub PUBLIC OPENDDS)
target_compile_definitions(osub PUBLIC OPENDDS)
target_link_libraries(opub i11eperf_o OpenDDS::OpenDDS)
target_link_libraries(osub i11eperf_o OpenDDS::OpenDDS)
add_custom_target(opendds_ini ALL)
add_custom_command(
TARGET opendds_ini POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_LIST_DIR}/opendds.ini
${CMAKE_CURRENT_BINARY_DIR}/opendds.ini)
else()
message(STATUS "OpenDDS not found")
endif()
### OpenSplice
find_package(OpenSplice QUIET)
if(OpenSplice_FOUND)
message(STATUS "OpenSplice found")
# - need to remove @topic, add #pragma keylist
# - renaming to i11eperf_s.idl also addresses file name clashes
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/i11eperf_s.idl
COMMAND gawk
ARGS -f ${CMAKE_SOURCE_DIR}/preproc-ospl-idl.gawk ${CMAKE_SOURCE_DIR}/idl/i11eperf.idl > ${CMAKE_CURRENT_BINARY_DIR}/i11eperf_s.idl
DEPENDS ${CMAKE_SOURCE_DIR}/idl/i11eperf.idl ${CMAKE_SOURCE_DIR}/preproc-ospl-idl.gawk)
osplidl_generate(i11eperf_s ${CMAKE_CURRENT_BINARY_DIR}/i11eperf_s.idl)
add_executable(spub src/cpub.cpp)
add_executable(ssub src/csub.cpp)
target_compile_definitions(spub PUBLIC OPENSPLICE)
target_compile_definitions(ssub PUBLIC OPENSPLICE)
target_link_libraries(spub i11eperf_s OpenSplice::cxx)
target_link_libraries(ssub i11eperf_s OpenSplice::cxx)
else()
message(STATUS "OpenSplice not found")
endif()