forked from OpenDDS/OpenDDS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenDDSConfig.cmake
581 lines (499 loc) · 15.5 KB
/
OpenDDSConfig.cmake
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
# Distributed under the OpenDDS License. See accompanying LICENSE
# file or http://www.opendds.org/license.html for details.
#.rst:
# OpenDDS CMake Config-File Package
# ---------------------------------
#
# Finds OpenDDS MPC-Compiled libraries and imports them as CMake targets.
#
# The following imported targets will be defined if the corresponding libraries
# were compiled with OpenDDS (using MPC):
#
# OpenDDS::OpenDDS - Convenience target which will loop-in most targets required
# for a typical OpenDDS scenario:
# * OpenDDS::Dcps
# * OpenDDS::Multicast
# * OpenDDS::Rtps
# * OpenDDS::Rtps_Udp
# * OpenDDS::InfoRepoDiscovery
# * OpenDDS::Shmem
# * OpenDDS::Tcp
# * OpenDDS::Udp
# * OpenDDS::Security if OpenDDS is built with security
#
# OpenDDS::<LIB> - Target for specific library dependency that was generated by
# compiling OpenDDS. These will generally be located in the
# $DDS_ROOT/lib directory. For example, OpenDDS_Dcps(d).so/.dll
# will be imported as the OpenDDS::Dcps CMake target.
#
# ACE::ACE - Target for the core ACE library.
#
# ACE::<LIB> - Similar to OpenDDS::<LIB> except typically these sit in the
# $ACE_ROOT/lib directory with files like ACE_XML_Utils(d).so/.dll
# getting imported as ACE::XML_Utils.
#
# TAO::TAO - Target for the core TAO library.
#
# TAO::<LIB> - Similar to OpenDDS::<LIB> except typically these sit in the
# $ACE_ROOT/lib directory (note: not $TAO_ROOT/lib) with files like
# TAO_PortableServer(d).so/.dll getting imported as TAO::PortableServer.
#
# In addition to the imported targets above the following macro will be important
# for adding IDL sources to a given target.
#
# OPENDDS_TARGET_SOURCES(target
# [items...]
# [<INTERFACE|PUBLIC|PRIVATE> items...]
# [TAO_IDL_OPTIONS options...]
# [OPENDDS_IDL_OPTIONS options...])
#
# This macro behaves similarly to target_sources(...) with the following
# differences:
# 1) Items are IDL sources instead of C/C++ sources.
# 2) The scope-qualifier (PUBLIC, PRIVATE, INTERFACE) is not required.
# When it is omitted, PRIVATE is used by default.
# 3) Command-line options can be supplied to the TAO/OpenDDS IDL compilers
# using TAO_IDL_OPTIONS and/or OPENDDS_IDL_OPTIONS (if the default be-
# havior is not suitable).
#
# When IDL sources are supplied, custom commands are generated which will
# be invoked to compile the IDL sources into their component cpp/h files.
#
# NOTE: C/C++ items can also be accepted and added to the target, but passing
# non-IDL sources was deprecated in OpenDDS 3.15.
#
# A custom command will also be added to generate the required IDL export
# header file (*target*_export.h) to add the required export macros. This
# file is then added as a dependency for the supplied target.
#
cmake_minimum_required(VERSION 3.3.2)
if(OpenDDS_FOUND)
return()
endif()
include(${CMAKE_CURRENT_LIST_DIR}/init.cmake)
## Adding ${TAO_BIN_DIR} to the ace bin hints allows users of
## VxWorks layer builds to set TAO_BIN_DIR to the location of
## the partner host tools directory, but keep ACE_BIN_DIR the
## value of $ACE_ROOT so that other ACE related scripts can
## be located.
set(_dds_bin_hints ${OPENDDS_BIN_DIR})
set(_ace_bin_hints ${ACE_BIN_DIR} ${TAO_BIN_DIR})
set(_tao_bin_hints ${TAO_BIN_DIR})
find_program(PERL perl)
find_program(OPENDDS_IDL
NAMES
opendds_idl
HINTS
${_dds_bin_hints}
)
find_program(TAO_IDL
NAMES
tao_idl
HINTS
${_tao_bin_hints}
)
find_program(ACE_GPERF
NAMES
ace_gperf
HINTS
${_ace_bin_hints}
)
enable_language(C)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(OPENDDS_SECURITY)
find_package(OpenSSL PATHS "${OPENDDS_OPENSSL}" NO_DEFAULT_PATH)
if (NOT OpenSSL_FOUND)
set(OPENSSL_ROOT_DIR "${OPENDDS_OPENSSL}")
find_package(OpenSSL)
endif()
if (NOT OpenSSL_FOUND)
message(FATAL_ERROR "Could not find OpenSSL")
endif()
if(NOT OPENDDS_XERCES3)
set(OPENDDS_XERCES3 ON)
endif()
endif()
if(OPENDDS_XERCES3)
find_package(XercesC PATHS "${OPENDDS_XERCES3}" NO_DEFAULT_PATH)
if (NOT XercesC_FOUND)
find_package(XercesC)
endif()
if (NOT XercesC_FOUND)
message(FATAL_ERROR "Could not find XercesC")
endif()
endif()
set(_ace_libs
ACE
)
if(OPENDDS_XERCES3)
list(APPEND _ace_libs ACE_XML_Utils)
endif()
set(_tao_libs
TAO_IORManip
TAO_ImR_Client
TAO_Svc_Utils
TAO_IORTable
TAO_IDL_FE
TAO_PortableServer
TAO_BiDirGIOP
TAO_PI
TAO_CodecFactory
TAO_Valuetype
TAO_AnyTypeCode
TAO
)
set(_opendds_libs
OpenDDS_Dcps
OpenDDS_FACE
OpenDDS_Federator
OpenDDS_InfoRepoDiscovery
OpenDDS_InfoRepoLib
OpenDDS_InfoRepoServ
OpenDDS_Model
OpenDDS_monitor
OpenDDS_Multicast
OpenDDS_Rtps
OpenDDS_Rtps_Udp
OpenDDS_Shmem
OpenDDS_Tcp
OpenDDS_Udp
)
if(OPENDDS_SECURITY)
list(APPEND _opendds_libs OpenDDS_QOS_XML_XSC_Handler OpenDDS_Security)
endif()
list(APPEND _all_libs ${_opendds_libs} ${_ace_libs} ${_tao_libs})
set(ACE_DEPS
Threads::Threads
)
macro(_OPENDDS_SYSTEM_LIBRARY name)
list(APPEND ACE_DEPS ${name})
string(TOUPPER "${name}" _cap_name)
if((${ARGC} GREATER 1) AND ("${ARGV1}" STREQUAL "NO_CHECK"))
set(${_cap_name}_LIBRARY ${name})
else()
find_library(${_cap_name}_LIBRARY ${name})
endif()
list(APPEND _opendds_required_deps ${_cap_name}_LIBRARY)
endmacro()
if(UNIX)
_OPENDDS_SYSTEM_LIBRARY(dl)
if(NOT APPLE)
_OPENDDS_SYSTEM_LIBRARY(rt)
endif()
elseif(MSVC)
# For some reason CMake can't find this in some cases, but we know it should
# be there, so just link to it without a check.
_OPENDDS_SYSTEM_LIBRARY(iphlpapi NO_CHECK)
endif()
if(OPENDDS_XERCES3)
set(ACE_XML_UTILS_DEPS
ACE::ACE
XercesC::XercesC
)
endif()
set(OPENDDS_IDL_DEPS
TAO::IDL_FE
ACE::ACE
)
set(OPENDDS_DCPS_DEPS
TAO::PortableServer
TAO::BiDirGIOP
TAO::PI
TAO::CodecFactory
TAO::Valuetype
TAO::AnyTypeCode
TAO::TAO
ACE::ACE
)
set(OPENDDS_FACE_DEPS
OpenDDS::Dcps
)
set(OPENDDS_FEDERATOR_DEPS
OpenDDS::InfoRepoLib
)
set(OPENDDS_INFOREPODISCOVERY_DEPS
OpenDDS::Tcp
OpenDDS::Dcps
)
set(OPENDDS_INFOREPOLIB_DEPS
OpenDDS::InfoRepoDiscovery
TAO::Svc_Utils
TAO::ImR_Client
TAO::IORManip
TAO::IORTable
)
set(OPENDDS_INFOREPOSERV_DEPS
OpenDDS::Federator
)
set(OPENDDS_MODEL_DEPS
OpenDDS::Dcps
)
set(OPENDDS_MONITOR_DEPS
OpenDDS::Dcps
)
set(OPENDDS_MULTICAST_DEPS
OpenDDS::Dcps
)
set(OPENDDS_QOS_XML_XSC_HANDLER_DEPS
OpenDDS::Dcps
ACE::XML_Utils
)
set(OPENDDS_RTPS_DEPS
OpenDDS::Dcps
)
set(OPENDDS_RTPS_UDP_DEPS
OpenDDS::Rtps
)
set(OPENDDS_SECURITY_DEPS "")
if(OPENDDS_SECURITY)
list(APPEND OPENDDS_SECURITY_DEPS
OpenDDS::Rtps
ACE::XML_Utils
OpenSSL::SSL
OpenSSL::Crypto
)
endif()
set(OPENDDS_SHMEM_DEPS
OpenDDS::Dcps
)
set(OPENDDS_TCP_DEPS
OpenDDS::Dcps
)
set(OPENDDS_UDP_DEPS
OpenDDS::Dcps
)
foreach(_lib ${_opendds_libs})
string(TOUPPER ${_lib} _lib)
if(NOT DEFINED "${_lib}_DEPS")
message(FATAL_ERROR "OpenDDS lib ${_lib} is missing a dependency list!")
endif()
endforeach()
macro(opendds_vs_force_static)
# See https://gitlab.kitware.com/cmake/community/wikis/FAQ#dynamic-replace
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
endforeach()
endmacro()
if(MSVC AND OPENDDS_STATIC)
opendds_vs_force_static()
endif()
function(opendds_find_our_libraries_for_config config suffix)
if(MSVC AND OPENDDS_STATIC)
set(suffix "s${suffix}")
endif()
macro(find_library_group lib_group_name libs)
set(lib_dir "${${lib_group_name}_LIB_DIR}")
foreach(lib ${libs})
set(lib_file_base "${lib}${suffix}")
string(TOUPPER ${lib} var_prefix)
set(lib_var "${var_prefix}_LIBRARY_${config}")
find_library(${lib_var} "${lib_file_base}" HINTS "${lib_dir}")
set(found_var "${var_prefix}_LIBRARY_FOUND")
if(${lib_var})
set(${found_var} TRUE PARENT_SCOPE)
# Workaround https://gitlab.kitware.com/cmake/cmake/-/issues/23249
# These paths might be symlinks and IMPORTED_RUNTIME_ARTIFACTS seems to
# copy symlinks verbatim, so resolve them now.
set(lib_var_real "${lib_var}_REAL")
get_filename_component(${lib_var_real} "${${lib_var}}" REALPATH)
# find_library makes cache variables, so we have to override it.
set(${lib_var} "${${lib_var_real}}" CACHE FILEPATH "" FORCE)
if(MSVC AND NOT OPENDDS_STATIC)
# find_library finds the ".lib" file on Windows, but if OpenDDS is not
# static we also need the ".dll" file for IMPORTED_LOCATION and
# IMPORTED_RUNTIME_ARTIFACTS to work correctly.
find_file("${lib_var}_DLL" "${lib_file_base}.dll" HINTS "${lib_dir}")
endif()
elseif(NOT DEFINED ${found_var})
set(${found_var} FALSE PARENT_SCOPE)
endif()
endforeach()
endmacro()
find_library_group("ACE" "${_ace_libs}")
find_library_group("TAO" "${_tao_libs}")
find_library_group("OPENDDS" "${_opendds_libs}")
endfunction()
if(MSVC)
opendds_find_our_libraries_for_config("RELEASE" "")
opendds_find_our_libraries_for_config("DEBUG" "d")
elseif(OPENDDS_DEBUG)
opendds_find_our_libraries_for_config("DEBUG" "")
else()
opendds_find_our_libraries_for_config("RELEASE" "")
endif()
include(SelectLibraryConfigurations)
foreach(_lib ${_all_libs})
string(TOUPPER ${_lib} _LIB_VAR)
select_library_configurations(${_LIB_VAR})
endforeach()
list(APPEND _opendds_required_deps
OPENDDS_DCPS_LIBRARY
OPENDDS_IDL
ACE_LIBRARY
ACE_GPERF
TAO_LIBRARY
TAO_IDL
PERL
)
foreach(_dep ${_opendds_required_deps})
if(NOT ${_dep})
list(APPEND _opendds_missing_deps ${_dep})
endif()
endforeach()
if(_opendds_missing_deps)
_OPENDDS_RETURN_ERR("Missing required dependencies ${_opendds_missing_deps}")
else()
set(OPENDDS_FOUND TRUE)
endif()
macro(_OPENDDS_ADD_TARGET_BINARY target path)
if (NOT TARGET ${target} AND EXISTS "${path}")
add_executable(${target} IMPORTED)
set_target_properties(${target}
PROPERTIES
IMPORTED_LOCATION "${path}"
)
endif()
endmacro()
function(opendds_add_library_group lib_group_name libs has_mononym)
string(TOUPPER ${lib_group_name} lib_group_var_prefix)
macro(add_target_library_config target var_prefix config)
set(lib_var "${var_prefix}_LIBRARY_${config}")
set(lib_file "${${lib_var}}")
if(EXISTS "${lib_file}")
set_property(TARGET ${target}
APPEND PROPERTY
IMPORTED_CONFIGURATIONS ${config}
)
# Set any extra compiler and linker options that are needed to use the
# libraries.
foreach(from_libs ALL "JUST_${lib_group_var_prefix}")
foreach(kind COMPILE LINK)
set(options_var "OPENDDS_${from_libs}_LIBS_INTERFACE_${kind}_OPTIONS")
if(DEFINED ${options_var})
set_property(TARGET ${target}
APPEND PROPERTY "INTERFACE_${kind}_OPTIONS" "${${options_var}}")
endif()
endforeach()
endforeach()
set(imploc "${lib_file}")
if(MSVC)
set_target_properties(${target}
PROPERTIES
"IMPORTED_IMPLIB_${config}" "${lib_file}"
)
set(dll "${lib_var}_DLL")
if(DEFINED "${dll}")
set(imploc "${${dll}}")
endif()
endif()
set_target_properties(${target}
PROPERTIES
"IMPORTED_LINK_INTERFACE_LANGUAGES_${config}" "CXX"
"IMPORTED_LOCATION_${config}" "${imploc}"
)
endif()
endmacro()
macro(add_target_library target var_prefix include_dirs)
if(NOT TARGET ${target} AND ${var_prefix}_LIBRARY_FOUND)
add_library(${target} ${OPENDDS_LIBRARY_TYPE} IMPORTED)
set_target_properties(${target}
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${include_dirs}"
INTERFACE_LINK_LIBRARIES "${${var_prefix}_DEPS}"
INTERFACE_COMPILE_DEFINITIONS "${OPENDDS_DCPS_COMPILE_DEFS}"
)
add_target_library_config(${target} ${var_prefix} "RELEASE")
add_target_library_config(${target} ${var_prefix} "DEBUG")
endif()
endmacro()
foreach(lib ${libs})
string(TOUPPER ${lib} var_prefix)
if(has_mononym AND lib STREQUAL "${lib_group_name}")
set(target "${lib_group_name}::${lib_group_name}")
else()
string(REPLACE "${lib_group_name}_" "${lib_group_name}::" target "${lib}")
endif()
add_target_library(${target} ${var_prefix} "${${lib_group_var_prefix}_INCLUDE_DIRS}")
endforeach()
endfunction()
if(OPENDDS_FOUND)
include("${CMAKE_CURRENT_LIST_DIR}/options.cmake")
_OPENDDS_ADD_TARGET_BINARY(opendds_idl "${OPENDDS_IDL}")
_OPENDDS_ADD_TARGET_BINARY(tao_idl "${TAO_IDL}")
_OPENDDS_ADD_TARGET_BINARY(ace_gperf "${ACE_GPERF}")
_OPENDDS_ADD_TARGET_BINARY(perl "${PERL}")
opendds_add_library_group("ACE" "${_ace_libs}" TRUE)
opendds_add_library_group("TAO" "${_tao_libs}" TRUE)
opendds_add_library_group("OpenDDS" "${_opendds_libs}" FALSE)
if(NOT TARGET OpenDDS::OpenDDS)
add_library(OpenDDS::OpenDDS INTERFACE IMPORTED)
set(_opendds_core_libs
OpenDDS::Dcps
OpenDDS::Multicast
OpenDDS::Rtps
OpenDDS::Rtps_Udp
OpenDDS::InfoRepoDiscovery
OpenDDS::Shmem
OpenDDS::Tcp
OpenDDS::Udp)
if(OPENDDS_SECURITY)
list(APPEND _opendds_core_libs OpenDDS::Security)
endif()
set_target_properties(OpenDDS::OpenDDS
PROPERTIES
INTERFACE_LINK_LIBRARIES "${_opendds_core_libs}")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/api_macros.cmake)
if(OPENDDS_CMAKE_VERBOSE)
message(STATUS "Loaded OpenDDS targets:")
foreach(_target ${OPENDDS_LIBRARIES})
get_target_property(_target_location ${_target} LOCATION)
message(STATUS "${_target} -> ${_target_location}")
endforeach()
endif()
## ACE provides (or uses) many deprecated functions.
## For now, we'll silence the warnings.
if(MSVC)
target_compile_options(ACE::ACE INTERFACE /wd4996)
target_compile_definitions(ACE::ACE INTERFACE
_CRT_SECURE_NO_WARNINGS
_WINSOCK_DEPRECATED_NO_WARNINGS)
endif()
endif()
function(opendds_get_library_var_prefix scoped_name var_prefix_var)
if(scoped_name STREQUAL "ACE::ACE")
set(var_prefix "ACE")
elseif(scoped_name STREQUAL "TAO::TAO")
set(var_prefix "TAO")
else()
string(TOUPPER ${scoped_name} var_prefix)
string(REPLACE "::" "_" var_prefix "${var_prefix}")
endif()
set(${var_prefix_var} ${var_prefix} PARENT_SCOPE)
endfunction()
function(opendds_get_library_dependencies deps_var lib)
set(libs "${lib}")
list(APPEND libs ${ARGN})
set(deps "${${deps_var}}")
foreach(lib ${libs})
if(NOT ${lib} IN_LIST deps)
string(REGEX MATCH "^(OpenDDS|ACE|TAO)::" re_out "${lib}")
if (CMAKE_MATCH_1)
set(ace_tao_opendds ${CMAKE_MATCH_1})
opendds_get_library_var_prefix(${lib} var_prefix)
set(dep_list_name "${var_prefix}_DEPS")
if(DEFINED ${dep_list_name})
opendds_get_library_dependencies(deps ${${dep_list_name}})
endif()
list(APPEND deps ${lib})
endif()
endif()
endforeach()
list(REMOVE_DUPLICATES deps)
set(${deps_var} "${deps}" PARENT_SCOPE)
endfunction()