Make standalone tests build via top level repo project

Previously repo/tests/CMakeLists.txt was a standalone project on which
CMake could be called. This was useful for Coin to be able to build
and package only tests, but was a bit troublesome because that means
having to specify the usual boilerplate like minimum CMake version,
which packages to find in every tests.pro project.

Instead of having a separate standalone project, modify the top level
project and associated CMake code to allow passing a special
QT_BUILD_STANDALONE_TESTS variable, which causes the top level project
to build only tests, and find Qt in the previously installed qt
location.

This also means that when building a repo, we generate a
${repo_name}TestsConfig.cmake file which does find_package on all the
modules that have been built as part of that repo. So that when
standalone tests bare built for that repo, the modules are
automatically found.

qt_set_up_standalone_tests_build() is modified to be a no-op because
it is not needed anymore. Its usage should be removed from all the
other repos, and then removed from qtbase.

Non-adjusted tests/CMakeLists.txt projects in other repositories
should still be buildable with the current code, until they are updated
to the new format.

Adjust the Coin build instructions to build the standalone tests in a
separate directory.

Adjust pro2cmake to generate new structure for the tests/tests.pro
projects.

Adjust the qtbase tests project.

Fixes: QTBUG-79239
Change-Id: Ib4b66bc772d8876cdcbae1e90ce5a5a5234fa675
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Alexandru Croitor 2019-11-01 11:48:23 +01:00
parent c1ba9bb72a
commit de3a806def
11 changed files with 182 additions and 121 deletions

View File

@ -10,68 +10,75 @@ project(QtBase
LANGUAGES CXX C ASM
)
## Add some paths to check for cmake modules:
list(PREPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/3rdparty/extra-cmake-modules/find-modules"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/3rdparty/kwin"
)
if(NOT QT_BUILD_STANDALONE_TESTS)
## Add some paths to check for cmake modules:
list(PREPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/3rdparty/extra-cmake-modules/find-modules"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/3rdparty/kwin"
)
## Find the build internals package.
set(QT_BUILD_INTERNALS_SKIP_CMAKE_MODULE_PATH_ADDITION TRUE)
list(PREPEND CMAKE_PREFIX_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
)
find_package(QtBuildInternals CMAKE_FIND_ROOT_PATH_BOTH)
unset(QT_BUILD_INTERNALS_SKIP_CMAKE_MODULE_PATH_ADDITION)
else()
# When building standalone tests, an istalled BuildInternals package already exists.
find_package(Qt6 REQUIRED COMPONENTS BuildInternals CMAKE_FIND_ROOT_PATH_BOTH)
endif()
## Find the build internals package.
set(QT_BUILD_INTERNALS_SKIP_CMAKE_MODULE_PATH_ADDITION TRUE)
list(PREPEND CMAKE_PREFIX_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
)
find_package(QtBuildInternals CMAKE_FIND_ROOT_PATH_BOTH)
unset(QT_BUILD_INTERNALS_SKIP_CMAKE_MODULE_PATH_ADDITION)
qt_build_repo_begin()
## Should this Qt be static or dynamically linked?
option(BUILD_SHARED_LIBS "Build Qt statically or dynamically" ON)
set(QT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
if(NOT QT_BUILD_STANDALONE_TESTS)
## Should this Qt be static or dynamically linked?
option(BUILD_SHARED_LIBS "Build Qt statically or dynamically" ON)
set(QT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
## Should this Qt be built with Werror?
option(WARNINGS_ARE_ERRORS "Build Qt with warnings as errors" ${FEATURE_developer_build})
## Should this Qt be built with Werror?
option(WARNINGS_ARE_ERRORS "Build Qt with warnings as errors" ${FEATURE_developer_build})
## Should Qt be built using PCH?
option(BUILD_WITH_PCH "Build Qt using precompiled headers?" ON)
## Should Qt be built using PCH?
option(BUILD_WITH_PCH "Build Qt using precompiled headers?" ON)
## QtBase specific configure tests:
include(QtBaseConfigureTests)
## QtBase specific configure tests:
include(QtBaseConfigureTests)
## Build System tests:
include(QtBaseCMakeTesting)
## Build System tests:
include(QtBaseCMakeTesting)
## Targets for global features, etc.:
include(QtBaseGlobalTargets)
## Targets for global features, etc.:
include(QtBaseGlobalTargets)
qt_set_language_standards()
## Set language standards after QtBaseGlobalTargets, because that's when the relevant
## feature variables are available.
qt_set_language_standards()
## Decide whether tools will be built.
qt_check_if_tools_will_be_built()
## Visit all the directories:
add_subdirectory(src)
endif()
## Visit all the directories:
add_subdirectory(src)
if (BUILD_TESTING)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
if (QT_WILL_BUILD_TOOLS)
add_subdirectory(qmake)
if(NOT QT_BUILD_STANDALONE_TESTS)
if(QT_WILL_BUILD_TOOLS)
add_subdirectory(qmake)
endif()
# As long as we use the mkspecs (for qplatformdefs.h), we need to always
# install it, especially when cross-compiling.
set(mkspecs_install_dir "${INSTALL_DATADIR}")
qt_path_join(mkspecs_install_dir ${QT_INSTALL_DIR} ${mkspecs_install_dir})
qt_copy_or_install(DIRECTORY "${PROJECT_SOURCE_DIR}/mkspecs"
DESTINATION ${mkspecs_install_dir})
endif()
# As long as we use the mkspecs (for qplatformdefs.h), we need to always
# install it, especially when cross-compiling.
set(mkspecs_install_dir "${INSTALL_DATADIR}")
qt_path_join(mkspecs_install_dir ${QT_INSTALL_DIR} ${mkspecs_install_dir})
qt_copy_or_install(DIRECTORY "${PROJECT_SOURCE_DIR}/mkspecs"
DESTINATION ${mkspecs_install_dir})
qt_build_repo_end()
if(BUILD_EXAMPLES)
if(NOT QT_BUILD_STANDALONE_TESTS AND BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

View File

@ -2,9 +2,12 @@
# Collection of auto dection routines to improve the user eperience when
# building Qt from source.
#
# Make sure to not run detection when building standalone tests, because the detection was already
# done when initially configuring qtbase.
function(qt_auto_detect_android)
if(DEFINED CMAKE_TOOLCHAIN_FILE AND NOT DEFINED QT_AUTODETECT_ANDROID)
if(DEFINED CMAKE_TOOLCHAIN_FILE AND NOT DEFINED QT_AUTODETECT_ANDROID
AND NOT QT_BUILD_STANDALONE_TESTS)
file(READ ${CMAKE_TOOLCHAIN_FILE} toolchain_file_content OFFSET 0 LIMIT 80)
string(FIND ${toolchain_file_content} "The Android Open Source Project" find_result REVERSE)
@ -31,7 +34,7 @@ function(qt_auto_detect_android)
endfunction()
function(qt_auto_detect_vpckg)
if(DEFINED ENV{VCPKG_ROOT})
if(DEFINED ENV{VCPKG_ROOT} AND NOT QT_BUILD_STANDALONE_TESTS)
set(vcpkg_toolchain_file "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
get_filename_component(vcpkg_toolchain_file "${vcpkg_toolchain_file}" ABSOLUTE)
@ -49,6 +52,10 @@ function(qt_auto_detect_vpckg)
message(STATUS "Using vcpkg triplet ${VCPKG_TARGET_TRIPLET}")
endif()
unset(vcpkg_toolchain_file)
message(STATUS "CMAKE_TOOLCHAIN_FILE is: ${CMAKE_TOOLCHAIN_FILE}")
if(DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
message(STATUS "VCPKG_CHAINLOAD_TOOLCHAIN_FILE is: ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
endif()
endif()
endfunction()

View File

@ -60,37 +60,42 @@ macro(qt_build_repo_begin)
# Find Apple frameworks if needed.
qt_find_apple_system_frameworks()
# Decide whether tools will be built.
qt_check_if_tools_will_be_built()
endmacro()
macro(qt_build_repo_end)
# Delayed actions on some of the Qt targets:
include(QtPostProcess)
if(NOT QT_BUILD_STANDALONE_TESTS)
# Delayed actions on some of the Qt targets:
include(QtPostProcess)
# Install the repo-specific cmake find modules.
qt_path_join(__qt_repo_install_dir ${QT_CONFIG_INSTALL_DIR} ${INSTALL_CMAKE_NAMESPACE})
# Install the repo-specific cmake find modules.
qt_path_join(__qt_repo_install_dir ${QT_CONFIG_INSTALL_DIR} ${INSTALL_CMAKE_NAMESPACE})
if(NOT PROJECT_NAME STREQUAL "QtBase")
if (EXISTS cmake)
qt_copy_or_install(DIRECTORY cmake/
DESTINATION "${__qt_repo_install_dir}"
FILES_MATCHING PATTERN "Find*.cmake"
)
if(NOT PROJECT_NAME STREQUAL "QtBase")
if (EXISTS cmake)
qt_copy_or_install(DIRECTORY cmake/
DESTINATION "${__qt_repo_install_dir}"
FILES_MATCHING PATTERN "Find*.cmake"
)
endif()
endif()
endif()
# Print a feature summary:
feature_summary(WHAT PACKAGES_FOUND
REQUIRED_PACKAGES_NOT_FOUND
RECOMMENDED_PACKAGES_NOT_FOUND
OPTIONAL_PACKAGES_NOT_FOUND
RUNTIME_PACKAGES_NOT_FOUND
FATAL_ON_MISSING_REQUIRED_PACKAGES)
# Print a feature summary:
feature_summary(WHAT PACKAGES_FOUND
REQUIRED_PACKAGES_NOT_FOUND
RECOMMENDED_PACKAGES_NOT_FOUND
OPTIONAL_PACKAGES_NOT_FOUND
RUNTIME_PACKAGES_NOT_FOUND
FATAL_ON_MISSING_REQUIRED_PACKAGES)
endif()
qt_print_build_instructions()
endmacro()
function(qt_print_build_instructions)
if(NOT PROJECT_NAME STREQUAL "QtBase")
if(NOT PROJECT_NAME STREQUAL "QtBase" OR QT_BUILD_STANDALONE_TESTS)
return()
endif()
@ -118,19 +123,18 @@ macro(qt_build_repo)
# If testing is enabled, try to find the qtbase Test package.
# Do this before adding src, because there might be test related conditions
# in source.
if (BUILD_TESTING)
if (BUILD_TESTING AND NOT QT_BUILD_STANDALONE_TESTS)
find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS Test)
endif()
## Decide whether tools will be built.
qt_check_if_tools_will_be_built()
if(NOT QT_BUILD_STANDALONE_TESTS)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/CMakeLists.txt")
add_subdirectory(src)
endif()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/CMakeLists.txt")
add_subdirectory(src)
endif()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tools/CMakeLists.txt")
add_subdirectory(tools)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tools/CMakeLists.txt")
add_subdirectory(tools)
endif()
endif()
if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeLists.txt")
@ -139,23 +143,34 @@ macro(qt_build_repo)
qt_build_repo_end()
if (BUILD_EXAMPLES AND BUILD_SHARED_LIBS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/CMakeLists.txt")
if (BUILD_EXAMPLES AND BUILD_SHARED_LIBS
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/CMakeLists.txt"
AND NOT QT_BUILD_STANDALONE_TESTS)
add_subdirectory(examples)
endif()
endmacro()
macro(qt_set_up_standalone_tests_build)
qt_set_up_build_internals_paths()
include(QtSetup)
# Optionally include a repo specific Setup module.
include(QtRepoSetup OPTIONAL)
qt_find_apple_system_frameworks()
qt_check_if_tools_will_be_built()
# Remove this macro once all usages of it have been removed.
# Standalone tests are not handled via the main repo project and qt_build_tests.
endmacro()
macro(qt_build_tests)
if(QT_BUILD_STANDALONE_TESTS)
# Find location of TestsConfig.cmake. These contain the modules that need to be
# find_package'd when testing.
set(_qt_build_tests_install_prefix
"${QT_CONFIG_INSTALL_DIR}/${INSTALL_CMAKE_NAMESPACE}BuildInternals/StandaloneTests")
if(QT_WILL_INSTALL)
qt_path_join(_qt_build_tests_install_prefix
${CMAKE_INSTALL_PREFIX} ${_qt_build_tests_install_prefix})
endif()
include("${_qt_build_tests_install_prefix}/${CMAKE_PROJECT_NAME}TestsConfig.cmake")
# Of course we always need the test module as well.
find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS Test)
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/auto/CMakeLists.txt")
add_subdirectory(auto)
endif()

View File

@ -346,10 +346,37 @@ function(qt_create_tools_config_files)
endforeach()
endfunction()
function(qt_internal_create_config_file_for_standalone_tests)
set(standalone_tests_config_dir "StandaloneTests")
qt_path_join(config_build_dir
${QT_CONFIG_BUILD_DIR}
"${INSTALL_CMAKE_NAMESPACE}BuildInternals" "${standalone_tests_config_dir}")
qt_path_join(config_install_dir
${QT_CONFIG_INSTALL_DIR}
"${INSTALL_CMAKE_NAMESPACE}BuildInternals" "${standalone_tests_config_dir}")
list(JOIN QT_REPO_KNOWN_MODULES " " QT_REPO_KNOWN_MODULES_STRING)
string(STRIP "${QT_REPO_KNOWN_MODULES_STRING}" QT_REPO_KNOWN_MODULES_STRING)
# Ceate a Config file that calls find_package on the modules that were built as part
# of the current repo. This is used for standalone tests.
configure_file(
"${QT_CMAKE_DIR}/QtStandaloneTestsConfig.cmake.in"
"${config_build_dir}/${CMAKE_PROJECT_NAME}TestsConfig.cmake"
@ONLY
)
qt_install(FILES
"${config_build_dir}/${CMAKE_PROJECT_NAME}TestsConfig.cmake"
DESTINATION "${config_install_dir}"
COMPONENT Devel
)
endfunction()
qt_create_tools_config_files()
qt_internal_create_depends_files()
qt_generate_build_internals_extra_cmake_code()
qt_internal_create_plugins_files()
qt_internal_create_config_file_for_standalone_tests()
if (ANDROID)
qt_modules_process_android_dependencies()

View File

@ -39,7 +39,7 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
# or when enabling developer builds and no prefix is specified.
# This detection only happens when building qtbase, and later is propagated via the generated
# QtBuildInternalsExtra.cmake file.
if (PROJECT_NAME STREQUAL "QtBase")
if (PROJECT_NAME STREQUAL "QtBase" AND NOT QT_BUILD_STANDALONE_TESTS)
if((CMAKE_INSTALL_PREFIX STREQUAL CMAKE_BINARY_DIR) OR
(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND FEATURE_developer_build))
@ -87,6 +87,14 @@ endif()
## Set up testing
option(BUILD_TESTING "Build the testing tree." ${QT_BUILD_TESTING})
if(QT_BUILD_STANDALONE_TESTS)
set(QT_BUILD_TESTING ON)
# BuildInternals might have set it to OFF on initial configuration. So force it to ON when
# building standalone tests.
set(BUILD_TESTING ON CACHE BOOL "Build the testing tree." FORCE)
endif()
include(CTest)
enable_testing()

View File

@ -0,0 +1,2 @@
find_package(@INSTALL_CMAKE_NAMESPACE@ @PROJECT_VERSION@
REQUIRED COMPONENTS @QT_REPO_KNOWN_MODULES_STRING@)

View File

@ -1,21 +1,16 @@
type: Group
instructions:
- type: ChangeDirectory
directory: "{{.SourceDir}}/tests"
directory: "{{.SourceDir}}"
- type: MakeDirectory
directory: "standalone_tests"
- type: SetBuildDirectory
directory: "{{.SourceDir}}/standalone_tests"
- type: ChangeDirectory
directory: "{{.BuildDir}}"
- type: EnvironmentVariable
variableName: COIN_CMAKE_ARGS
variableValue: "{{.SourceDir}}\\tests"
enable_if:
condition: property
property: host.os
equals_value: Windows
- type: EnvironmentVariable
variableName: COIN_CMAKE_ARGS
variableValue: "{{.SourceDir}}/tests"
disable_if:
condition: property
property: host.os
equals_value: Windows
variableValue: "-DQT_BUILD_STANDALONE_TESTS=ON -S {{.SourceDir}} -B ."
- !include "{{qt/qtbase}}/call_cmake.yaml"
- type: ExecuteCommand
command: "{{.Env.ENV_PREFIX}} cmake --build . --parallel"
@ -25,7 +20,7 @@ instructions:
Failed to build sources. In the current state bug can be everywhere. Contact Liang first.
- type: UploadTestArtifact
transferType: UploadModuleTestsArtifact
archiveDirectory: "{{.SourceDir}}/tests"
archiveDirectory: "{{.BuildDir}}"
maxTimeInSeconds: 1200
maxTimeBetweenOutput: 1200
disable_if:

View File

@ -1,14 +1,18 @@
type: Group
instructions:
- type: ChangeDirectory
directory: "{{.SourceDir}}"
- type: MakeDirectory
directory: "standalone_tests"
- type: InstallTestBinaryArchive
relativeStoragePath: "{{.Env.MODULE_ARTIFACTS_RELATIVE_STORAGE_PATH}}/tests.tar.gz"
directory: "{{.SourceDir}}/tests"
directory: "{{.SourceDir}}/standalone_tests"
maxTimeInSeconds: 1200
maxTimeBetweenOutput: 1200
userMessageOnFailure: >
Failed to install tests archive.
- type: ChangeDirectory
directory: "{{.SourceDir}}/tests"
directory: "{{.SourceDir}}/standalone_tests"
- type: ExecuteCommand
command: "ctest -V --rerun-failed"
ignoreExitCode: true

View File

@ -0,0 +1,7 @@
# Generated from tests.pro.
if(QT_BUILD_STANDALONE_TESTS)
# Add qt_find_package calls for extra dependencies that need to be found when building
# the standalone tests here.
endif()
qt_build_tests()

View File

@ -1,21 +1,13 @@
# special case begin
if(NOT TARGET Qt::Test)
cmake_minimum_required(VERSION 3.14.0)
project(QtBaseTests VERSION 6.0.0 LANGUAGES C CXX ASM)
find_package(Qt6 REQUIRED COMPONENTS BuildInternals Core Test)
find_package(Qt6 COMPONENTS DBus Gui OpenGL Widgets Xml
AccessibilitySupport LinuxAccessibilitySupport
WindowsUIAutomationSupport
)
qt_set_up_standalone_tests_build()
# Generated from tests.pro.
# Find a few packages that are usually found in configure.cmake,
# because a few tests link directly against those libraries.
if(QT_BUILD_STANDALONE_TESTS)
# Add qt_find_package calls for extra dependencies that need to be found when building
# the standalone tests here.
# special case begin
qt_find_package(WrapDBus1 PROVIDED_TARGETS dbus-1)
qt_find_package(ICU COMPONENTS i18n uc data PROVIDED_TARGETS ICU::i18n ICU::uc ICU::data)
qt_find_package(Threads PROVIDED_TARGETS Threads::Threads)
qt_find_package(OpenSSL PROVIDED_TARGETS OpenSSL::OpenSSL)
# special case end
endif()
# special case end
qt_build_tests()

View File

@ -3248,12 +3248,9 @@ def handle_top_level_repo_tests_project(scope: Scope, cm_fh: IO[str]):
content = dedent(
f"""\
if(NOT TARGET Qt::Test)
cmake_minimum_required(VERSION {cmake_version_string})
project({qt_lib} VERSION 6.0.0 LANGUAGES C CXX)
find_package(Qt6 ${{PROJECT_VERSION}} REQUIRED COMPONENTS BuildInternals Core SET_ME_TO_SOMETHING_USEFUL)
find_package(Qt6 ${{PROJECT_VERSION}} OPTIONAL_COMPONENTS SET_ME_TO_SOMETHING_USEFUL){requires_content}
qt_set_up_standalone_tests_build()
if(QT_BUILD_STANDALONE_TESTS)
# Add qt_find_package calls for extra dependencies that need to be found when building
# the standalone tests here.
endif()
qt_build_tests()
"""