1 #=============================================================================
2 # Copyright 2005-2011 Kitware, Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of Kitware, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #=============================================================================
33 include(MacroAddFileDependencies)
36 function(QT5_ADD_DBUS_INTERFACE _sources _interface _basename)
37 get_filename_component(_infile ${_interface} ABSOLUTE)
38 set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
39 set(_impl "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
40 set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
42 get_source_file_property(_nonamespace ${_interface} NO_NAMESPACE)
49 get_source_file_property(_classname ${_interface} CLASSNAME)
51 set(_params ${_params} -c ${_classname})
54 get_source_file_property(_include ${_interface} INCLUDE)
56 set(_params ${_params} -i ${_include})
59 add_custom_command(OUTPUT "${_impl}" "${_header}"
60 COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} ${_params} -p ${_basename} ${_infile}
61 DEPENDS ${_infile} VERBATIM)
63 set_source_files_properties("${_impl}" PROPERTIES SKIP_AUTOMOC TRUE)
65 qt5_generate_moc("${_header}" "${_moc}")
67 list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
68 macro_add_file_dependencies("${_impl}" "${_moc}")
69 set(${_sources} ${${_sources}} PARENT_SCOPE)
73 function(QT5_ADD_DBUS_INTERFACES _sources)
74 foreach(_current_FILE ${ARGN})
75 get_filename_component(_infile ${_current_FILE} ABSOLUTE)
76 get_filename_component(_basename ${_current_FILE} NAME)
77 # get the part before the ".xml" suffix
78 string(TOLOWER ${_basename} _basename)
79 string(REGEX REPLACE "(.*\\.)?([^\\.]+)\\.xml" "\\2" _basename ${_basename})
80 qt5_add_dbus_interface(${_sources} ${_infile} ${_basename}interface)
82 set(${_sources} ${${_sources}} PARENT_SCOPE)
86 function(QT5_GENERATE_DBUS_INTERFACE _header) # _customName OPTIONS -some -options )
89 set(multiValueArgs OPTIONS)
91 cmake_parse_arguments(_DBUS_INTERFACE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
93 set(_customName ${_DBUS_INTERFACE_UNPARSED_ARGUMENTS})
94 set(_qt4_dbus_options ${_DBUS_INTERFACE_OPTIONS})
96 get_filename_component(_in_file ${_header} ABSOLUTE)
97 get_filename_component(_basename ${_header} NAME_WE)
100 if(IS_ABSOLUTE ${_customName})
101 get_filename_component(_containingDir ${_customName} PATH)
102 if(NOT EXISTS ${_containingDir})
103 file(MAKE_DIRECTORY "${_containingDir}")
105 set(_target ${_customName})
107 set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_customName})
110 set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.xml)
113 add_custom_command(OUTPUT ${_target}
114 COMMAND ${QT_DBUSCPP2XML_EXECUTABLE} ${_qt4_dbus_options} ${_in_file} -o ${_target}
115 DEPENDS ${_in_file} VERBATIM
120 function(QT5_ADD_DBUS_ADAPTOR _sources _xml_file _include _parentClass) # _optionalBasename _optionalClassName)
121 get_filename_component(_infile ${_xml_file} ABSOLUTE)
123 set(_optionalBasename "${ARGV4}")
124 if(_optionalBasename)
125 set(_basename ${_optionalBasename} )
127 string(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2adaptor" _basename ${_infile})
128 string(TOLOWER ${_basename} _basename)
131 set(_optionalClassName "${ARGV5}")
132 set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
133 set(_impl "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
134 set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
136 if(_optionalClassName)
137 add_custom_command(OUTPUT "${_impl}" "${_header}"
138 COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} -m -a ${_basename} -c ${_optionalClassName} -i ${_include} -l ${_parentClass} ${_infile}
139 DEPENDS ${_infile} VERBATIM
142 add_custom_command(OUTPUT "${_impl}" "${_header}"
143 COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} -m -a ${_basename} -i ${_include} -l ${_parentClass} ${_infile}
144 DEPENDS ${_infile} VERBATIM
148 qt5_generate_moc("${_header}" "${_moc}")
149 set_source_files_properties("${_impl}" PROPERTIES SKIP_AUTOMOC TRUE)
150 macro_add_file_dependencies("${_impl}" "${_moc}")
152 list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
153 set(${_sources} ${${_sources}} PARENT_SCOPE)