summaryrefslogtreecommitdiffstats
path: root/src/corelib/Qt6CTestMacros.cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-07-14 10:38:51 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-07-17 09:43:04 +0200
commit96e3ee06598d00e7155f3f8574759ea658a134e5 (patch)
treefac2baa25b9b1c7460e7d43772d011e12d34724a /src/corelib/Qt6CTestMacros.cmake
parent054b66a65748c9ebfafeca88bf31669a24994237 (diff)
CMake: Get tests/auto/cmake tests working
The tests/auto/cmake project can be configured separately as a standalone project with qt-cmake, or as part of the overall qtbase standalone tests. To do that a bunch of things were done - Ported all Qt5 strings to Qt6 - Replaced in all projects the use of add_definitions and include_directories with a target based approach, except for 2 tests where we check that the old-style approach works, otherwise the tests would file - Removed some (possibly unneeded) EGL / OpenGL tests - Fixed some C++ code - Added setup code to tests/auto/cmake/CMakeLists.txt to figure out which modules are available and should be tested - Fixed Qt6CTestMacros.cmake to be loaded by Qt6Core - Removed the CMake tests to not be run in qmake builds of Qt because they would fail anyway - Enabled the CMake tests to be part of standalone tests - Disabled auto-passing of the C and CXX compiler cache vars when cross-compiling so that the tests can somewhat pass on boot2qt. This is the issue we encountered in e2b2cd9397c76e91ac1ebe493bcac7696767c02e - Ultimately disabled tests for boot2qt, because the -rpath-link flag is not generated by CMake for some reason. - Added code to setup the environment when running an executable that was built as part of the test, so that the proper Qt libraries are found. This handles both the standalone tests case and separate project case. The remaining unported tests are test_import_plugins which requires quite a bit of work to get some modules and plugins built that were done as part of the qmake .pro files, test_plugins that checks some Network plugins which I'm not sure about, and test_add_big_resource which doesn't work with namespaced builds and there's no good way of detecting those at the moment either. Change-Id: Ic8809c72817d1db81af6c6014c11df6473ad8c75 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/corelib/Qt6CTestMacros.cmake')
-rw-r--r--src/corelib/Qt6CTestMacros.cmake158
1 files changed, 95 insertions, 63 deletions
diff --git a/src/corelib/Qt6CTestMacros.cmake b/src/corelib/Qt6CTestMacros.cmake
index 962d49d6b2..d1ea0a350d 100644
--- a/src/corelib/Qt6CTestMacros.cmake
+++ b/src/corelib/Qt6CTestMacros.cmake
@@ -19,11 +19,11 @@ endforeach()
set(BUILD_OPTIONS_LIST)
-if (CMAKE_C_COMPILER)
+if (CMAKE_C_COMPILER AND NOT CMAKE_CROSSCOMPILING)
list(APPEND BUILD_OPTIONS_LIST "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
endif()
-if (CMAKE_CXX_COMPILER)
+if (CMAKE_CXX_COMPILER AND NOT CMAKE_CROSSCOMPILING)
list(APPEND BUILD_OPTIONS_LIST "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
endif()
@@ -49,20 +49,6 @@ if (NO_DBUS)
list(APPEND BUILD_OPTIONS_LIST "-DNO_DBUS=True")
endif()
-# Qt requires C++11 features in header files, which means
-# the buildsystem needs to add a -std flag for certain compilers
-# CMake adds the flag automatically in most cases, but notably not
-# on Windows prior to CMake 3.3
-if (CMAKE_VERSION VERSION_LESS 3.3)
- if (CMAKE_CXX_COMPILER_ID STREQUAL AppleClang
- OR (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang))
- list(APPEND BUILD_OPTIONS_LIST "-DCMAKE_CXX_FLAGS=-std=gnu++0x -stdlib=libc++")
- elseif (CMAKE_CXX_COMPILER_ID STREQUAL GNU
- OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
- list(APPEND BUILD_OPTIONS_LIST "-DCMAKE_CXX_FLAGS=-std=gnu++0x")
- endif()
-endif()
-
foreach(module ${CMAKE_MODULES_UNDER_TEST})
list(APPEND BUILD_OPTIONS_LIST
"-DCMAKE_${module}_MODULE_MAJOR_VERSION=${CMAKE_${module}_MODULE_MAJOR_VERSION}"
@@ -71,21 +57,83 @@ foreach(module ${CMAKE_MODULES_UNDER_TEST})
)
endforeach()
+function(_qt_internal_set_up_test_run_environment testname)
+ # This is copy-pasted from qt_add_test and adapted to the standalone project case.
+ if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
+ set(QT_PATH_SEPARATOR "\\;")
+ else()
+ set(QT_PATH_SEPARATOR ":")
+ endif()
+
+ if(NOT INSTALL_BINDIR)
+ set(INSTALL_BINDIR bin)
+ endif()
+
+ if(NOT INSTALL_PLUGINSDIR)
+ set(INSTALL_PLUGINSDIR "plugins")
+ endif()
+
+ set(install_prefixes "")
+ if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+ set(install_prefixes "${CMAKE_INSTALL_PREFIX}")
+ endif()
+
+ # If part of Qt build or standalone tests, use the build internals install prefix.
+ # If the tests are configured as a separate project, use the Qt6 package provided install
+ # prefix.
+ if(QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX)
+ list(APPEND install_prefixes "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}")
+ else()
+ list(APPEND install_prefixes "${QT6_INSTALL_PREFIX}")
+ endif()
+
+ set(test_env_path "PATH=${CMAKE_CURRENT_BINARY_DIR}")
+ foreach(install_prefix ${install_prefixes})
+ set(test_env_path "${test_env_path}${QT_PATH_SEPARATOR}${install_prefix}/${INSTALL_BINDIR}")
+ endforeach()
+ set(test_env_path "${test_env_path}${QT_PATH_SEPARATOR}$ENV{PATH}")
+ string(REPLACE ";" "\;" test_env_path "${test_env_path}")
+ set_property(TEST "${testname}" APPEND PROPERTY ENVIRONMENT "${test_env_path}")
+ set_property(TEST "${testname}" APPEND PROPERTY ENVIRONMENT "QT_TEST_RUNNING_IN_CTEST=1")
+
+ # Add the install prefix to list of plugin paths when doing a prefix build
+ if(NOT QT_INSTALL_DIR)
+ foreach(install_prefix ${install_prefixes})
+ list(APPEND plugin_paths "${install_prefix}/${INSTALL_PLUGINSDIR}")
+ endforeach()
+ endif()
+
+ #TODO: Collect all paths from known repositories when performing a super
+ # build.
+ list(APPEND plugin_paths "${PROJECT_BINARY_DIR}/${INSTALL_PLUGINSDIR}")
+ list(JOIN plugin_paths "${QT_PATH_SEPARATOR}" plugin_paths_joined)
+ set_property(TEST "${testname}"
+ APPEND PROPERTY ENVIRONMENT "QT_PLUGIN_PATH=${plugin_paths_joined}")
+
+endfunction()
+
macro(expect_pass _dir)
cmake_parse_arguments(_ARGS "" "BINARY" "" ${ARGN})
string(REPLACE "(" "_" testname "${_dir}")
string(REPLACE ")" "_" testname "${testname}")
- add_test(${testname} ${CMAKE_CTEST_COMMAND}
- --build-and-test
- "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}"
- "${CMAKE_CURRENT_BINARY_DIR}/${_dir}"
- --build-config "${CMAKE_BUILD_TYPE}"
- --build-generator ${CMAKE_GENERATOR}
- --build-makeprogram ${CMAKE_MAKE_PROGRAM}
- --build-project ${_dir}
- --build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${BUILD_OPTIONS_LIST}
- --test-command ${_ARGS_BINARY}
- )
+
+ set(__expect_pass__prefixes "${CMAKE_PREFIX_PATH}")
+ string(REPLACE ";" "\;" __expect_pass__prefixes "${__expect_pass__prefixes}")
+
+ set(ctest_command_args
+ --build-and-test
+ "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}"
+ "${CMAKE_CURRENT_BINARY_DIR}/${_dir}"
+ --build-config "${CMAKE_BUILD_TYPE}"
+ --build-generator "${CMAKE_GENERATOR}"
+ --build-makeprogram "${CMAKE_MAKE_PROGRAM}"
+ --build-project "${_dir}"
+ --build-options "-DCMAKE_PREFIX_PATH=${__expect_pass__prefixes}" ${BUILD_OPTIONS_LIST}
+ --test-command ${_ARGS_BINARY})
+ add_test(${testname} ${CMAKE_CTEST_COMMAND} ${ctest_command_args})
+ if(_ARGS_BINARY)
+ _qt_internal_set_up_test_run_environment("${testname}")
+ endif()
endmacro()
macro(expect_fail _dir)
@@ -94,11 +142,11 @@ macro(expect_fail _dir)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}")
- file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}/${_dir}/FindPackageHints.cmake" "set(Qt5Tests_PREFIX_PATH \"${CMAKE_PREFIX_PATH}\")")
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}/${_dir}/FindPackageHints.cmake" "set(Qt6Tests_PREFIX_PATH \"${CMAKE_PREFIX_PATH}\")")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}/CMakeLists.txt"
"
- cmake_minimum_required(VERSION 2.8)
+ cmake_minimum_required(VERSION 3.14)
project(${_dir})
try_compile(Result \${CMAKE_CURRENT_BINARY_DIR}/${_dir}
@@ -117,9 +165,9 @@ macro(expect_fail _dir)
"${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}"
"${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}/build"
--build-config "${CMAKE_BUILD_TYPE}"
- --build-generator ${CMAKE_GENERATOR}
- --build-makeprogram ${CMAKE_MAKE_PROGRAM}
- --build-project ${_dir}
+ --build-generator "${CMAKE_GENERATOR}"
+ --build-makeprogram "${CMAKE_MAKE_PROGRAM}"
+ --build-project "${_dir}"
--build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${BUILD_OPTIONS_LIST}
)
endmacro()
@@ -130,11 +178,11 @@ function(test_module_includes)
set(packages_string "")
set(libraries_string "")
- foreach(_package ${Qt5_MODULE_TEST_DEPENDS})
+ foreach(_package ${Qt6_MODULE_TEST_DEPENDS})
set(packages_string
"
${packages_string}
- find_package(Qt5${_package} 5.0.0 REQUIRED)
+ find_package(Qt6${_package} 6.0.0 REQUIRED)
"
)
endforeach()
@@ -147,52 +195,36 @@ function(test_module_includes)
set(packages_string
"${packages_string}
- find_package(Qt5${qtmodule} 5.0.0 REQUIRED)
- include_directories(\${Qt5${qtmodule}_INCLUDE_DIRS})
- add_definitions(\${Qt5${qtmodule}_DEFINITIONS})\n")
+ find_package(Qt6${qtmodule} 6.0.0 REQUIRED)\n")
list(FIND CMAKE_MODULES_UNDER_TEST ${qtmodule} _findIndex)
if (NOT _findIndex STREQUAL -1)
set(packages_string
"${packages_string}
- if(NOT \"\${Qt5${qtmodule}_VERSION}\" VERSION_EQUAL ${CMAKE_MODULE_VERSION})
- message(SEND_ERROR \"Qt5${qtmodule}_VERSION variable was not ${CMAKE_MODULE_VERSION}. Got \${Qt5${qtmodule}_VERSION} instead.\")
+ if(NOT \"\${Qt6${qtmodule}_VERSION}\" VERSION_EQUAL ${CMAKE_MODULE_VERSION})
+ message(SEND_ERROR \"Qt6${qtmodule}_VERSION variable was not ${CMAKE_MODULE_VERSION}. Got \${Qt6${qtmodule}_VERSION} instead.\")
endif()
- if(NOT \"\${Qt5${qtmodule}_VERSION_MAJOR}\" VERSION_EQUAL ${CMAKE_${qtmodule}_MODULE_MAJOR_VERSION})
- message(SEND_ERROR \"Qt5${qtmodule}_VERSION_MAJOR variable was not ${CMAKE_${qtmodule}_MODULE_MAJOR_VERSION}. Got \${Qt5${qtmodule}_VERSION_MAJOR} instead.\")
+ if(NOT \"\${Qt6${qtmodule}_VERSION_MAJOR}\" VERSION_EQUAL ${CMAKE_${qtmodule}_MODULE_MAJOR_VERSION})
+ message(SEND_ERROR \"Qt6${qtmodule}_VERSION_MAJOR variable was not ${CMAKE_${qtmodule}_MODULE_MAJOR_VERSION}. Got \${Qt6${qtmodule}_VERSION_MAJOR} instead.\")
endif()
- if(NOT \"\${Qt5${qtmodule}_VERSION_MINOR}\" VERSION_EQUAL ${CMAKE_${qtmodule}_MODULE_MINOR_VERSION})
- message(SEND_ERROR \"Qt5${qtmodule}_VERSION_MINOR variable was not ${CMAKE_${qtmodule}_MODULE_MINOR_VERSION}. Got \${Qt5${qtmodule}_VERSION_MINOR} instead.\")
+ if(NOT \"\${Qt6${qtmodule}_VERSION_MINOR}\" VERSION_EQUAL ${CMAKE_${qtmodule}_MODULE_MINOR_VERSION})
+ message(SEND_ERROR \"Qt6${qtmodule}_VERSION_MINOR variable was not ${CMAKE_${qtmodule}_MODULE_MINOR_VERSION}. Got \${Qt6${qtmodule}_VERSION_MINOR} instead.\")
endif()
- if(NOT \"\${Qt5${qtmodule}_VERSION_PATCH}\" VERSION_EQUAL ${CMAKE_${qtmodule}_MODULE_PATCH_VERSION})
- message(SEND_ERROR \"Qt5${qtmodule}_VERSION_PATCH variable was not ${CMAKE_${qtmodule}_MODULE_PATCH_VERSION}. Got \${Qt5${qtmodule}_VERSION_PATCH} instead.\")
- endif()
- if(NOT \"\${Qt5${qtmodule}_VERSION_STRING}\" VERSION_EQUAL ${CMAKE_MODULE_VERSION})
- message(SEND_ERROR \"Qt5${qtmodule}_VERSION_STRING variable was not ${CMAKE_MODULE_VERSION}. Got \${Qt5${qtmodule}_VERSION_STRING} instead.\")
+ if(NOT \"\${Qt6${qtmodule}_VERSION_PATCH}\" VERSION_EQUAL ${CMAKE_${qtmodule}_MODULE_PATCH_VERSION})
+ message(SEND_ERROR \"Qt6${qtmodule}_VERSION_PATCH variable was not ${CMAKE_${qtmodule}_MODULE_PATCH_VERSION}. Got \${Qt6${qtmodule}_VERSION_PATCH} instead.\")
endif()\n"
)
endif()
- set(libraries_string "${libraries_string} Qt5::${qtmodule}")
+ set(libraries_string "${libraries_string} Qt6::${qtmodule}")
endwhile()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/module_includes/CMakeLists.txt"
"
- cmake_minimum_required(VERSION 2.8)
+ cmake_minimum_required(VERSION 3.14)
project(module_includes)
${packages_string}
- set(CMAKE_CXX_FLAGS \"\${CMAKE_CXX_FLAGS} \${Qt5Core_EXECUTABLE_COMPILE_FLAGS}\")
- if (CMAKE_VERSION VERSION_LESS 3.3)
- if (CMAKE_CXX_COMPILER_ID STREQUAL AppleClang
- OR (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang))
- set(CMAKE_CXX_FLAGS \"\${CMAKE_CXX_FLAGS} -std=gnu++0x -stdlib=libc++\")
- elseif (CMAKE_CXX_COMPILER_ID STREQUAL GNU
- OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
- set(CMAKE_CXX_FLAGS \"\${CMAKE_CXX_FLAGS} -std=gnu++0x\")
- endif()
- endif()
-
add_executable(module_includes_exe \"\${CMAKE_CURRENT_SOURCE_DIR}/main.cpp\")
target_link_libraries(module_includes_exe ${libraries_string})\n"
)
@@ -235,8 +267,8 @@ function(test_module_includes)
"${CMAKE_CURRENT_BINARY_DIR}/module_includes/"
"${CMAKE_CURRENT_BINARY_DIR}/module_includes/build"
--build-config "${CMAKE_BUILD_TYPE}"
- --build-generator ${CMAKE_GENERATOR}
- --build-makeprogram ${CMAKE_MAKE_PROGRAM}
+ --build-generator "${CMAKE_GENERATOR}"
+ --build-makeprogram "${CMAKE_MAKE_PROGRAM}"
--build-project module_includes
--build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${BUILD_OPTIONS_LIST}
)