forked from jrl-umi3218/jrl-cmakemodules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidl.cmake
202 lines (187 loc) · 7.67 KB
/
idl.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
# Copyright (C) 2008-2014 LAAS-CNRS, JRL AIST-CNRS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#.rst:
# .. command:: OMNIIDL_INCLUDE_DIRECTORIES (DIRECTORIES)
#
# Set include directories for omniidl
#
# :param DIRECTORIES: a list of directories to search for idl files.
#
MACRO (OMNIIDL_INCLUDE_DIRECTORIES)
SET (_OMNIIDL_INCLUDE_FLAG "")
FOREACH (DIR ${ARGV})
SET (_OMNIIDL_INCLUDE_FLAG ${_OMNIIDL_INCLUDE_FLAG}
-I${DIR} " "
)
ENDFOREACH ()
STRING (REGEX REPLACE " " ";" _OMNIIDL_INCLUDE_FLAG ${_OMNIIDL_INCLUDE_FLAG})
ENDMACRO ()
#.rst:
# .. command:: GENERATE_IDL_CPP (FILENAME DIRECTORY)
#
# Generate C++ stubs from an idl file.
# An include directory can also be specified.
# The filename of the generated file is appended to ``ALL_IDL_CPP_STUBS``.
#
# In CMake, *source file properties are visible only to targets added in the
# same directory (CMakeLists.txt)*. As a result, we cannot provide a single
# macro that takes care of generating the files and ensures a proper build
# dependency graph.
#
# .. warning::
# It is your responsibility to make sure the target dependency tree
# is correct. For instance with::
#
# ADD_CUSTOM_TARGET(generate_idl_cpp DEPENDS ${ALL_IDL_CPP_STUBS})
# ADD_DEPENDENCIES (my-library generate_idl_cpp)
#
# For more information:
# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_add_a_dependency_to_a_source_file_which_is_generated_in_a_subdirectory.3F
#
# :param FILENAME: IDL filename without the extension.
# Can be prefixed by a path: _path/_filename
# :param DIRECTORY: IDL directory.
# The idl file being search for is: ``${DIRECTORY}/${_filename}.idl``
# :param ENABLE_Wba: Option to trigger generation of code for TypeCode and Any.
# :param HEADER_SUFFIX: Set option -Wbh of omniidl
# :param NO_DEFAULT: Do not add default arguments to omniidl (``-Wbkeep_inc_path``)
# :param ARGUMENTS: The following words are passed as arguments to omniidl
#
MACRO(GENERATE_IDL_CPP FILENAME DIRECTORY)
SET(options ENABLE_Wba NO_DEFAULT)
SET(oneValueArgs HEADER_SUFFIX)
SET(multiValueArgs ARGUMENTS)
CMAKE_PARSE_ARGUMENTS(_omni "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
IF(NOT DEFINED _omni_HEADER_SUFFIX)
SET(_omni_HEADER_SUFFIX ".hh")
ENDIF()
GET_FILENAME_COMPONENT (_PATH ${FILENAME} PATH)
GET_FILENAME_COMPONENT (_NAME ${FILENAME} NAME)
IF (_PATH STREQUAL "")
SET(_PATH "./")
ENDIF (_PATH STREQUAL "")
FIND_PROGRAM(OMNIIDL omniidl)
IF(${OMNIIDL} STREQUAL OMNIIDL-NOTFOUND)
MESSAGE(FATAL_ERROR "cannot find omniidl.")
ENDIF(${OMNIIDL} STREQUAL OMNIIDL-NOTFOUND)
SET(IDL_COMPILED_FILES ${FILENAME}SK.cc ${FILENAME}${_omni_HEADER_SUFFIX})
SET(_omniidl_args -bcxx ${_OMNIIDL_INCLUDE_FLAG} -Wbh=${_omni_HEADER_SUFFIX} ${_omni_ARGUMENTS})
# This is to keep backward compatibility
IF(NOT _omni_NO_DEFAULT)
SET(_omniidl_args ${_omniidl_args} -Wbkeep_inc_path)
ENDIF()
IF(_omni_ENABLE_Wba)
SET(_omniidl_args ${_omniidl_args} -Wba)
SET(IDL_COMPILED_FILES ${IDL_COMPILED_FILES} ${FILENAME}DynSK.cc)
ENDIF(_omni_ENABLE_Wba)
ADD_CUSTOM_COMMAND(
OUTPUT ${IDL_COMPILED_FILES}
COMMAND ${OMNIIDL}
ARGS ${_omniidl_args} -C${_PATH} ${DIRECTORY}/${_NAME}.idl
MAIN_DEPENDENCY ${DIRECTORY}/${_NAME}.idl
COMMENT "Generating C++ stubs for ${_NAME}"
)
LIST(APPEND ALL_IDL_CPP_STUBS ${IDL_COMPILED_FILES})
# Clean generated files.
SET_PROPERTY(
DIRECTORY APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES
${IDL_COMPILED_FILES}
)
SET_PROPERTY(SOURCE ${IDL_COMPILED_FILES}
APPEND_STRING PROPERTY
COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual -Wno-unused-variable -Wno-unused-parameter")
LIST(APPEND LOGGING_WATCHED_VARIABLES OMNIIDL ALL_IDL_CPP_STUBS)
ENDMACRO(GENERATE_IDL_CPP FILENAME DIRECTORY)
#.rst:
# .. command:: GENERATE_IDL_PYTHON (FILENAME DIRECTORY)
#
# Generate Python stubs from an idl file.
# An include directory can also be specified.
# The filename of the generated file is appended to ``ALL_IDL_PYTHON_STUBS``.
#
# In CMake, *source file properties are visible only to targets added in the
# same directory (CMakeLists.txt)*. As a result, we cannot provide a single
# macro that takes care of generating the files and ensures a proper build
# dependency graph.
#
# .. warning::
# It is your responsibility to make sure the target dependency tree
# is correct. For instance with::
#
# ADD_CUSTOM_TARGET(generate_idl_python DEPENDS ${ALL_IDL_PYTHON_STUBS})
# ADD_DEPENDENCIES (my-library generate_idl_python)
#
# For more information:
# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_add_a_dependency_to_a_source_file_which_is_generated_in_a_subdirectory.3F
#
# :param FILENAME: IDL filename without the extension.
# Can be prefixed by a path: _path/_filename
# :param DIRECTORY: IDL directory.
# The idl file being search for is: ``${DIRECTORY}/${_filename}.idl``
# :param ARGUMENTS: The following words are passed as arguments to omniidl
# :param ENABLE_DOCSTRING: generate docstrings from doxygen comments (only in Python 3)
# :param STUBS: set option -Wbstubs of omniidl.
#
MACRO(GENERATE_IDL_PYTHON FILENAME DIRECTORY)
SET(options ENABLE_DOCSTRING)
SET(oneValueArgs STUBS)
SET(multiValueArgs ARGUMENTS)
CMAKE_PARSE_ARGUMENTS(_omni "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
GET_FILENAME_COMPONENT (_PATH ${FILENAME} PATH)
GET_FILENAME_COMPONENT (_NAME ${FILENAME} NAME)
IF (_PATH STREQUAL "")
SET(_PATH "./")
ENDIF (_PATH STREQUAL "")
FIND_PROGRAM(OMNIIDL omniidl)
IF(${OMNIIDL} STREQUAL OMNIIDL-NOTFOUND)
MESSAGE(FATAL_ERROR "cannot find omniidl.")
ENDIF(${OMNIIDL} STREQUAL OMNIIDL-NOTFOUND)
IF(_omni_ENABLE_DOCSTRING AND PYTHON_VERSION_MAJOR EQUAL 3)
SET(_omniidl_args -p${CMAKE_SOURCE_DIR}/cmake/hpp/idl -bomniidl_be_python_with_docstring -K)
ELSE()
SET(_omniidl_args -bpython)
ENDIF()
SET(_omniidl_args ${_omniidl_args} ${_OMNIIDL_INCLUDE_FLAG} -C${_PATH} ${_omni_ARGUMENTS})
IF(DEFINED _omni_STUBS)
SET(_omniidl_args ${_omniidl_args} -Wbstubs=${_omni_STUBS})
STRING(REPLACE "." "/" _omni_STUBS_DIR ${_omni_STUBS})
ENDIF()
SET(output_files ${CMAKE_CURRENT_BINARY_DIR}/${_PATH}/${_omni_STUBS_DIR}/${FILENAME}_idl.py)
ADD_CUSTOM_COMMAND(
OUTPUT ${output_files}
COMMAND ${OMNIIDL}
ARGS ${_omniidl_args}
${DIRECTORY}/${_NAME}.idl
MAIN_DEPENDENCY ${DIRECTORY}/${_NAME}.idl
COMMENT "Generating Python stubs for ${_NAME}"
)
LIST(APPEND ALL_IDL_PYTHON_STUBS ${output_files})
# Clean generated files.
SET_PROPERTY(
DIRECTORY APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES
${output_files}
)
LIST(APPEND LOGGING_WATCHED_VARIABLES OMNIIDL ALL_IDL_PYTHON_STUBS)
ENDMACRO(GENERATE_IDL_PYTHON FILENAME DIRECTORY)
# GENERATE_IDL_FILE FILENAME DIRECTORY
# ------------------------------------
#
# Legacy macro, now replaced by GENERATE_IDL_CPP.
MACRO(GENERATE_IDL_FILE FILENAME DIRECTORY)
MESSAGE(FATAL_ERROR
"GENERATE_IDL_FILE has been removed. Please use GENERATE_IDL_CPP instead.")
ENDMACRO(GENERATE_IDL_FILE FILENAME DIRECTORY)