forked from qt/qtbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CMake: Provide script to configure and build one or more tests
Before this patch there were a few ways to build tests - Configure all tests as part of the repo build - Configure all tests as part of the repo build, but don't build tests by default (-DQT_NO_MAKE_TESTS=ON) - Configure all tests as a standalone project in a separate build dir using -QT_BUILD_STANDALONE_TESTS=ON All of the above incur some time overhead due to the necessity of configuring all tests. Sometimes you just want to build ONE test (or a few). To facilitate that use case, a new shell script called bin/qt-cmake-standalone-test(.bat) can now be used to configure and build one or more tests. The script takes one single argument pointing to the desired test project path and configures a generic template project that sets up all the necessary Qt CMake private API, afterwards calling add_subdirectory on the passed in project. Example $ path/to/qt/bin/qt-cmake-standalone-test ./tests/auto/gui/image/qicon or $ path/to/qt/bin/qt-cmake-standalone-test ./tests/auto/gui/image After that, simply run 'ninja && ctest' to build and run the test(s). This is the CMake equivalent of calling qmake on a test .pro file (or on a tests SUBDIRS .pro file) There are 3 details worth mentioning. Due to the add_subdirectory call, the built artifacts will not be in the top-level build dir, but rather in a nested build_dir. The script currently can't handle more than one argument (the path to the project), so you can't pass additional -DFoo=bar arguments. If a test uses a 3rd party library (like Threads::Threads) which was not a public dependency for any of the Qt modules, configuration will fail saying that the target was not found. Perhaps we should consider recording these packages when generating the StandaloneConfig.cmake files. Change-Id: Icde6ecb839341d34f341d9a19402c91196ed5aa0 Reviewed-by: Leander Beernaert <[email protected]> Reviewed-by: Alexandru Croitor <[email protected]>
- Loading branch information
Showing
4 changed files
with
95 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@__qt_cmake_private_path@ @__qt_cmake_standalone_test_path@ -DQT_STANDALONE_TEST_PATH=@__qt_cmake_standalone_passed_args@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
cmake/QtBuildInternals/QtStandaloneTestTemplateProject/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
project(qt_single_test VERSION 6.0.0 LANGUAGES C CXX ASM) | ||
|
||
find_package(Qt6 REQUIRED COMPONENTS BuildInternals) | ||
|
||
# Includes QtSetup and friends for private CMake API. | ||
qt_build_internals_set_up_private_api() | ||
|
||
# Find all StandaloneTestsConfig.cmake files, and include them | ||
# This will find all Qt packages that are required for standalone tests. | ||
# It will find more packages that needed for a certain test, but will ensure any test can | ||
# be built. | ||
qt_get_standalone_tests_confg_files_path(standalone_tests_config_path) | ||
file(GLOB config_files "${standalone_tests_config_path}/*") | ||
foreach(file ${config_files}) | ||
include("${file}") | ||
endforeach() | ||
|
||
# Get the absolute path of the passed-in project dir, relative to the current working directory | ||
# of the calling script, rather than relative to this source directory. | ||
# The calling script sets PWD. If not set, just use the passed-in value as-is. | ||
if(DEFINED PWD) | ||
get_filename_component(absolute_project_path "${QT_STANDALONE_TEST_PATH}" ABSOLUTE | ||
BASE_DIR "${PWD}") | ||
else() | ||
set(absolute_project_path "${QT_STANDALONE_TEST_PATH}") | ||
endif() | ||
|
||
# Add the test project path as a subdirectory project. | ||
add_subdirectory("${absolute_project_path}" "build_dir") |