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 explicitly. 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 () 0132 IF(_TPQT_DOING_DEPENDS) 0133 LIST(APPEND ${_tpqt_depends} "${_currentArg}") 0134 ELSE() 0135 LIST(APPEND ${_tpqt_other} "${_currentArg}") 0136 ENDIF() 0137 ENDIF () 0138 ENDFOREACH() 0139 ENDMACRO () 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() 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() 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 () 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 () 0172 0173 add_custom_target(moc-${_moc_outfile_name} DEPENDS ${outfile}) 0174 add_dependencies(moc-${_moc_outfile_name} ${ARGN}) 0175 ENDFUNCTION () 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) # don't run automoc on this file 0183 endfunction() 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) # don't run automoc on this file 0191 endfunction() 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() 0201 endfunction() 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 ${CMAKE_CURRENT_BINARY_DIR}/_gen/stable-spec.xml 0228 ${CMAKE_CURRENT_BINARY_DIR}/_gen/spec-${spec}.xml) 0229 add_custom_target(generate_cli-${spec}-body DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}-body.hpp) 0230 add_dependencies(all-generated-sources generate_cli-${spec}-body) 0231 0232 if (client_generator_depends) 0233 add_dependencies(generate_cli-${spec}-body ${client_generator_depends}) 0234 endif () 0235 0236 tpqt_generate_moc_i_target_deps(${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.h 0237 ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.moc.hpp 0238 "generate_cli-${spec}-body") 0239 endfunction() 0240 0241 function(tpqt_future_client_generator spec namespace) 0242 tpqt_extract_depends(future_client_generator_args future_client_generator_depends ${ARGN}) 0243 set(ARGS 0244 ${CMAKE_SOURCE_DIR}/tools/qt-client-gen.py 0245 --namespace=${namespace} 0246 --typesnamespace=TpFuture 0247 --headerfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.h 0248 --implfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}-body.hpp 0249 --realinclude=TelepathyQt/future-internal.h 0250 --prettyinclude=TelepathyQt/future-internal.h 0251 --specxml=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-spec.xml 0252 --ifacexml=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.xml 0253 --extraincludes=${TYPES_INCLUDE} 0254 --extraincludes='<TelepathyQt/Types>' 0255 --extraincludes='<TelepathyQt/future-internal.h>' 0256 --visibility=TP_QT_NO_EXPORT 0257 ${future_client_generator_args}) 0258 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.h ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}-body.hpp 0259 COMMAND ${PYTHON_EXECUTABLE} 0260 ARGS ${ARGS} 0261 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 0262 0263 DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py 0264 ${CMAKE_SOURCE_DIR}/tools/qt-client-gen.py 0265 ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-spec.xml 0266 ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.xml) 0267 add_custom_target(generate_future-${spec}-body DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}-body.hpp) 0268 add_dependencies(all-generated-sources generate_future-${spec}-body) 0269 0270 if (future_client_generator_depends) 0271 add_dependencies(generate_future-${spec}-body ${future_client_generator_depends}) 0272 endif () 0273 0274 tpqt_generate_moc_i_target_deps(${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.h 0275 ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.moc.hpp 0276 "generate_future-${spec}-body") 0277 endfunction() 0278 0279 function(tpqt_service_generator spec group pretty_include namespace) 0280 tpqt_extract_depends(service_generator_args service_generator_depends ${ARGN}) 0281 string(REPLACE "svc-" "" spec ${spec}) 0282 set(ARGS 0283 ${CMAKE_SOURCE_DIR}/tools/qt-svc-gen.py 0284 --group=${group} 0285 --namespace=${namespace} 0286 --typesnamespace=Tp 0287 --headerfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.h 0288 --implfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.cpp 0289 --realinclude=TelepathyQt/_gen/svc-${spec}.h 0290 --mocinclude=TelepathyQt/_gen/svc-${spec}.moc.hpp 0291 --specxml=${CMAKE_CURRENT_BINARY_DIR}/_gen/stable-spec.xml 0292 --ifacexml=${CMAKE_CURRENT_BINARY_DIR}/_gen/spec-svc-${spec}.xml 0293 --visibility=TP_QT_EXPORT 0294 ${service_generator_args}) 0295 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.h ${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.cpp 0296 COMMAND ${PYTHON_EXECUTABLE} 0297 ARGS ${ARGS} 0298 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 0299 0300 DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py 0301 ${CMAKE_SOURCE_DIR}/tools/qt-svc-gen.py 0302 ${CMAKE_CURRENT_BINARY_DIR}/_gen/stable-spec.xml 0303 ${CMAKE_CURRENT_BINARY_DIR}/_gen/spec-svc-${spec}.xml) 0304 add_custom_target(generate_service-${spec}-body DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.cpp) 0305 add_dependencies(all-generated-service-sources generate_service-${spec}-body) 0306 0307 if (service_generator_depends) 0308 add_dependencies(generate_service-${spec}-body ${service_generator_depends}) 0309 endif () 0310 0311 tpqt_generate_moc_i_target_deps(${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.h 0312 ${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.moc.hpp 0313 "generate_service-${spec}-body") 0314 endfunction() 0315 0316 # This function is used for generating CM in various examples 0317 function(tpqt_generate_manager_file MANAGER_FILE OUTPUT_FILENAME DEPEND_FILENAME) 0318 # make_directory is required, otherwise the command won't work!! 0319 make_directory(${CMAKE_CURRENT_BINARY_DIR}/_gen) 0320 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/param-spec-struct.h 0321 ${CMAKE_CURRENT_BINARY_DIR}/_gen/${OUTPUT_FILENAME} 0322 0323 COMMAND ${PYTHON_EXECUTABLE} 0324 0325 ARGS ${CMAKE_SOURCE_DIR}/tools/manager-file.py 0326 ${MANAGER_FILE} 0327 _gen 0328 0329 DEPENDS ${CMAKE_SOURCE_DIR}/tools/manager-file.py) 0330 0331 set_source_files_properties(${DEPEND_FILENAME} 0332 PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/param-spec-struct.h) 0333 endfunction() 0334 0335 function(tpqt_xincludator _TARGET_NAME _INPUT_FILE _OUTPUT_FILE) 0336 tpqt_extract_depends(xincludator_gen_args xincludator_gen_depends ${ARGN}) 0337 # Gather all .xml files in TelepathyQt and spec/ and make this target depend on those 0338 file(GLOB depends_xml_files ${CMAKE_SOURCE_DIR}/TelepathyQt/*.xml ${CMAKE_SOURCE_DIR}/spec/*.xml) 0339 0340 add_custom_command(OUTPUT ${_OUTPUT_FILE} 0341 0342 COMMAND ${PYTHON_EXECUTABLE} 0343 0344 ARGS ${CMAKE_SOURCE_DIR}/tools/xincludator.py 0345 ${_INPUT_FILE} 0346 ${xincludator_gen_args} 0347 > ${_OUTPUT_FILE} 0348 0349 DEPENDS ${CMAKE_SOURCE_DIR}/tools/xincludator.py 0350 ${_INPUT_FILE} ${depends_xml_files}) 0351 add_custom_target(${_TARGET_NAME} DEPENDS ${_OUTPUT_FILE}) 0352 0353 if (xincludator_gen_depends) 0354 add_dependencies(${_TARGET_NAME} ${xincludator_gen_depends}) 0355 endif () 0356 endfunction() 0357 0358 function(tpqt_constants_gen _TARGET_NAME _SPEC_XML _OUTFILE) 0359 tpqt_extract_depends(constants_gen_args constants_gen_depends ${ARGN}) 0360 # Gather all .xml files in TelepathyQt and spec/ and make this target depend on those 0361 file(GLOB depends_xml_files ${CMAKE_SOURCE_DIR}/TelepathyQt/*.xml ${CMAKE_SOURCE_DIR}/spec/*.xml) 0362 0363 add_custom_command(OUTPUT ${_OUTFILE} 0364 0365 COMMAND ${PYTHON_EXECUTABLE} 0366 0367 ARGS ${CMAKE_SOURCE_DIR}/tools/qt-constants-gen.py 0368 ${constants_gen_args} 0369 --specxml=${_SPEC_XML} 0370 > ${_OUTFILE} 0371 0372 DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py 0373 ${CMAKE_SOURCE_DIR}/tools/qt-constants-gen.py 0374 ${_SPEC_XML} ${depends_xml_files}) 0375 add_custom_target(${_TARGET_NAME} DEPENDS ${_OUTFILE}) 0376 add_dependencies(all-generated-sources ${_TARGET_NAME}) 0377 0378 if (constants_gen_depends) 0379 add_dependencies(${_TARGET_NAME} ${constants_gen_depends}) 0380 endif () 0381 endfunction () 0382 0383 function(tpqt_types_gen _TARGET_NAME _SPEC_XML _OUTFILE_DECL _OUTFILE_IMPL _NAMESPACE _REALINCLUDE _PRETTYINCLUDE) 0384 tpqt_extract_depends(types_gen_args types_gen_depends ${ARGN}) 0385 # Gather all .xml files in TelepathyQt and spec/ and make this target depend on those 0386 file(GLOB depends_xml_files ${CMAKE_SOURCE_DIR}/TelepathyQt/*.xml ${CMAKE_SOURCE_DIR}/spec/*.xml) 0387 0388 add_custom_command(OUTPUT ${_OUTFILE_DECL} ${_OUTFILE_IMPL} 0389 COMMAND ${PYTHON_EXECUTABLE} 0390 ARGS ${CMAKE_SOURCE_DIR}/tools/qt-types-gen.py 0391 --namespace=${_NAMESPACE} 0392 --declfile=${_OUTFILE_DECL} 0393 --implfile=${_OUTFILE_IMPL} 0394 --realinclude=${_REALINCLUDE} 0395 --prettyinclude=${_PRETTYINCLUDE} 0396 ${types_gen_args} 0397 --specxml=${_SPEC_XML} 0398 0399 DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py 0400 ${CMAKE_SOURCE_DIR}/tools/qt-types-gen.py 0401 ${_SPEC_XML} ${depends_xml_files}) 0402 add_custom_target(${_TARGET_NAME} DEPENDS ${_OUTFILE_IMPL}) 0403 add_dependencies(all-generated-sources ${_TARGET_NAME}) 0404 0405 if (types_gen_depends) 0406 add_dependencies(${_TARGET_NAME} ${types_gen_depends}) 0407 endif () 0408 endfunction() 0409 0410 macro(tpqt_add_generic_unit_test _fancyName _name) 0411 tpqt_generate_moc_i(${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) 0412 add_executable(test-${_name} ${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) 0413 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}) 0414 add_test(${_fancyName} ${SH} ${CMAKE_CURRENT_BINARY_DIR}/runGenericTest.sh ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) 0415 list(APPEND _telepathy_qt_test_cases test-${_name}) 0416 0417 # Valgrind and Callgrind targets 0418 _tpqt_add_check_targets(${_fancyName} ${_name} ${CMAKE_CURRENT_BINARY_DIR}/runGenericTest.sh ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) 0419 endmacro() 0420 0421 macro(tpqt_add_dbus_unit_test _fancyName _name) 0422 tpqt_generate_moc_i(${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) 0423 add_executable(test-${_name} ${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) 0424 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}) 0425 set(with_session_bus ${CMAKE_CURRENT_BINARY_DIR}/runDbusTest.sh) 0426 add_test(${_fancyName} ${SH} ${with_session_bus} ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) 0427 list(APPEND _telepathy_qt_test_cases test-${_name}) 0428 0429 # Valgrind and Callgrind targets 0430 _tpqt_add_check_targets(${_fancyName} ${_name} ${with_session_bus} ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) 0431 endmacro() 0432 0433 macro(_tpqt_add_check_targets _fancyName _name _runnerScript) 0434 set_tests_properties(${_fancyName} 0435 PROPERTIES 0436 FAIL_REGULAR_EXPRESSION "^FAIL!") 0437 0438 # Standard check target 0439 add_custom_target(check-${_fancyName} ${SH} ${_runnerScript} ${ARGN}) 0440 add_dependencies(check-${_fancyName} test-${_name}) 0441 0442 # Lcov target 0443 add_dependencies(lcov-check test-${_name}) 0444 0445 # Valgrind target 0446 add_custom_target(check-valgrind-${_fancyName}) 0447 add_dependencies(check-valgrind-${_fancyName} test-${_name}) 0448 0449 add_custom_command( 0450 TARGET check-valgrind-${_fancyName} 0451 COMMAND G_SLICE=always-malloc ${SH} ${_runnerScript} /usr/bin/valgrind 0452 --tool=memcheck 0453 --leak-check=full 0454 --leak-resolution=high 0455 --child-silent-after-fork=yes 0456 --num-callers=20 0457 --gen-suppressions=all 0458 --log-file=${CMAKE_CURRENT_BINARY_DIR}/test-${_fancyName}.memcheck.log 0459 --suppressions=${CMAKE_SOURCE_DIR}/tools/tp-qt-tests.supp 0460 --suppressions=${CMAKE_SOURCE_DIR}/tools/telepathy-glib.supp 0461 ${ARGN} 0462 WORKING_DIRECTORY 0463 ${CMAKE_CURRENT_BINARY_DIR} 0464 COMMENT "Running valgrind on test \"${_fancyName}\"") 0465 add_dependencies(check-valgrind check-valgrind-${_fancyName}) 0466 0467 # Callgrind target 0468 add_custom_target(check-callgrind-${_fancyName}) 0469 add_dependencies(check-callgrind-${_fancyName} test-${_name}) 0470 add_custom_command( 0471 TARGET check-callgrind-${_fancyName} 0472 COMMAND ${SH} ${_runnerScript} /usr/bin/valgrind 0473 --tool=callgrind 0474 --dump-instr=yes 0475 --log-file=${CMAKE_CURRENT_BINARY_DIR}/test-${_fancyName}.callgrind.log 0476 --callgrind-out-file=${CMAKE_CURRENT_BINARY_DIR}/test-${_fancyName}.callgrind.out 0477 ${ARGN} 0478 WORKING_DIRECTORY 0479 ${CMAKE_CURRENT_BINARY_DIR} 0480 COMMENT 0481 "Running callgrind on test \"${_fancyName}\"") 0482 add_dependencies(check-callgrind check-callgrind-${_fancyName}) 0483 endmacro() 0484 0485 function(tpqt_setup_dbus_test_environment) 0486 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/runDbusTest.sh " 0487 ${test_environment} 0488 sh ${CMAKE_SOURCE_DIR}/tools/with-session-bus.sh \\ 0489 --config-file=${CMAKE_BINARY_DIR}/tests/dbus-1/session.conf -- $@ 0490 ") 0491 endfunction() 0492 0493 macro(make_install_path_absolute out in) 0494 if (IS_ABSOLUTE "${in}") 0495 set(${out} "${in}") 0496 else () 0497 set(${out} "\${TELEPATHY_QT${QT_VERSION_MAJOR}_INSTALL_DIR}/${in}") 0498 endif () 0499 endmacro()