forked from OpenDDS/OpenDDS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdds_idl_sources.cmake
216 lines (170 loc) · 7.71 KB
/
dds_idl_sources.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
# Distributed under the OpenDDS License. See accompanying LICENSE
# file or http://www.opendds.org/license.html for details.
include(${CMAKE_CURRENT_LIST_DIR}/tao_idl_sources.cmake)
function(opendds_target_generated_dependencies target idl_file scope)
get_source_file_property(idl_ts_files ${idl_file} OPENDDS_TYPESUPPORT_IDLS)
set(all_idl_files ${idl_file} ${idl_ts_files})
foreach(file ${all_idl_files})
get_source_file_property(cpps ${file} OPENDDS_CPP_FILES)
get_source_file_property(hdrs ${file} OPENDDS_HEADER_FILES)
list(APPEND cpp_files ${cpps})
list(APPEND hdr_files ${hdrs})
endforeach()
set(all_gen_files ${cpp_files} ${hdr_files} ${idl_ts_files})
set(all_files ${all_gen_files} ${idl_file})
get_source_file_property(bridge_target ${idl_file} OPENDDS_IDL_BRIDGE_TARGET)
if (NOT bridge_target)
# Each IDL file corresponds to one bridge target. All targets which depend
# upon the C/C++ files generated from IDL compilation will also depend upon
# the bridge target to guarantee that IDL files will compile prior to the
# dependent targets. This is simply set to the first IDL-Dependent target.
set(bridge_target ${target})
set_source_files_properties(${idl_file}
PROPERTIES
OPENDDS_IDL_BRIDGE_TARGET ${bridge_target})
set_source_files_properties(${all_idl_files} ${hdr_files}
PROPERTIES
HEADER_FILE_ONLY ON)
set_source_files_properties(${cpp_files}
PROPERTIES
SKIP_AUTOGEN ON)
source_group("Generated Files" FILES ${all_gen_files})
source_group("IDL Files" FILES ${idl_file})
endif()
add_dependencies(${target} ${bridge_target})
target_sources(${target} ${scope} ${cpp_files} ${all_idl_files} ${hdr_files})
foreach(file ${hdr_files})
get_target_property(target_includes ${target} INCLUDE_DIRECTORIES)
get_filename_component(file_path ${file} DIRECTORY)
if (NOT "${file_path}" IN_LIST target_includes)
target_include_directories(${target} PUBLIC ${file_path})
endif()
endforeach()
endfunction()
function(opendds_target_idl_sources target)
set(oneValueArgs SCOPE SKIP_TAO_IDL)
set(multiValueArgs TAO_IDL_FLAGS DDS_IDL_FLAGS IDL_FILES)
cmake_parse_arguments(_arg "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
foreach(idl_file ${_arg_IDL_FILES})
if (NOT IS_ABSOLUTE ${idl_file})
set(idl_file ${CMAKE_CURRENT_LIST_DIR}/${idl_file})
endif()
get_property(_generated_dependencies SOURCE ${idl_file}
PROPERTY OPENDDS_IDL_GENERATED_DEPENDENCIES SET)
if (_generated_dependencies)
# If an IDL-Generation command was already created this file can safely be
# skipped; however, the dependencies still need to be added to the target.
opendds_target_generated_dependencies(${target} ${idl_file} ${_arg_SCOPE})
else()
list(APPEND non_generated_idl_files ${idl_file})
endif()
endforeach()
if (NOT non_generated_idl_files)
return()
endif()
get_property(target_link_libs TARGET ${target} PROPERTY LINK_LIBRARIES)
if ("OpenDDS::FACE" IN_LIST target_link_libs)
foreach(_tao_face_flag -SS -Wb,no_fixed_err)
if (NOT "${_arg_TAO_IDL_FLAGS}" MATCHES "${_tao_face_flag}")
list(APPEND _arg_TAO_IDL_FLAGS ${_tao_face_flag})
endif()
endforeach()
foreach(_dds_face_flag -GfaceTS -Lface)
if (NOT "${_arg_DDS_IDL_FLAGS}" MATCHES "${_dds_face_flag}")
list(APPEND _arg_DDS_IDL_FLAGS ${_dds_face_flag})
endif()
endforeach()
endif()
file(RELATIVE_PATH working_dir ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_LIST_DIR})
if (NOT IS_ABSOLUTE "${working_dir}")
set(_working_binary_dir ${CMAKE_CURRENT_BINARY_DIR}/${working_dir})
set(_working_source_dir ${CMAKE_CURRENT_SOURCE_DIR}/${working_dir})
else()
set(_working_binary_dir ${working_dir})
set(_working_source_dir ${CMAKE_CURRENT_SOURCE_DIR})
endif()
## remove trailing slashes
string(REGEX REPLACE "/$" "" _working_binary_dir ${_working_binary_dir})
string(REGEX REPLACE "/$" "" _working_source_dir ${_working_source_dir})
## opendds_idl would generate different code with the -I flag followed by absolute path
## or relative path, if it's a relative path we need to keep it a relative path to the binary tree
file(RELATIVE_PATH _rel_path_to_source_tree ${_working_binary_dir} ${_working_source_dir})
if (_rel_path_to_source_tree)
set(_rel_path_to_source_tree "${_rel_path_to_source_tree}/")
endif ()
foreach(flag ${_arg_DDS_IDL_FLAGS})
if ("${flag}" MATCHES "^-I(\\.\\..*)")
list(APPEND _converted_dds_idl_flags -I${_rel_path_to_source_tree}${CMAKE_MATCH_1})
else()
list(APPEND _converted_dds_idl_flags ${flag})
endif()
endforeach()
set(_ddsidl_flags ${_converted_dds_idl_flags})
foreach(input ${non_generated_idl_files})
unset(_ddsidl_cmd_arg_-SI)
unset(_ddsidl_cmd_arg_-GfaceTS)
unset(_ddsidl_cmd_arg_-o)
unset(_ddsidl_cmd_arg_-Wb,java)
cmake_parse_arguments(_ddsidl_cmd_arg "-SI;-GfaceTS;-Wb,java" "-o" "" ${_ddsidl_flags})
get_filename_component(noext_name ${input} NAME_WE)
get_filename_component(abs_filename ${input} ABSOLUTE)
get_filename_component(file_ext ${input} EXT)
get_filename_component(idl_file_dir ${abs_filename} DIRECTORY)
if (_ddsidl_cmd_arg_-o)
set(output_prefix ${_working_binary_dir}/${_ddsidl_cmd_arg_-o}/${noext_name})
else()
set(output_prefix ${_working_binary_dir}/${noext_name})
endif()
if (NOT _ddsidl_cmd_arg_-SI)
set(_cur_type_support_idl ${output_prefix}TypeSupport.idl)
else()
unset(_cur_type_support_idl)
endif()
set(_cur_idl_headers ${output_prefix}TypeSupportImpl.h)
set(_cur_idl_cpp_files ${output_prefix}TypeSupportImpl.cpp)
if (_ddsidl_cmd_arg_-GfaceTS)
list(APPEND _cur_idl_headers ${output_prefix}C.h ${output_prefix}_TS.hpp)
list(APPEND _cur_idl_cpp_files ${output_prefix}_TS.cpp)
## if this is FACE IDL, do not reprocess the original idl file throught tao_idl
else()
set(_cur_idl_file ${input})
endif()
if (_ddsidl_cmd_arg_-Wb,java)
set(_cur_java_list "${output_prefix}${file_ext}.TypeSupportImpl.java.list")
list(APPEND file_dds_idl_flags -j)
else()
unset(_cur_java_list)
endif()
set(_cur_idl_outputs ${_cur_idl_headers} ${_cur_idl_cpp_files})
_tao_append_lib_dir_to_path(_tao_extra_lib_dirs)
add_custom_command(
OUTPUT ${_cur_idl_outputs} ${_cur_type_support_idl} ${_cur_java_list}
DEPENDS opendds_idl ${DDS_ROOT}/dds/idl/IDLTemplate.txt
MAIN_DEPENDENCY ${abs_filename}
COMMAND ${CMAKE_COMMAND} -E env "DDS_ROOT=${DDS_ROOT}" "TAO_ROOT=${TAO_INCLUDE_DIR}"
"${_tao_extra_lib_dirs}"
$<TARGET_FILE:opendds_idl> -I${_working_source_dir}
${_ddsidl_flags} ${file_dds_idl_flags} ${abs_filename}
WORKING_DIRECTORY ${_arg_WORKING_DIRECTORY}
)
set_property(SOURCE ${abs_filename} APPEND PROPERTY
OPENDDS_CPP_FILES ${_cur_idl_cpp_files})
set_property(SOURCE ${abs_filename} APPEND PROPERTY
OPENDDS_HEADER_FILES ${_cur_idl_headers})
set_property(SOURCE ${abs_filename} APPEND PROPERTY
OPENDDS_TYPESUPPORT_IDLS ${_cur_type_support_idl})
set_property(SOURCE ${abs_filename} APPEND PROPERTY
OPENDDS_JAVA_OUTPUTS "@${_cur_java_list}")
if (NOT _arg_SKIP_TAO_IDL)
tao_idl_command(${target}
IDL_FLAGS
-I${DDS_ROOT}
-I${idl_file_dir} # The type-support IDL will include the primary IDL file
${_arg_TAO_IDL_FLAGS}
IDL_FILES ${_cur_idl_file} ${_cur_type_support_idl})
endif()
set_property(SOURCE ${abs_filename} PROPERTY
OPENDDS_IDL_GENERATED_DEPENDENCIES TRUE)
opendds_target_generated_dependencies(${target} ${abs_filename} ${_arg_SCOPE})
endforeach()
endfunction()