Currently in order to compile a Qt6 test standalone one needs to use
the qt-cmake-standalone-test script which will load the
Qt6BuildInternals/QtStandaloneTestTemplateProject/CMakeLists.txt project
with the current test source directory to create a complete CMake project.
This commit will allow a test to have these lines at top:
cmake_minimum_required(VERSION 3.16)
if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
project(a_qt_test LANGUAGES C CXX ASM)
find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST)
endif()
and be standalone and work with any IDE capable of loading CMake projects.
Fixes: QTCREATORBUG-25389
Pick-to: 6.1
Change-Id: If3f878b7e560a8bfbb604a8f1aa30b7962742e66
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
The source permissions are transferred when using configure_file for
non-prefix builds. This allows running qt-cmake-standalone-test in
both non-prefix and prefix builds.
Change-Id: I38829901d0bd4dfc4b89c665169798052b218fb0
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Despite being installed in the the binary directory, this
CMake snippet cannot be executed.
Pick-to: 6.0
Change-Id: Ibfd31e51184f0688d19ac063804cc200c95555a7
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Make paths in qt-cmake-standalone-test relative to script's PWD.
Fixes: QTBUG-88380
Change-Id: I6ab507c31ebed391f4e85bc6fe3f7f747dd97d54
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This makes sure the executable is run as a shell script
with the proper interpreter on Unix systems.
Otherwise it will fail in some shells, like fish.
On windows, it prevents all commands in the batch file
from displaying on the screen.
Change-Id: If554262f172b035b9661b3e2ff26a96789fa707b
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
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 <leander.beernaert@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>