Warning, /network/telepathy-logger-qt/cmake/modules/TpQtMacros.cmake is written in an unsupported language. File is not indexed.
0001 # - Common macros for Tp-Qt 0002 0003 # Copyright (c) 2010, Collabora Ltd. <http://www.collabora.co.uk/> 0004 # 0005 # Redistribution and use is allowed according to the terms of the BSD license. 0006 0007 # 0008 # These macros/functions are not exported - they are meant for internal usage into Telepathy-Qt's build system. 0009 # 0010 # Preamble: How dynamic generators are handled with the CMake build system. 0011 # Telepathy-Qt strongly relies upon lots of files generated at build time through some python programs, found 0012 # in tools/. To avoid developers the struggle of handling those manually, a set of convenience macros have been 0013 # created to handle them with the correct dependencies. Each of those macros takes a target name as a first argument 0014 # and creates a target with that exact name. In a similar fashion, in the last argument you can specify a list 0015 # of targets the generated target will depend on. This way, you can handle transparently dependencies between 0016 # generated files, while the dirty stuff is done for you in the background. 0017 # 0018 # macro TPQT_EXTRACT_DEPENDS (tpqt_other tpqt_depends) 0019 # Internal macro used to extract arguments from ARGN 0020 # 0021 # function TPQT_CREATE_MOC_COMMAND_TARGET_DEPS(inputfile outputfile moc_flags moc_options target_dependencies ...) 0022 # This function behaves exactly like qt_create_moc_command, but creates a custom target for the 0023 # moc file generation, allowing to specify a list of targets the generated moc target will depend on. 0024 # Just like qt_create_moc_command, it is an internal macro and it's not meant to be used explicitely. 0025 # 0026 # function TPQT_GENERATE_MOC_I(inputfile outputfile) 0027 # This function behaves exactly like qt_generate_moc, but it generates moc files with the -i option, 0028 # which disables the generation of an #include directive. This macro has to be used always when building 0029 # Tp-Qt internals due to the internal header files restrictions. 0030 # 0031 # function TPQT_GENERATE_MOC_I_TARGET_DEPS(inputfile outputfile target_dependencies ...) 0032 # This function acts as an overload to QT_GENERATE_MOC_I: it does exactly the same thing, but creates a 0033 # custom target for the moc file generation, and adds target_dependencies to it as dependencies. 0034 # 0035 # function TPQT_GENERATE_MOCS(sourcefile ...) 0036 # Generates mocs from a list of header files. You usually want to use this function when building tests 0037 # or examples. Please remember the list of the header files passed to this function MUST be added to the 0038 # target's sources. 0039 # 0040 # function TPQT_CLIENT_GENERATOR(spec group pretty_include namespace [arguments] [DEPENDS dependencies ...]) 0041 # This function takes care of invoking qt-client-gen.py with the correct arguments, which generates 0042 # headers out of specs. spec is the name of the spec headers will be generated from, group represents 0043 # the spec's group, pretty_include is the name of the capitalized header (for example ClientGenerator), 0044 # namespace is the C++ namespace the generated header will belong to. This function also accepts 0045 # as an optional last argument a list of additional command line arguments which will be passed to 0046 # qt-client-gen.py upon execution. After issuing DEPENDS in the last argument you can pass a list of targets 0047 # the generated target will depend on. 0048 # 0049 # function TPQT_FUTURE_CLIENT_GENERATOR(spec namespace [arguments] [DEPENDS dependencies ...]) 0050 # Same as tpqt_client_generator, but for future interfaces 0051 # 0052 # function TPQT_SERVICE_GENERATOR(spec group pretty_include namespace [arguments] [DEPENDS dependencies ...]) 0053 # This function takes care of invoking qt-svc-gen.py with the correct arguments, which generates 0054 # headers out of specs. spec is the name of the spec headers will be generated from, group represents 0055 # the spec's group, pretty_include is the name of the capitalized header (for example ServiceGenerator), 0056 # namespace is the C++ namespace the generated header will belong to. This function also accepts 0057 # as an optional last argument a list of additional command line arguments which will be passed to 0058 # qt-svc-gen.py upon execution. After issuing DEPENDS in the last argument you can pass a list of targets 0059 # the generated target will depend on. 0060 # 0061 # function TPQT_GENERATE_MANAGER_FILE(MANAGER_FILE OUTPUT_FILENAME DEPEND_FILENAME) 0062 # This function takes care of invoking manager-file.py with the correct arguments. The first argument is the 0063 # path to the manager-file.py file which should be used, the second is the output filename of the manager, 0064 # and the third is the path to the file which depends on the generated manager file. 0065 # 0066 # function TPQT_XINCLUDATOR (TARGET_NAME INPUT_FILE OUTPUT_FILE [additional_arguments ...] [DEPENDS dependencies ...]) 0067 # This function takes care of invoking xincludator.py with the correct arguments. TARGET_NAME is the name of 0068 # the generated target (see preamble), INPUT_FILE is the input spec file, OUTPUT_FILE is the filename 0069 # the generated file will be saved to. This function also accepts as an optional last argument a list of 0070 # additional command line arguments which will be passed to xincludator upon execution. 0071 # After issuing DEPENDS in the last argument you can pass a list of targets the generated target will depend on. 0072 # 0073 # function TPQT_CONSTANTS_GEN (TARGET_NAME SPEC_XML OUTPUT_FILE [additional_arguments ...] [DEPENDS dependencies ...]) 0074 # This function takes care of invoking qt-constants-gen.py with the correct arguments. TARGET_NAME is the name of 0075 # the generated target (see preamble), SPEC_XML is the spec input file, OUTPUT_FILE is the filename 0076 # the generated file will be saved to. This function also accepts as an optional last argument a list of 0077 # additional command line arguments which will be passed to qt-constants-gen.py upon execution. 0078 # After issuing DEPENDS in the last argument you can pass a list of targets the generated target will depend on. 0079 # 0080 # function TPQT_TYPES_GEN (TARGET_NAME SPEC_XML OUTFILE_DECL OUTFILE_IMPL NAMESPACE 0081 # REAL_INCLUDE PRETTY_INCLUDE [additional_arguments ...] [DEPENDS dependencies ...]) 0082 # This function takes care of invoking qt-types-gen.py with the correct arguments. TARGET_NAME is the name of 0083 # the generated target (see preamble), SPEC_XML is the input spec file, OUTFILE_DECL is the filename 0084 # the header of the generated file will be saved to, OUTFILE_IMPL is the filename the implementation of the 0085 # generated file will be saved to, NAMESPACE is the C++ namespace the generated header will belong to, 0086 # REAL_INCLUDE is the real include file you want to use, PRETTY_INCLUDE is the name of the capitalized header 0087 # (for example ClientGenerator). 0088 # This function also accepts as an optional last argument a list of additional command line arguments 0089 # which will be passed to qt-constants-gen.py upon execution. 0090 # After issuing DEPENDS in the last argument you can pass a list of targets the generated target will depend on. 0091 # 0092 # macro TPQT_ADD_GENERIC_UNIT_TEST (fancyName name [libraries ...]) 0093 # This macro takes care of building and adding a generic unit test to the automatic CTest suite. The requirement 0094 # for using this macro is to have the unit test contained in a single source file named ${name}.cpp. fancyName will 0095 # be used as the test and target's name, and you can specify as a third and optional argument a set of additional 0096 # libraries the target will link to. 0097 # 0098 # macro TPQT_ADD_DBUS_UNIT_TEST (fancyName name [libraries ...]) 0099 # This macro takes care of building and adding an unit test requiring DBus emulation to the automatic 0100 # CTest suite. The requirement for using this macro is to have the unit test contained in a single 0101 # source file named ${name}.cpp. fancyName will be used as the test and target's name, and you can specify as a third 0102 # and optional argument a set of additional libraries the target will link to. Please remember that you need to 0103 # set up the DBus environment by calling TPQT_SETUP_DBUS_TEST_ENVIRONMENT BEFORE you call this macro. 0104 # 0105 # macro _TPQT_ADD_CHECK_TARGETS (fancyName name command [args]) 0106 # This is an internal macro which is meant to be used by TPQT_ADD_DBUS_UNIT_TEST and TPQT_ADD_GENERIC_UNIT_TEST. 0107 # It takes care of generating a check target for each test method available (currently normal execution, valgrind and 0108 # callgrind). This macro accepts the same arguments as the add test macros, but accepts a command and a list of 0109 # arguments for running the test instead of the link libraries. However, you are not meant to call this macro from 0110 # your CMakeLists.txt files. 0111 # 0112 # function TPQT_SETUP_DBUS_TEST_ENVIRONMENT () 0113 # This function MUST be called before calling TPQT_ADD_DBUS_UNIT_TEST. It takes care of preparing the test 0114 # environment for DBus tests and generating the needed files. 0115 # 0116 # macro MAKE_INSTALL_PATH_ABSOLUTE (out in) 0117 # This macro makes the path given in the "in" variable absolute (or leaves it unchanged 0118 # if it's absolute already) by prefixing it with TELEPATHY_QT_INSTALL_DIR, 0119 # and returns the absolute path in the "out" variable. This macro is mainly used for 0120 # generating *Config.cmake files. 0121 # 0122 # 0123 0124 MACRO (TPQT_EXTRACT_DEPENDS _tpqt_other _tpqt_depends) 0125 SET(${_tpqt_other}) 0126 SET(${_tpqt_depends}) 0127 SET(_TPQT_DOING_DEPENDS FALSE) 0128 FOREACH(_currentArg ${ARGN}) 0129 IF ("${_currentArg}" STREQUAL "DEPENDS") 0130 SET(_TPQT_DOING_DEPENDS TRUE) 0131 ELSE ("${_currentArg}" STREQUAL "DEPENDS") 0132 IF(_TPQT_DOING_DEPENDS) 0133 LIST(APPEND ${_tpqt_depends} "${_currentArg}") 0134 ELSE(_TPQT_DOING_DEPENDS) 0135 LIST(APPEND ${_tpqt_other} "${_currentArg}") 0136 ENDIF(_TPQT_DOING_DEPENDS) 0137 ENDIF ("${_currentArg}" STREQUAL "DEPENDS") 0138 ENDFOREACH(_currentArg) 0139 ENDMACRO (TPQT_EXTRACT_DEPENDS) 0140 0141 # helper function to set up a moc rule 0142 FUNCTION (TPQT_CREATE_MOC_COMMAND_TARGET_DEPS infile outfile moc_flags moc_options) 0143 # For Windows, create a parameters file to work around command line length limit 0144 GET_FILENAME_COMPONENT(_moc_outfile_name "${outfile}" NAME) 0145 IF (WIN32) 0146 # Pass the parameters in a file. Set the working directory to 0147 # be that containing the parameters file and reference it by 0148 # just the file name. This is necessary because the moc tool on 0149 # MinGW builds does not seem to handle spaces in the path to the 0150 # file given with the @ syntax. 0151 GET_FILENAME_COMPONENT(_moc_outfile_dir "${outfile}" PATH) 0152 IF(_moc_outfile_dir) 0153 SET(_moc_working_dir WORKING_DIRECTORY ${_moc_outfile_dir}) 0154 ENDIF(_moc_outfile_dir) 0155 SET (_moc_parameters_file ${outfile}_parameters) 0156 SET (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}") 0157 FILE (REMOVE ${_moc_parameters_file}) 0158 FOREACH(arg ${_moc_parameters}) 0159 FILE (APPEND ${_moc_parameters_file} "${arg}\n") 0160 ENDFOREACH(arg) 0161 ADD_CUSTOM_COMMAND(OUTPUT ${outfile} 0162 COMMAND ${QT_MOC_EXECUTABLE} @${_moc_outfile_name}_parameters 0163 DEPENDS ${infile} 0164 ${_moc_working_dir} 0165 VERBATIM) 0166 ELSE (WIN32) 0167 ADD_CUSTOM_COMMAND(OUTPUT ${outfile} 0168 COMMAND ${QT_MOC_EXECUTABLE} 0169 ARGS ${moc_flags} ${moc_options} -o ${outfile} ${infile} 0170 DEPENDS ${infile}) 0171 ENDIF (WIN32) 0172 0173 add_custom_target(moc-${_moc_outfile_name} DEPENDS ${outfile}) 0174 add_dependencies(moc-${_moc_outfile_name} ${ARGN}) 0175 ENDFUNCTION (TPQT_CREATE_MOC_COMMAND_TARGET_DEPS) 0176 0177 # add the -i option to QT_GENERATE_MOC 0178 function(TPQT_GENERATE_MOC_I infile outfile) 0179 qt5_get_moc_flags(moc_flags) 0180 get_filename_component(abs_infile ${infile} ABSOLUTE) 0181 qt5_create_moc_command(${abs_infile} ${outfile} "${moc_flags}" "-i") 0182 set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC TRUE) # dont run automoc on this file 0183 endfunction(TPQT_GENERATE_MOC_I) 0184 0185 # same as tpqt_generate_moc_i, but lets the caller specify a list of targets which the mocs should depend on 0186 function(TPQT_GENERATE_MOC_I_TARGET_DEPS infile outfile) 0187 qt5_get_moc_flags(moc_flags) 0188 get_filename_component(abs_infile ${infile} ABSOLUTE) 0189 tpqt_create_moc_command_target_deps(${abs_infile} ${outfile} "${moc_flags}" "-i" ${ARGN}) 0190 set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC TRUE) # dont run automoc on this file 0191 endfunction(TPQT_GENERATE_MOC_I_TARGET_DEPS) 0192 0193 # generates mocs for the passed list. The list should be added to the target's sources 0194 function(tpqt_generate_mocs) 0195 file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/_gen" ) 0196 foreach(moc_src ${ARGN}) 0197 string(REPLACE ".h" ".moc.hpp" generated_file ${moc_src}) 0198 tpqt_generate_moc_i(${CMAKE_CURRENT_SOURCE_DIR}/${moc_src} ${CMAKE_CURRENT_BINARY_DIR}/_gen/${generated_file}) 0199 set_property(SOURCE ${moc_src} APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/${generated_file}) 0200 endforeach(moc_src ${ARGN}) 0201 endfunction(tpqt_generate_mocs) 0202 0203 function(tpqt_client_generator spec group pretty_include namespace) 0204 tpqt_extract_depends(client_generator_args client_generator_depends ${ARGN}) 0205 set(ARGS 0206 ${CMAKE_SOURCE_DIR}/tools/qt-client-gen.py 0207 --group=${group} 0208 --namespace=${namespace} 0209 --typesnamespace=Tp 0210 --headerfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.h 0211 --implfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}-body.hpp 0212 --realinclude=TelepathyQt/${spec}.h 0213 --prettyinclude=TelepathyQt/${pretty_include} 0214 --specxml=${CMAKE_CURRENT_BINARY_DIR}/_gen/stable-spec.xml 0215 --ifacexml=${CMAKE_CURRENT_BINARY_DIR}/_gen/spec-${spec}.xml 0216 --extraincludes=${TYPES_INCLUDE} 0217 --must-define=IN_TP_QT_HEADER 0218 --visibility=TP_QT_EXPORT 0219 ${client_generator_args}) 0220 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.h ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}-body.hpp 0221 COMMAND ${PYTHON_EXECUTABLE} 0222 ARGS ${ARGS} 0223 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 0224 0225 DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py 0226 ${CMAKE_SOURCE_DIR}/tools/qt-client-gen.py) 0227 add_custom_target(generate_cli-${spec}-body DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}-body.hpp) 0228 add_dependencies(all-generated-sources generate_cli-${spec}-body) 0229 0230 if (client_generator_depends) 0231 add_dependencies(generate_cli-${spec}-body ${client_generator_depends}) 0232 endif (client_generator_depends) 0233 0234 tpqt_generate_moc_i_target_deps(${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.h 0235 ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.moc.hpp 0236 "generate_cli-${spec}-body") 0237 endfunction(tpqt_client_generator spec group pretty_include namespace) 0238 0239 function(tpqt_future_client_generator spec namespace) 0240 tpqt_extract_depends(future_client_generator_args future_client_generator_depends ${ARGN}) 0241 set(ARGS 0242 ${CMAKE_SOURCE_DIR}/tools/qt-client-gen.py 0243 --namespace=${namespace} 0244 --typesnamespace=TpFuture 0245 --headerfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.h 0246 --implfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}-body.hpp 0247 --realinclude=TelepathyQt/future-internal.h 0248 --prettyinclude=TelepathyQt/future-internal.h 0249 --specxml=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-spec.xml 0250 --ifacexml=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.xml 0251 --extraincludes=${TYPES_INCLUDE} 0252 --extraincludes='<TelepathyQt/Types>' 0253 --extraincludes='<TelepathyQt/future-internal.h>' 0254 --visibility=TP_QT_NO_EXPORT 0255 ${future_client_generator_args}) 0256 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.h ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}-body.hpp 0257 COMMAND ${PYTHON_EXECUTABLE} 0258 ARGS ${ARGS} 0259 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 0260 0261 DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py 0262 ${CMAKE_SOURCE_DIR}/tools/qt-client-gen.py) 0263 add_custom_target(generate_future-${spec}-body DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}-body.hpp) 0264 add_dependencies(all-generated-sources generate_future-${spec}-body) 0265 0266 if (future_client_generator_depends) 0267 add_dependencies(generate_future-${spec}-body ${future_client_generator_depends}) 0268 endif (future_client_generator_depends) 0269 0270 tpqt_generate_moc_i_target_deps(${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.h 0271 ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.moc.hpp 0272 "generate_future-${spec}-body") 0273 endfunction(tpqt_future_client_generator spec namespace) 0274 0275 function(tpqt_service_generator spec group pretty_include namespace) 0276 tpqt_extract_depends(service_generator_args service_generator_depends ${ARGN}) 0277 string(REPLACE "svc-" "" spec ${spec}) 0278 set(ARGS 0279 ${CMAKE_SOURCE_DIR}/tools/qt-svc-gen.py 0280 --group=${group} 0281 --namespace=${namespace} 0282 --typesnamespace=Tp 0283 --headerfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.h 0284 --implfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.cpp 0285 --realinclude=TelepathyQt/_gen/svc-${spec}.h 0286 --mocinclude=TelepathyQt/_gen/svc-${spec}.moc.hpp 0287 --specxml=${CMAKE_CURRENT_BINARY_DIR}/_gen/stable-spec.xml 0288 --ifacexml=${CMAKE_CURRENT_BINARY_DIR}/_gen/spec-svc-${spec}.xml 0289 --visibility=TP_QT_EXPORT 0290 ${service_generator_args}) 0291 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.h ${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.cpp 0292 COMMAND ${PYTHON_EXECUTABLE} 0293 ARGS ${ARGS} 0294 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 0295 0296 DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py 0297 ${CMAKE_SOURCE_DIR}/tools/qt-svc-gen.py) 0298 add_custom_target(generate_service-${spec}-body DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.cpp) 0299 add_dependencies(all-generated-service-sources generate_service-${spec}-body) 0300 0301 if (service_generator_depends) 0302 add_dependencies(generate_service-${spec}-body ${service_generator_depends}) 0303 endif (service_generator_depends) 0304 0305 tpqt_generate_moc_i_target_deps(${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.h 0306 ${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.moc.hpp 0307 "generate_service-${spec}-body") 0308 endfunction(tpqt_service_generator spec group pretty_include namespace) 0309 0310 # This function is used for generating CM in various examples 0311 function(tpqt_generate_manager_file MANAGER_FILE OUTPUT_FILENAME DEPEND_FILENAME) 0312 # make_directory is required, otherwise the command won't work!! 0313 make_directory(${CMAKE_CURRENT_BINARY_DIR}/_gen) 0314 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/param-spec-struct.h 0315 ${CMAKE_CURRENT_BINARY_DIR}/_gen/${OUTPUT_FILENAME} 0316 0317 COMMAND ${PYTHON_EXECUTABLE} 0318 0319 ARGS ${CMAKE_SOURCE_DIR}/tools/manager-file.py 0320 ${MANAGER_FILE} 0321 _gen 0322 0323 DEPENDS ${CMAKE_SOURCE_DIR}/tools/manager-file.py) 0324 0325 set_source_files_properties(${DEPEND_FILENAME} 0326 PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/param-spec-struct.h) 0327 endfunction(tpqt_generate_manager_file MANAGER_FILE) 0328 0329 function(tpqt_xincludator _TARGET_NAME _INPUT_FILE _OUTPUT_FILE) 0330 tpqt_extract_depends(xincludator_gen_args xincludator_gen_depends ${ARGN}) 0331 # Gather all .xml files in TelepathyQt and spec/ and make this target depend on those 0332 file(GLOB depends_xml_files ${CMAKE_SOURCE_DIR}/TelepathyQt/*.xml ${CMAKE_SOURCE_DIR}/spec/*.xml) 0333 0334 add_custom_command(OUTPUT ${_OUTPUT_FILE} 0335 0336 COMMAND ${PYTHON_EXECUTABLE} 0337 0338 ARGS ${CMAKE_SOURCE_DIR}/tools/xincludator.py 0339 ${_INPUT_FILE} 0340 ${xincludator_gen_args} 0341 > ${_OUTPUT_FILE} 0342 0343 DEPENDS ${CMAKE_SOURCE_DIR}/tools/xincludator.py 0344 ${_INPUT_FILE} ${depends_xml_files}) 0345 add_custom_target(${_TARGET_NAME} DEPENDS ${_OUTPUT_FILE}) 0346 0347 if (xincludator_gen_depends) 0348 add_dependencies(${_TARGET_NAME} ${xincludator_gen_depends}) 0349 endif (xincludator_gen_depends) 0350 endfunction(tpqt_xincludator _TARGET_NAME _INPUT_FILE _OUTPUT_FILE) 0351 0352 function(tpqt_constants_gen _TARGET_NAME _SPEC_XML _OUTFILE) 0353 tpqt_extract_depends(constants_gen_args constants_gen_depends ${ARGN}) 0354 # Gather all .xml files in TelepathyQt and spec/ and make this target depend on those 0355 file(GLOB depends_xml_files ${CMAKE_SOURCE_DIR}/TelepathyQt/*.xml ${CMAKE_SOURCE_DIR}/spec/*.xml) 0356 0357 add_custom_command(OUTPUT ${_OUTFILE} 0358 0359 COMMAND ${PYTHON_EXECUTABLE} 0360 0361 ARGS ${CMAKE_SOURCE_DIR}/tools/qt-constants-gen.py 0362 ${constants_gen_args} 0363 --specxml=${_SPEC_XML} 0364 > ${_OUTFILE} 0365 0366 DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py 0367 ${CMAKE_SOURCE_DIR}/tools/qt-constants-gen.py 0368 ${_SPEC_XML} ${depends_xml_files}) 0369 add_custom_target(${_TARGET_NAME} DEPENDS ${_OUTFILE}) 0370 add_dependencies(all-generated-sources ${_TARGET_NAME}) 0371 0372 if (constants_gen_depends) 0373 add_dependencies(${_TARGET_NAME} ${constants_gen_depends}) 0374 endif (constants_gen_depends) 0375 endfunction (tpqt_constants_gen _TARGET_NAME _SPEC_XML _OUTFILE) 0376 0377 function(tpqt_types_gen _TARGET_NAME _SPEC_XML _OUTFILE_DECL _OUTFILE_IMPL _NAMESPACE _REALINCLUDE _PRETTYINCLUDE) 0378 tpqt_extract_depends(types_gen_args types_gen_depends ${ARGN}) 0379 # Gather all .xml files in TelepathyQt and spec/ and make this target depend on those 0380 file(GLOB depends_xml_files ${CMAKE_SOURCE_DIR}/TelepathyQt/*.xml ${CMAKE_SOURCE_DIR}/spec/*.xml) 0381 0382 add_custom_command(OUTPUT ${_OUTFILE_DECL} ${_OUTFILE_IMPL} 0383 COMMAND ${PYTHON_EXECUTABLE} 0384 ARGS ${CMAKE_SOURCE_DIR}/tools/qt-types-gen.py 0385 --namespace=${_NAMESPACE} 0386 --declfile=${_OUTFILE_DECL} 0387 --implfile=${_OUTFILE_IMPL} 0388 --realinclude=${_REALINCLUDE} 0389 --prettyinclude=${_PRETTYINCLUDE} 0390 ${types_gen_args} 0391 --specxml=${_SPEC_XML} 0392 0393 DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py 0394 ${CMAKE_SOURCE_DIR}/tools/qt-types-gen.py 0395 ${_SPEC_XML} ${depends_xml_files}) 0396 add_custom_target(${_TARGET_NAME} DEPENDS ${_OUTFILE_IMPL}) 0397 add_dependencies(all-generated-sources ${_TARGET_NAME}) 0398 0399 if (types_gen_depends) 0400 add_dependencies(${_TARGET_NAME} ${types_gen_depends}) 0401 endif (types_gen_depends) 0402 endfunction(tpqt_types_gen _TARGET_NAME _SPEC_XML _OUTFILE_DECL _OUTFILE_IMPL _NAMESPACE _REALINCLUDE _PRETTYINCLUDE) 0403 0404 macro(tpqt_add_generic_unit_test _fancyName _name) 0405 tpqt_generate_moc_i(${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) 0406 add_executable(test-${_name} ${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) 0407 target_link_libraries(test-${_name} ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTTEST_LIBRARY} telepathy-qt${QT_VERSION_MAJOR} tp-qt-tests ${TP_QT_EXECUTABLE_LINKER_FLAGS} ${ARGN}) 0408 add_test(${_fancyName} ${SH} ${CMAKE_CURRENT_BINARY_DIR}/runGenericTest.sh ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) 0409 list(APPEND _telepathy_qt_test_cases test-${_name}) 0410 0411 # Valgrind and Callgrind targets 0412 _tpqt_add_check_targets(${_fancyName} ${_name} ${CMAKE_CURRENT_BINARY_DIR}/runGenericTest.sh ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) 0413 endmacro(tpqt_add_generic_unit_test _fancyName _name) 0414 0415 macro(tpqt_add_dbus_unit_test _fancyName _name) 0416 tpqt_generate_moc_i(${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) 0417 add_executable(test-${_name} ${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) 0418 target_link_libraries(test-${_name} ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTTEST_LIBRARY} telepathy-qt${QT_VERSION_MAJOR} tp-qt-tests ${TP_QT_EXECUTABLE_LINKER_FLAGS} ${ARGN}) 0419 set(with_session_bus ${CMAKE_CURRENT_BINARY_DIR}/runDbusTest.sh) 0420 add_test(${_fancyName} ${SH} ${with_session_bus} ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) 0421 list(APPEND _telepathy_qt_test_cases test-${_name}) 0422 0423 # Valgrind and Callgrind targets 0424 _tpqt_add_check_targets(${_fancyName} ${_name} ${with_session_bus} ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) 0425 endmacro(tpqt_add_dbus_unit_test _fancyName _name) 0426 0427 macro(_tpqt_add_check_targets _fancyName _name _runnerScript) 0428 set_tests_properties(${_fancyName} 0429 PROPERTIES 0430 FAIL_REGULAR_EXPRESSION "^FAIL!") 0431 0432 # Standard check target 0433 add_custom_target(check-${_fancyName} ${SH} ${_runnerScript} ${ARGN}) 0434 add_dependencies(check-${_fancyName} test-${_name}) 0435 0436 # Lcov target 0437 add_dependencies(lcov-check test-${_name}) 0438 0439 # Valgrind target 0440 add_custom_target(check-valgrind-${_fancyName}) 0441 add_dependencies(check-valgrind-${_fancyName} test-${_name}) 0442 0443 add_custom_command( 0444 TARGET check-valgrind-${_fancyName} 0445 COMMAND G_SLICE=always-malloc ${SH} ${_runnerScript} /usr/bin/valgrind 0446 --tool=memcheck 0447 --leak-check=full 0448 --leak-resolution=high 0449 --child-silent-after-fork=yes 0450 --num-callers=20 0451 --gen-suppressions=all 0452 --log-file=${CMAKE_CURRENT_BINARY_DIR}/test-${_fancyName}.memcheck.log 0453 --suppressions=${CMAKE_SOURCE_DIR}/tools/tp-qt-tests.supp 0454 --suppressions=${CMAKE_SOURCE_DIR}/tools/telepathy-glib.supp 0455 ${ARGN} 0456 WORKING_DIRECTORY 0457 ${CMAKE_CURRENT_BINARY_DIR} 0458 COMMENT "Running valgrind on test \"${_fancyName}\"") 0459 add_dependencies(check-valgrind check-valgrind-${_fancyName}) 0460 0461 # Callgrind target 0462 add_custom_target(check-callgrind-${_fancyName}) 0463 add_dependencies(check-callgrind-${_fancyName} test-${_name}) 0464 add_custom_command( 0465 TARGET check-callgrind-${_fancyName} 0466 COMMAND ${SH} ${_runnerScript} /usr/bin/valgrind 0467 --tool=callgrind 0468 --dump-instr=yes 0469 --log-file=${CMAKE_CURRENT_BINARY_DIR}/test-${_fancyName}.callgrind.log 0470 --callgrind-out-file=${CMAKE_CURRENT_BINARY_DIR}/test-${_fancyName}.callgrind.out 0471 ${ARGN} 0472 WORKING_DIRECTORY 0473 ${CMAKE_CURRENT_BINARY_DIR} 0474 COMMENT 0475 "Running callgrind on test \"${_fancyName}\"") 0476 add_dependencies(check-callgrind check-callgrind-${_fancyName}) 0477 endmacro(_tpqt_add_check_targets _fancyName _name) 0478 0479 function(tpqt_setup_dbus_test_environment) 0480 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/runDbusTest.sh " 0481 ${test_environment} 0482 sh ${CMAKE_SOURCE_DIR}/tools/with-session-bus.sh \\ 0483 --config-file=${CMAKE_BINARY_DIR}/tests/dbus-1/session.conf -- $@ 0484 ") 0485 endfunction(tpqt_setup_dbus_test_environment) 0486 0487 macro(make_install_path_absolute out in) 0488 if (IS_ABSOLUTE "${in}") 0489 set(${out} "${in}") 0490 else (IS_ABSOLUTE "${in}") 0491 set(${out} "\${TELEPATHY_QT${QT_VERSION_MAJOR}_INSTALL_DIR}/${in}") 0492 endif (IS_ABSOLUTE "${in}") 0493 endmacro(make_install_path_absolute out in)