Merge topic 'export-refactor-more-for-cps'
[kiteware-cmake.git] / Tests / QtAutogen / TestMacros.cmake
blob529592e85ee8ef1807fba46336aab742b5da1e72
1 # Autogen build options
2 set(Autogen_BUILD_OPTIONS "-DQT_TEST_VERSION=${QT_TEST_VERSION}")
3 if(_isMultiConfig)   # Set in Tests/CMakeLists.txt
4   list(APPEND Autogen_CTEST_OPTIONS --build-config $<CONFIGURATION>)
5 else()
6   list(APPEND Autogen_BUILD_OPTIONS "-DCMAKE_BUILD_TYPE=$<CONFIGURATION>")
7 endif()
8 list(APPEND Autogen_BUILD_OPTIONS
9     "-DCMAKE_AUTOGEN_VERBOSE=1"
11 if(Qt${QT_TEST_VERSION}Core_DIR)
12   get_filename_component(prefix "${Qt${QT_TEST_VERSION}Core_DIR}" DIRECTORY)
13   get_filename_component(prefix "${prefix}" DIRECTORY)
14   get_filename_component(prefix "${prefix}" DIRECTORY)
15   list(APPEND Autogen_BUILD_OPTIONS "-DCMAKE_PREFIX_PATH:STRING=${prefix}")
16 else()
17   list(APPEND Autogen_BUILD_OPTIONS
18     "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
19   )
20 endif()
21 # XXX(xcode-per-cfg-src): Drop the NO_PER_CONFIG_SOURCES exclusion
22 # when the Xcode generator supports per-config sources.
23 if(CMAKE_GENERATOR STREQUAL "Xcode")
24   list(APPEND Autogen_BUILD_OPTIONS -DNO_PER_CONFIG_SOURCES=1)
25 endif()
27 # A macro to add a QtAutogen test
28 macro(ADD_AUTOGEN_TEST NAME)
29   if(${ARGC} GREATER 1)
30     # On Windows there is no RPATH, so while Qt might be available for building,
31     # the required dlls may not be in the PATH, so we can't run the executables
32     # on that platform.
33     if(WIN32)
34       set(_TestCommand --test-command ${CMAKE_CTEST_COMMAND} -V)
35     else()
36       set(_TestCommand --test-command ${ARGN})
37     endif()
38   endif()
40   set(_QtXAutogen "Qt${QT_TEST_VERSION}Autogen")
41   set(_SourceDir "${CMake_SOURCE_DIR}/Tests/QtAutogen/${NAME}")
42   set(_BuildDir "${CMake_BINARY_DIR}/Tests/${_QtXAutogen}/${NAME}")
43   add_test(NAME "${_QtXAutogen}.${NAME}" COMMAND "${CMAKE_CTEST_COMMAND}"
44     --build-and-test
45     "${_SourceDir}"
46     "${_BuildDir}"
47     ${build_generator_args}
48     --build-project ${NAME}
49     ${Autogen_CTEST_OPTIONS}
50     --build-exe-dir "${_BuildDir}"
51     --force-new-ctest-process
52     --build-options ${build_options} ${Autogen_BUILD_OPTIONS}
53     ${_TestCommand}
54   )
55   set_tests_properties("${_QtXAutogen}.${NAME}" PROPERTIES LABELS "Qt${QT_TEST_VERSION}")
56   list(APPEND TEST_BUILD_DIRS "${_BuildDir}")
57   unset(_TestCommand)
58   unset(_QtXAutogen)
59   unset(_SourceDir)
60   unset(_BuildDir)
61 endmacro()
63 # Allow using qtx_wrap_cpp and qtx_generate_moc or not
64 set(QT_TEST_ALLOW_QT_MACROS TRUE)
65 # Do a simple check if there is are non ASCII character in the build path
66 string(REGEX MATCH "[^ -~]+" NON_ASCII_BDIR ${CMAKE_CURRENT_BINARY_DIR})
67 if(NON_ASCII_BDIR)
68   # Qt4 moc does not support utf8 paths in _parameter files generated by
69   # qtx_wrap_cpp
70   # https://bugreports.qt.io/browse/QTBUG-35480
71   if(QT_TEST_VERSION EQUAL 4)
72     set(QT_TEST_ALLOW_QT_MACROS FALSE)
73   endif()
74   # On windows qtx_wrap_cpp also fails in Qt5 when used on a path that
75   # contains non ASCII characters
76   if(WIN32)
77     set(QT_TEST_ALLOW_QT_MACROS FALSE)
78   endif()
79 endif()