CMake: Build minimal subset of tests in desktop static builds

Add new configure option -make minimal-static-tests and CMake option
QT_BUILD_MINIMAL_STATIC_TESTS. In conjunction with QT_BUILD_TESTS
it will enable building a minimal subset of tests when targeting
a static desktop Qt build.

In qtbase the minimal subset includes all the auto tests of testlib,
tools, corelib and cmake. In particular this will also do cmake build
tests and qmake build tests (tst_qmake)

Adjust CI instructions to enable building a minimal subset of static
tests when a platform configuration is tagged with the
MinimalStaticTests feature.

Fix and skip a few tests that were failing.

Pick-to: 6.1
Task-number: QTBUG-87580
Task-number: QTBUG-91869
Change-Id: I1fc311b8d5e743ccf05047fb9a7fdb813a645206
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Alexandru Croitor 2021-03-15 17:03:38 +01:00
parent c87847db87
commit 0e6c4224f0
12 changed files with 58 additions and 33 deletions

View File

@ -511,11 +511,13 @@ macro(qt_build_tests)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/auto/CMakeLists.txt")
add_subdirectory(auto)
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/CMakeLists.txt" AND QT_BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/manual/CMakeLists.txt" AND QT_BUILD_MANUAL_TESTS)
add_subdirectory(manual)
if(NOT QT_BUILD_MINIMAL_STATIC_TESTS)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/CMakeLists.txt" AND QT_BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/manual/CMakeLists.txt" AND QT_BUILD_MANUAL_TESTS)
add_subdirectory(manual)
endif()
endif()
endmacro()

View File

@ -662,7 +662,7 @@ function(check_qt_build_parts type)
set(buildFlag "FALSE")
endif()
list(APPEND knownParts "tests" "examples" "benchmarks")
list(APPEND knownParts "tests" "examples" "benchmarks" "manual-tests" "minimal-static-tests")
foreach(part ${${input}})
if(part IN_LIST knownParts)

View File

@ -164,6 +164,7 @@ option(QT_BUILD_EXAMPLES "Build Qt examples" OFF)
option(QT_BUILD_EXAMPLES_BY_DEFAULT "Should examples be built as part of the default 'all' target." ON)
option(QT_BUILD_MANUAL_TESTS "Build Qt manual tests" OFF)
option(QT_BUILD_MINIMAL_STATIC_TESTS "Build minimal subset of tests for static Qt builds" OFF)
## Find host tools (if non native):
set(QT_HOST_PATH "" CACHE PATH "Installed Qt host directory path, used for cross compiling.")

View File

@ -23,6 +23,15 @@ instructions:
env_var: COIN_CMAKE_ARGS
equals_value: null
# Inform CMake to build just a minimal set of tests for static Qt builds.
- type: AppendToEnvironmentVariable
variableName: COIN_CMAKE_ARGS
variableValue: " -DQT_BUILD_MINIMAL_STATIC_TESTS=ON"
enable_if:
condition: property
property: features
contains_value: "MinimalStaticTests"
- !include "{{qt/qtbase}}/call_cmake_for_standalone_tests.yaml"
- type: ExecuteCommand
command: "{{.Env.TESTS_ENV_PREFIX}} cmake --build . --parallel -v"
@ -35,7 +44,3 @@ instructions:
archiveDirectory: "{{.BuildDir}}"
maxTimeInSeconds: 1200
maxTimeBetweenOutput: 1200
disable_if:
condition: property
property: configureArgs
contains_value: "-DBUILD_SHARED_LIBS=OFF"

View File

@ -2,7 +2,3 @@ type: Group
instructions:
- !include "{{qt/qtbase}}/cmake_regular_test_instructions_common.yaml"
- !include "{{qt/qtbase}}/cmake_run_ctest_enforce_exit_code.yaml"
disable_if:
condition: property
property: configureArgs
contains_value: "-DBUILD_SHARED_LIBS=OFF"

View File

@ -175,8 +175,10 @@ Component selection:
-skip <repo> ......... Exclude an entire repository from the build.
-make <part> ......... Add <part> to the list of parts to be built.
Specifying this option clears the default list first.
[libs and examples, also tools if not cross-building,
also tests if -developer-build]
(allowed values: libs, tools, examples, tests,
benchmarks, manual-tests, minimal-static-tests)
[default: libs and examples, also tools if not
cross-building, also tests if -developer-build]
-nomake <part> ....... Exclude <part> from the list of parts to be built.
-gui ................. Build the Qt GUI module and dependencies [yes]
-widgets ............. Build the Qt Widgets module and dependencies [yes]

View File

@ -74,13 +74,14 @@ qt_commandline_option(linker TYPE optionalString VALUES bfd gold lld)
qt_commandline_option(ltcg TYPE boolean)
# special case begin
qt_commandline_option(make TYPE addString VALUES examples libs tests tools
benchmarks)
benchmarks manual-tests minimal-static-tests)
# special case end
qt_commandline_option(make-tool TYPE string)
qt_commandline_option(mips_dsp TYPE boolean)
qt_commandline_option(mips_dspr2 TYPE boolean)
qt_commandline_option(mp TYPE boolean NAME msvc_mp)
qt_commandline_option(nomake TYPE addString VALUES examples tests tools benchmarks) # special case
qt_commandline_option(nomake TYPE addString VALUES examples tests tools benchmarks
manual-tests minimal-static-tests) # special case
qt_commandline_option(opensource TYPE void NAME commercial VALUE no)
qt_commandline_option(optimize-debug TYPE boolean NAME optimize_debug)
qt_commandline_option(optimize-size TYPE boolean NAME optimize_size)

View File

@ -22,6 +22,12 @@ if (TARGET Qt::Xml AND TARGET Qt::Sql AND TARGET Qt::Network)
add_subdirectory(cmake)
endif()
# special case end
# Limit set of tests to run for static Qt builds.
if(QT_BUILD_MINIMAL_STATIC_TESTS)
return()
endif()
if (TARGET Qt::Concurrent)
add_subdirectory(concurrent)
endif()

View File

@ -14,23 +14,15 @@ add_executable(test_interface_exe WIN32 main.cpp mainwindow.cpp)
# link explicitly to Qt::WinMain.
target_link_libraries(test_interface_exe Qt::Widgets)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/try_compile-test.cpp"
"
#include <QString>
#include <QWidget>
int main(int,char**) { QWidget w; w.show(); return 0; }
"
)
# Fix try_compile to inherit the parent configuration.
set(CMAKE_TRY_COMPILE_CONFIGURATION "${CMAKE_BUILD_TYPE}")
# The try_compile works because Qt::Widgets is listed in the LINK_LIBRARIES,
# which causes the includes, defines and appropriate PIC flag to be used.
try_compile(_TRY_COMPILE_RES "${CMAKE_CURRENT_BINARY_DIR}/try_compile-test"
"${CMAKE_CURRENT_BINARY_DIR}/try_compile-test.cpp"
LINK_LIBRARIES Qt::Widgets
# Can't use source file based try_compile, because it doesn't handle object libraries
# referenced in generator expressions properly.
try_compile(_TRY_COMPILE_RES
"${CMAKE_CURRENT_BINARY_DIR}/widget_test"
"${CMAKE_CURRENT_SOURCE_DIR}/widget_test"
widget_test
OUTPUT_VARIABLE TC_OV
)

View File

@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.14)
project(test_interface_try_compile)
find_package(Qt6Widgets)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_executable(test_interface_try_compile_exe main.cpp)
target_link_libraries(test_interface_try_compile_exe Qt::Widgets)

View File

@ -0,0 +1,4 @@
#include <QString>
#include <QWidget>
int main(int, char**) { QWidget w; w.show(); return 0; }

View File

@ -746,6 +746,9 @@ void tst_qmessagehandler::qMessagePattern_data()
#define QT_NAMESPACE_STR ""
#endif
#if QT_CONFIG(static)
QSKIP("These test cases don't work with static Qt builds");
#else
#ifndef QT_NO_DEBUG
QTest::newRow("backtrace") << "[%{backtrace}] %{message}" << true << (QList<QByteArray>()
// MyClass::qt_static_metacall is explicitly marked as hidden in the Q_OBJECT macro
@ -755,7 +758,8 @@ void tst_qmessagehandler::qMessagePattern_data()
QTest::newRow("backtrace depth,separator") << "[%{backtrace depth=2 separator=\"\n\"}] %{message}" << true << (QList<QByteArray>()
<< "[MyClass::myFunction\nMyClass::mySlot1] from_a_function 34"
<< "[T::T\n");
#endif
#endif // #if !QT_CONFIG(process)
#endif // #ifdef __GLIBC__
}