QDBusPendingCallPrivate: save 8 bytes on 64-bit archs
[profile/ivi/qtbase.git] / src / dbus / Qt5DBusMacros.cmake
1 #=============================================================================
2 # Copyright 2005-2011 Kitware, Inc.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 #   notice, this list of conditions and the following disclaimer.
11 #
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.
15 #
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.
19 #
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 #=============================================================================
32
33 include(MacroAddFileDependencies)
34
35
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")
41
42     get_source_file_property(_nonamespace ${_interface} NO_NAMESPACE)
43     if(_nonamespace)
44         set(_params -N -m)
45     else()
46         set(_params -m)
47     endif()
48
49     get_source_file_property(_classname ${_interface} CLASSNAME)
50     if(_classname)
51         set(_params ${_params} -c ${_classname})
52     endif()
53
54     get_source_file_property(_include ${_interface} INCLUDE)
55     if(_include)
56         set(_params ${_params} -i ${_include})
57     endif()
58
59     add_custom_command(OUTPUT "${_impl}" "${_header}"
60         COMMAND ${Qt5DBus_QDBUSXML2CPP_EXECUTABLE} ${_params} -p ${_basename} ${_infile}
61         DEPENDS ${_infile} VERBATIM)
62
63     set_source_files_properties("${_impl}" PROPERTIES SKIP_AUTOMOC TRUE)
64
65     qt5_generate_moc("${_header}" "${_moc}")
66
67     list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
68     macro_add_file_dependencies("${_impl}" "${_moc}")
69     set(${_sources} ${${_sources}} PARENT_SCOPE)
70 endfunction()
71
72
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)
81     endforeach()
82     set(${_sources} ${${_sources}} PARENT_SCOPE)
83 endfunction()
84
85
86 function(QT5_GENERATE_DBUS_INTERFACE _header) # _customName OPTIONS -some -options )
87     set(options)
88     set(oneValueArgs)
89     set(multiValueArgs OPTIONS)
90
91     cmake_parse_arguments(_DBUS_INTERFACE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
92
93     set(_customName ${_DBUS_INTERFACE_UNPARSED_ARGUMENTS})
94     set(_qt4_dbus_options ${_DBUS_INTERFACE_OPTIONS})
95
96     get_filename_component(_in_file ${_header} ABSOLUTE)
97     get_filename_component(_basename ${_header} NAME_WE)
98
99     if(_customName)
100         if(IS_ABSOLUTE ${_customName})
101           get_filename_component(_containingDir ${_customName} PATH)
102           if(NOT EXISTS ${_containingDir})
103               file(MAKE_DIRECTORY "${_containingDir}")
104           endif()
105           set(_target ${_customName})
106         else()
107             set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_customName})
108         endif()
109     else()
110         set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.xml)
111     endif()
112
113     add_custom_command(OUTPUT ${_target}
114         COMMAND ${Qt5DBus_QDBUSCPP2XML_EXECUTABLE} ${_qt4_dbus_options} ${_in_file} -o ${_target}
115         DEPENDS ${_in_file} VERBATIM
116     )
117 endfunction()
118
119
120 function(QT5_ADD_DBUS_ADAPTOR _sources _xml_file _include _parentClass) # _optionalBasename _optionalClassName)
121     get_filename_component(_infile ${_xml_file} ABSOLUTE)
122
123     set(_optionalBasename "${ARGV4}")
124     if(_optionalBasename)
125         set(_basename ${_optionalBasename} )
126     else()
127         string(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2adaptor" _basename ${_infile})
128         string(TOLOWER ${_basename} _basename)
129     endif()
130
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")
135
136     if(_optionalClassName)
137         add_custom_command(OUTPUT "${_impl}" "${_header}"
138           COMMAND ${Qt5DBus_QDBUSXML2CPP_EXECUTABLE} -m -a ${_basename} -c ${_optionalClassName} -i ${_include} -l ${_parentClass} ${_infile}
139           DEPENDS ${_infile} VERBATIM
140         )
141     else()
142         add_custom_command(OUTPUT "${_impl}" "${_header}"
143           COMMAND ${Qt5DBus_QDBUSXML2CPP_EXECUTABLE} -m -a ${_basename} -i ${_include} -l ${_parentClass} ${_infile}
144           DEPENDS ${_infile} VERBATIM
145         )
146     endif()
147
148     qt5_generate_moc("${_header}" "${_moc}")
149     set_source_files_properties("${_impl}" PROPERTIES SKIP_AUTOMOC TRUE)
150     macro_add_file_dependencies("${_impl}" "${_moc}")
151
152     list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
153     set(${_sources} ${${_sources}} PARENT_SCOPE)
154 endfunction()