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>
This commit is contained in:
Alexandru Croitor 2020-07-14 10:38:51 +02:00
parent 054b66a657
commit 96e3ee0659
41 changed files with 333 additions and 436 deletions

View File

@ -255,6 +255,10 @@ qt_add_module(Core
Threads::Threads # special case
PUBLIC_LIBRARIES # special case:
Qt::Platform # special case:
# special case begin
# Generated in QtBaseGlobalTargets
EXTRA_CMAKE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Qt6CTestMacros.cmake"
# special case end
)
# special case begin

View File

@ -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}
)

View File

@ -42,3 +42,6 @@ set(QT@PROJECT_VERSION_MAJOR@_INSTALL_PLUGINS "@INSTALL_PLUGINSDIR@")
set(QT@PROJECT_VERSION_MAJOR@_INSTALL_QML "@INSTALL_QMLDIR@")
set(QT@PROJECT_VERSION_MAJOR@_INSTALL_TESTS "@INSTALL_TESTSDIR@")
set(QT@PROJECT_VERSION_MAJOR@_INSTALL_TRANSLATIONS "@INSTALL_TRANSLATIONSDIR@")
get_filename_component(_Qt6CoreConfigDir ${CMAKE_CURRENT_LIST_FILE} PATH)
set(_Qt6CTestMacros "${_Qt6CoreConfigDir}/Qt6CTestMacros.cmake")

View File

@ -17,7 +17,7 @@ if (NOT CMAKE_CROSSCOMPILE AND QT_FEATURE_process)
add_subdirectory(tools)
endif()
add_subdirectory(corelib)
# add_subdirectory(cmake) ## FIXME: Does this still make sense in this form?
add_subdirectory(cmake)
if (TARGET Qt::Concurrent)
add_subdirectory(concurrent)
endif()

View File

@ -11,7 +11,6 @@ uikit {
SUBDIRS += testlib
qtConfig(process):!cross_compile: SUBDIRS += tools
SUBDIRS += corelib
!cross_compile: SUBDIRS += cmake
qtHaveModule(concurrent): SUBDIRS += concurrent
# QTBUG-63915: boot2qt fails dbus
qtHaveModule(dbus):!cross_compile:!boot2qt {
@ -32,7 +31,5 @@ qtHaveModule(printsupport): SUBDIRS += printsupport
qtHaveModule(sql): SUBDIRS += sql
qtHaveModule(widgets): SUBDIRS += widgets
qtHaveModule(xml): SUBDIRS += xml
!cross_compile: SUBDIRS += installed_cmake
SUBDIRS += other
installed_cmake.depends = cmake

View File

@ -1,10 +1,13 @@
# special case skip regeneration
# This is an automatic test for the CMake configuration files.
# To run it manually,
# 1) mkdir build # Create a build directory
# 2) cd build
# 3) cmake .. # Run cmake on this directory.
# 3) # Run cmake on this directory
# `$qt_prefix/bin/qt-cmake ..` or `cmake -DCMAKE_PREFIX_PATH=/path/to/qt ..`
# 4) ctest # Run ctest
# 5) ctest -V -R test_wrap_cpp_options # Run single test
#
# The expected output is something like:
#
@ -37,15 +40,46 @@
# needs to be set to the installation prefix or build prefix of Qt
# before running these tests.
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(qmake_cmake_files)
project(cmake_usage_tests)
enable_testing()
find_package(Qt5Core REQUIRED)
# Most of the tests fail to build on Boot2qt / qemu with undefined references to QtDBus because
# it's a private dependency of QtGui, and CMake for some reason doesn't generate an -rpath-link
# flag. Notably -rpath is specified which should implicitly enable -rpath-link, but that
# doesn't seem to be the case.
# Until this is figured out, disable the tests when cross-compiling to Linux.
if(UNIX AND NOT APPLE AND NOT WIN32 AND CMAKE_CROSSCOMPILING AND NOT QT_ENABLE_CMAKE_BOOT2QT_TESTS)
message(STATUS "Running CMake tests is disabled when cross-compiling to Linux / Boot2Qt.")
return()
endif()
include("${_Qt5CTestMacros}")
set(required_packages Core Network Xml Sql Test)
set(optional_packages DBus Gui Widgets PrintSupport OpenGL Concurrent)
# Setup the test when called as a completely standalone project.
find_package(Qt6 REQUIRED COMPONENTS ${required_packages})
find_package(Qt6 OPTIONAL_COMPONENTS ${optional_packages})
# Setup common test variables which were previously set by ctest_testcase_common.prf.
set(CMAKE_MODULES_UNDER_TEST "${required_packages}")
foreach(qt_package ${optional_packages})
set(package_name "${QT_CMAKE_EXPORT_NAMESPACE}${qt_package}")
list(APPEND CMAKE_MODULES_UNDER_TEST "${qt_package}")
endforeach()
foreach(qt_package ${CMAKE_MODULES_UNDER_TEST})
if(${package_name}_FOUND)
set(CMAKE_${qt_package}_MODULE_MAJOR_VERSION "${${package_name}_VERSION_MAJOR}")
set(CMAKE_${qt_package}_MODULE_MINOR_VERSION "${${package_name}_VERSION_MINOR}")
set(CMAKE_${qt_package}_MODULE_PATCH_VERSION "${${package_name}_VERSION_PATCH}")
endif()
endforeach()
include("${_Qt6CTestMacros}")
expect_pass(test_umbrella_config)
expect_pass(test_wrap_cpp_and_resources)
@ -58,7 +92,7 @@ expect_fail(test_wrap_cpp_options)
expect_pass(test_platform_defs_include)
expect_pass(test_qtmainwin_library)
if (HAVE_NINJA)
if (CMAKE_GENERATOR STREQUAL Ninja AND UNIX AND NOT WIN32)
make_directory("${CMAKE_CURRENT_SOURCE_DIR}/test_QFINDTESTDATA/build")
add_test(test_QFINDTESTDATA ${CMAKE_CTEST_COMMAND}
--build-and-test
@ -66,10 +100,12 @@ if (HAVE_NINJA)
# Build in a subdir of the source dir.
# This causes Ninja to use relative paths.
"${CMAKE_CURRENT_SOURCE_DIR}/test_QFINDTESTDATA/build"
--build-generator Ninja
--build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
--build-config "${CMAKE_BUILD_TYPE}"
--build-generator "${CMAKE_GENERATOR}"
--build-makeprogram "${CMAKE_MAKE_PROGRAM}"
--build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${BUILD_OPTIONS_LIST}
)
add_test(NAME run_test_QFINDTESTDATA COMMAND sh -c "cd \"${CMAKE_SOURCE_DIR}/test_QFINDTESTDATA/build/tests\" && ./test_QFINDTESTDATA -v2")
add_test(NAME run_test_QFINDTESTDATA COMMAND sh -c "cd \"${CMAKE_CURRENT_SOURCE_DIR}/test_QFINDTESTDATA/build/tests\" && ./test_QFINDTESTDATA -v2")
set_property(TEST run_test_QFINDTESTDATA
PROPERTY DEPENDS test_QFINDTESTDATA
@ -118,7 +154,7 @@ endif()
if (NOT NO_WIDGETS)
list(APPEND qt_module_includes
Widgets QWidget
OpenGL QGLBuffer
OpenGL QOpenGLBuffer
PrintSupport QPrinter
)
endif()
@ -133,9 +169,6 @@ test_module_includes(
${qt_module_includes}
)
expect_pass(test_concurrent_module)
if (QT_WITH_ANGLE OR (NOT WIN32 AND NOT APPLE AND NOT NO_EGL))
expect_pass(test_egl_lib)
endif()
expect_pass(test_opengl_lib)
if (NOT NO_WIDGETS)
@ -145,19 +178,17 @@ endif()
expect_pass(test_interface_link_libraries)
expect_pass(test_moc_macro_target)
if (NOT CMAKE_VERSION VERSION_LESS 3.9)
# The modification of TARGET_OBJECTS needs the following change in cmake
# https://gitlab.kitware.com/cmake/cmake/commit/93c89bc75ceee599ba7c08b8fe1ac5104942054f
expect_pass(test_add_big_resource)
endif()
# The modification of TARGET_OBJECTS needs the following change in cmake
# https://gitlab.kitware.com/cmake/cmake/commit/93c89bc75ceee599ba7c08b8fe1ac5104942054f
# FIXME: Doesn't currently work with namespaced Qt builds QTBUG-85620
# expect_pass(test_add_big_resource)
if (NOT CMAKE_VERSION VERSION_LESS 3.8)
# With earlier CMake versions, this test would simply run moc multiple times and lead to:
# /usr/bin/ld: error: CMakeFiles/mywidget.dir/mywidget_automoc.cpp.o: multiple definition of 'MyWidget::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)'
# /usr/bin/ld: CMakeFiles/mywidget.dir/moc_mywidget.cpp.o: previous definition here
# Reason: SKIP_* properties were added in CMake 3.8 only
expect_pass(test_QTBUG-63422)
endif()
# With earlier CMake versions, this test would simply run moc multiple times and lead to:
# /usr/bin/ld: error: CMakeFiles/mywidget.dir/mywidget_automoc.cpp.o: multiple definition of 'MyWidget::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)'
# /usr/bin/ld: CMakeFiles/mywidget.dir/moc_mywidget.cpp.o: previous definition here
# Reason: SKIP_* properties were added in CMake 3.8 only
expect_pass(test_QTBUG-63422)
expect_pass(test_import_plugins BINARY ${CMAKE_CTEST_COMMAND})
# FIXME: Needs porting of the qmake .pro files to create the modules and plugins in Qt6 CMake land.
# expect_pass(test_import_plugins BINARY ${CMAKE_CTEST_COMMAND})
expect_pass(test_versionless_targets)

View File

@ -1,20 +1,15 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project("test(needsquoting)dirname")
find_package(Qt5Widgets REQUIRED)
find_package(Qt6Widgets REQUIRED)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
add_definitions(${Qt5Widgets_DEFINITIONS})
set(CMAKE_INCLUDE_CURRENT_DIR ON)
qt5_wrap_cpp(moc_files mywidget.h)
qt5_wrap_ui(ui_files mywidget.ui)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
qt_wrap_cpp(moc_files mywidget.h)
qt_wrap_ui(ui_files mywidget.ui)
add_executable(mywidget mywidget.cpp ${moc_files} ${ui_files})
target_link_libraries(mywidget ${Qt5Widgets_LIBRARIES})
target_link_libraries(mywidget Qt::Widgets)

View File

@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 2.8.11)
cmake_minimum_required(VERSION 3.14)
project(test_QFINDTESTDATA)
find_package(Qt5Test REQUIRED)
find_package(Qt6Test REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

View File

@ -1,4 +1,6 @@
add_executable(test_QFINDTESTDATA WIN32 main.cpp)
target_link_libraries(test_QFINDTESTDATA Qt5::Test)
target_link_libraries(test_QFINDTESTDATA Qt::Test)
target_compile_definitions(test_QFINDTESTDATA PRIVATE QT_TESTCASE_BUILDDIR="${CMAKE_CURRENT_BINARY_DIR}")
target_compile_definitions(test_QFINDTESTDATA PRIVATE QT_TESTCASE_SOURCEDIR="${CMAKE_CURRENT_SOURCE_DIR}")

View File

@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_dependent_modules)
# Need to set the policy to link to qtmain.lib automatically.
cmake_policy(SET CMP0020 NEW)
find_package(Qt5Widgets REQUIRED)
find_package(Qt6Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
@ -14,9 +11,9 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
# make sure CMP0071 warnings cause a test failure
set(CMAKE_SUPPRESS_DEVELOPER_ERRORS FALSE CACHE INTERNAL "" FORCE)
qt5_wrap_cpp(moc_files mywidget.h)
qt5_wrap_ui(ui_files mywidget.ui)
qt5_add_resources(qrc_files res.qrc)
qt_wrap_cpp(moc_files mywidget.h)
qt_wrap_ui(ui_files mywidget.ui)
qt_add_resources(qrc_files res.qrc)
add_executable(mywidget
# source files
@ -30,4 +27,4 @@ add_executable(mywidget
${ui_files}
${qrc_files}
)
target_link_libraries(mywidget ${Qt5Widgets_LIBRARIES})
target_link_libraries(mywidget PRIVATE Qt::Widgets)

View File

@ -1,13 +1,13 @@
cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.14)
project(test_add_big_resource)
find_package(Qt5Core REQUIRED)
find_package(Qt6Core REQUIRED)
qt5_wrap_cpp(moc_files myobject.h)
qt_wrap_cpp(moc_files myobject.h)
qt5_add_big_resources(rcc_files "test_add_big_resource.qrc" "test_add_big_resource2.qrc")
qt_add_big_resources(rcc_files "test_add_big_resource.qrc" "test_add_big_resource2.qrc")
add_executable(myobject myobject.cpp ${moc_files} ${rcc_files})
target_link_libraries(myobject ${Qt5Core_LIBRARIES})
target_link_libraries(myobject PRIVATE Qt::Core)

View File

@ -1,15 +1,11 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_add_binary_resources_delayed_file)
find_package(Qt5Core REQUIRED)
find_package(Qt6Core REQUIRED)
include_directories(${Qt5Core_INCLUDE_DIRS})
add_definitions(${Qt5Core_DEFINITIONS})
qt5_add_binary_resources(rcc_file "${CMAKE_CURRENT_BINARY_DIR}/test_add_binary_resources_delayed_file.qrc" "${CMAKE_CURRENT_SOURCE_DIR}/existing.qrc")
qt_add_binary_resources(rcc_file "${CMAKE_CURRENT_BINARY_DIR}/test_add_binary_resources_delayed_file.qrc" "${CMAKE_CURRENT_SOURCE_DIR}/existing.qrc")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_add_binary_resources_delayed_file.qrc" "<!DOCTYPE RCC><RCC version=\"1.0\">
<qresource prefix=\"/\">
@ -18,7 +14,5 @@ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_add_binary_resources_delayed_file.q
</RCC>
")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
add_executable(test_add_binary_resources_delayed_file main.cpp)
target_link_libraries(test_add_binary_resources_delayed_file ${Qt5Core_LIBRARIES})
target_link_libraries(test_add_binary_resources_delayed_file PRIVATE Qt::Core)

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_add_resource_options)
@ -7,23 +7,17 @@ if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
endif()
find_package(Qt5Core REQUIRED HINTS ${Qt5Tests_PREFIX_PATH})
find_package(Qt6Core REQUIRED HINTS ${Qt6Tests_PREFIX_PATH})
include_directories(${Qt5Core_INCLUDE_DIRS})
add_definitions(${Qt5Core_DEFINITIONS})
qt5_wrap_cpp(moc_files myobject.h)
qt_wrap_cpp(moc_files myobject.h)
# Test options. The -binary option generates a binary to dlopen instead of
# a source file to compile. The compiler will consider it garbage when used
# in the add_executable call.
qt5_add_resources(rcc_files "test_macro_options.qrc" OPTIONS -binary)
qt_add_resources(rcc_files "test_macro_options.qrc" OPTIONS -binary)
# Test if OPTIONS can handle a quoted parameter. CMake would fail immediately!
qt5_add_resources(rcc_files_quoted_option "test_macro_options.qrc" OPTIONS -root "/")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
qt_add_resources(rcc_files_quoted_option "test_macro_options.qrc" OPTIONS -root "/")
add_executable(myobject myobject.cpp ${moc_files} ${rcc_files})
target_link_libraries(myobject ${Qt5Core_LIBRARIES})
target_link_libraries(myobject PRIVATE Qt::Core)

View File

@ -1,15 +1,11 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_add_resources_delayed_file)
find_package(Qt5Core REQUIRED)
find_package(Qt6Core REQUIRED)
include_directories(${Qt5Core_INCLUDE_DIRS})
add_definitions(${Qt5Core_DEFINITIONS})
qt5_add_resources(rcc_files "${CMAKE_CURRENT_BINARY_DIR}/test_add_resources_delayed_file.qrc")
qt_add_resources(rcc_files "${CMAKE_CURRENT_BINARY_DIR}/test_add_resources_delayed_file.qrc")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_add_resources_delayed_file.qrc" "<!DOCTYPE RCC><RCC version=\"1.0\">
<qresource prefix=\"/\">
@ -18,7 +14,5 @@ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_add_resources_delayed_file.qrc" "<!
</RCC>
")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
add_executable(test_add_resources_delayed_file main.cpp ${rcc_files})
target_link_libraries(test_add_resources_delayed_file ${Qt5Core_LIBRARIES})
target_link_libraries(test_add_resources_delayed_file PRIVATE Qt::Core)

View File

@ -1,22 +1,10 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_concurrent_module)
find_package(Qt5Concurrent 5.0.0 REQUIRED)
include_directories(
${Qt5Concurrent_INCLUDE_DIRS}
)
add_definitions(
${Qt5Concurrent_DEFINITIONS}
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
find_package(Qt6Concurrent 6.0.0 REQUIRED)
add_executable(mainapp main.cpp)
target_link_libraries(mainapp
${Qt5Concurrent_LIBRARIES}
)
target_link_libraries(mainapp PRIVATE Qt::Concurrent)

View File

@ -34,7 +34,8 @@
int main(int argc, char **argv)
{
QByteArray bytearray = "hello world";
QtConcurrent::run(bytearray, &QByteArray::split, ',');
auto result = QtConcurrent::run(&QByteArray::split, bytearray, ',');
Q_UNUSED(result);
return 0;
}

View File

@ -1,34 +1,26 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_dbus_module)
find_package(Qt5DBus 5.0.0 REQUIRED)
include_directories(
${Qt5DBus_INCLUDE_DIRS}
)
add_definitions(${Qt5DBus_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5DBus_EXECUTABLE_COMPILE_FLAGS}")
find_package(Qt6DBus 6.0.0 REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(my_srcs mydbusobject.cpp)
qt5_wrap_cpp(moc_files mydbusobject.h)
qt_wrap_cpp(moc_files mydbusobject.h)
qt5_generate_dbus_interface(
qt_generate_dbus_interface(
mydbusobject.h
${CMAKE_BINARY_DIR}/org.qtProject.Tests.MyDBusObject.xml
)
qt5_add_dbus_adaptor(my_srcs
qt_add_dbus_adaptor(my_srcs
${CMAKE_BINARY_DIR}/org.qtProject.Tests.MyDBusObject.xml
mydbusobject.h
MyDBusObject
)
add_executable(myobject ${my_srcs} ${moc_files})
target_link_libraries(myobject ${Qt5DBus_LIBRARIES})
target_link_libraries(myobject PRIVATE Qt6::DBus)

View File

@ -1,21 +1,15 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_dependent_modules)
# The module finds its dependencies
find_package(Qt5Widgets REQUIRED)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
add_definitions(${Qt5Core_DEFINITIONS})
find_package(Qt6Widgets REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
qt5_wrap_cpp(moc_files mywidget.h)
qt5_wrap_ui(ui_files mywidget.ui)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
qt_wrap_cpp(moc_files mywidget.h)
qt_wrap_ui(ui_files mywidget.ui)
add_executable(mywidget mywidget.cpp ${moc_files} ${ui_files})
target_link_libraries(mywidget ${Qt5Widgets_LIBRARIES})
target_link_libraries(mywidget Qt::Widgets)

View File

@ -1,14 +0,0 @@
cmake_minimum_required(VERSION 2.8)
project(test_egl_lib)
find_package(Qt5Gui REQUIRED)
include_directories(${Qt5Gui_INCLUDE_DIRS} ${Qt5Gui_EGL_INCLUDE_DIRS} )
add_definitions(${Qt5Gui_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS}")
add_executable(myobject main.cpp )
target_link_libraries(myobject ${Qt5Gui_LIBRARIES} ${Qt5Gui_EGL_LIBRARIES})

View File

@ -1,20 +1,18 @@
cmake_minimum_required(VERSION 2.8.11)
cmake_minimum_required(VERSION 3.14)
project(test_interface)
find_package(Qt5Widgets)
find_package(Qt6Widgets)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
add_executable(test_interface_exe WIN32 main.cpp mainwindow.cpp)
# No need to specify include directories, compile definitions, the PIC flag, or to
# link explicitly to Qt5::WinMain.
target_link_libraries(test_interface_exe Qt5::Widgets)
# link explicitly to Qt::WinMain.
target_link_libraries(test_interface_exe Qt::Widgets)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/try_compile-test.cpp"
"
@ -28,14 +26,14 @@ 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 Qt5::Widgets is listed in the LINK_LIBRARIES,
# 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 Qt5::Widgets
LINK_LIBRARIES Qt::Widgets
OUTPUT_VARIABLE TC_OV
)
if (NOT _TRY_COMPILE_RES)
message(SEND_ERROR "The use of try_compile with Qt5::Widgets failed. The output was :\n${TC_OV}")
message(SEND_ERROR "The use of try_compile with Qt::Widgets failed. The output was :\n${TC_OV}")
endif()

View File

@ -1,21 +1,19 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_interface_link_libraries)
find_package(Qt5Gui REQUIRED)
find_package(Qt6Gui REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
cmake_policy(SET CMP0022 NEW)
include(GenerateExportHeader)
add_library(somelib SHARED somelib.cpp)
generate_export_header(somelib)
set_property(TARGET somelib PROPERTY LINK_LIBRARIES Qt5::Gui)
set_property(TARGET somelib PROPERTY INTERFACE_LINK_LIBRARIES Qt5::Gui)
set_property(TARGET somelib PROPERTY LINK_LIBRARIES Qt::Gui)
set_property(TARGET somelib PROPERTY INTERFACE_LINK_LIBRARIES Qt::Gui)
add_executable(mainexe main.cpp)
set_property(TARGET mainexe PROPERTY LINK_LIBRARIES somelib)

View File

@ -1,21 +1,15 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_json_plugin_includes)
find_package(Qt5Core REQUIRED)
include_directories(${Qt5Core_INCLUDE_DIRS})
add_definitions(${Qt5Core_DEFINITIONS})
find_package(Qt6Core REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/jsontestplugin.json" "{}\n")
qt5_wrap_cpp(moc_files plugin.h)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
qt_wrap_cpp(moc_files plugin.h)
add_library(plugin plugin.cpp ${moc_files})
target_link_libraries(plugin ${Qt5Core_LIBRARIES})
target_link_libraries(plugin Qt::Core)

View File

@ -1,23 +1,23 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_moc_macro_target)
find_package(Qt5Core REQUIRED)
find_package(Qt6Core REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
qt5_generate_moc(main_gen_test.cpp
qt_generate_moc(main_gen_test.cpp
"${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc"
TARGET Qt5GenerateMacroTest
TARGET QtGenerateMacroTest
)
add_executable(Qt5GenerateMacroTest main_gen_test.cpp "${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc")
target_include_directories(Qt5GenerateMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface")
target_link_libraries(Qt5GenerateMacroTest Qt5::Core)
add_executable(QtGenerateMacroTest main_gen_test.cpp "${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc")
target_include_directories(QtGenerateMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface")
target_link_libraries(QtGenerateMacroTest PRIVATE Qt6::Core)
qt5_wrap_cpp(moc_file mywrapobject.h
TARGET Qt5WrapMacroTest
qt_wrap_cpp(moc_file mywrapobject.h
TARGET QtWrapMacroTest
)
add_executable(Qt5WrapMacroTest main_wrap_test.cpp ${moc_file})
target_include_directories(Qt5WrapMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface")
target_link_libraries(Qt5WrapMacroTest Qt5::Core)
add_executable(QtWrapMacroTest main_wrap_test.cpp ${moc_file})
target_include_directories(QtWrapMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface")
target_link_libraries(QtWrapMacroTest PRIVATE Qt::Core)

View File

@ -1,13 +1,11 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_multiple_find_package)
find_package(Qt5Core REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
find_package(Qt6Core REQUIRED)
add_subdirectory(subdir1)
add_executable(exe1 main.cpp)
target_link_libraries(exe1 Qt5::Core)
target_link_libraries(exe1 Qt::Core)

View File

@ -1,5 +1,5 @@
find_package(Qt5Core REQUIRED)
find_package(Qt6Core REQUIRED)
add_executable(exe2 "${CMAKE_CURRENT_SOURCE_DIR}/../main.cpp")
target_link_libraries(exe2 Qt5::Core)
target_link_libraries(exe2 Qt::Core)

View File

@ -1,36 +1,16 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_opengl_lib)
find_package(Qt5Gui REQUIRED)
find_package(Qt6Gui REQUIRED)
find_package(Qt6OpenGL REQUIRED)
include_directories(${Qt5Gui_INCLUDE_DIRS} ${Qt5Gui_OPENGL_INCLUDE_DIRS} )
add_definitions(${Qt5Gui_DEFINITIONS})
get_property(QtGui_enabled_features TARGET Qt5::Gui PROPERTY INTERFACE_QT_ENABLED_FEATURES)
get_property(QtGui_enabled_features TARGET Qt6::Gui PROPERTY QT_ENABLED_PUBLIC_FEATURES)
list(LENGTH QtGui_enabled_features _QtGui_enabled_featuresSize)
if (_QtGui_enabled_featuresSize LESS 1)
message(SEND_ERROR "The INTERFACE_QT_ENABLED_FEATURES property of Qt5::Gui is empty!")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS}")
if (${Qt5Gui_OPENGL_IMPLEMENTATION} STREQUAL GLESv2)
list(FIND QtGui_enabled_features "opengles2" _opengles2Index)
if(_opengles2Index EQUAL -1)
message(SEND_ERROR "The INTERFACE_QT_ENABLED_FEATURES property of Qt5::Gui does not contain the opengles2 feature!")
endif()
add_definitions(-DGL_IMPLEMENTATION_GLES2)
elseif (${Qt5Gui_OPENGL_IMPLEMENTATION} STREQUAL GL)
list(FIND QtGui_enabled_features "opengl" _openglIndex)
if(_openglIndex EQUAL -1)
message(SEND_ERROR "The INTERFACE_QT_ENABLED_FEATURES property of Qt5::Gui does not contain the opengl feature!")
endif()
add_definitions(-DGL_IMPLEMENTATION_GL)
else()
message(SEND_ERROR "Qt5Gui_OPENGL_IMPLEMENTATION does not contain valid data.")
message(SEND_ERROR "The QT_ENABLED_PUBLIC_FEATURES property of Qt6::Gui is empty!")
endif()
add_executable(myobject main.cpp )
target_link_libraries(myobject ${Qt5Gui_LIBRARIES} ${Qt5Gui_OPENGL_LIBRARIES})
target_link_libraries(myobject Qt::Gui Qt::OpenGL)

View File

@ -28,30 +28,11 @@
#include <qglobal.h>
#ifndef QT_OPENGL_DYNAMIC
# if defined(GL_IMPLEMENTATION_GLES2)
# include <GLES2/gl2.h>
# elif defined(GL_IMPLEMENTATION_GL)
# ifdef Q_OS_WIN
# include <qt_windows.h>
# endif
# ifdef Q_OS_MAC
# include <OpenGL/gl.h>
# else
# include <GL/gl.h>
# endif
# endif
#else
# include <QOpenGLFunctions>
#endif
#include <QOpenGLFunctions>
int main(int argc, char **argv)
{
#ifndef QT_OPENGL_DYNAMIC
glGetError();
#else
QOpenGLFunctions functions;
functions.glGetError();
#endif
return 0;
}

View File

@ -1,14 +1,9 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_platform_defs_include)
find_package(Qt5Core REQUIRED)
include_directories(${Qt5Core_INCLUDE_DIRS})
add_definitions(${Qt5Core_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
find_package(Qt6Core REQUIRED)
add_executable(myobject main.cpp)
target_link_libraries(myobject Qt5::Core)
target_link_libraries(myobject PRIVATE Qt6::Core)

View File

@ -1,25 +1,17 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_plugins)
find_package(Qt5Network 5.0.0 REQUIRED)
include_directories(
${Qt5Network_INCLUDE_DIRS}
)
add_definitions(${Qt5Netork_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Netork_EXECUTABLE_COMPILE_FLAGS}")
find_package(Qt6Network 6.0.0 REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(NOT Qt5Network_PLUGINS)
message(SEND_ERROR "Qt5 network plugins not known!")
if(NOT Qt6Network_PLUGINS)
message(SEND_ERROR "Qt6 network plugins not known!")
endif()
foreach(plugin ${Qt5Network_PLUGINS})
foreach(plugin ${Qt6Network_PLUGINS})
get_target_property(_loc ${plugin} LOCATION)
if (NOT EXISTS "${_loc}")
message(SEND_ERROR "Plugin ${plugin} not found at ${_loc}")

View File

@ -1,18 +1,9 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_private_includes)
find_package(Qt5Gui REQUIRED Private)
include_directories(
${Qt5Gui_INCLUDE_DIRS}
${Qt5Gui_PRIVATE_INCLUDE_DIRS}
)
add_definitions(${Qt5Gui_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS}")
find_package(Qt6Gui REQUIRED)
add_executable(testapp main.cpp)
target_link_libraries(testapp ${Qt5Gui_LIBRARIES})
target_link_libraries(testapp PRIVATE Qt::GuiPrivate)

View File

@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.14)
project(test_private_targets)
find_package(Qt5Gui REQUIRED)
find_package(Qt6Gui REQUIRED)
add_executable(testapp main.cpp)
target_link_libraries(testapp Qt5::GuiPrivate)
target_link_libraries(testapp Qt::GuiPrivate)

View File

@ -1,20 +1,14 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_qtmainwin_library)
find_package(Qt5Core REQUIRED)
find_package(Qt6Core REQUIRED)
include_directories(${Qt5Core_INCLUDE_DIRS})
qt_wrap_cpp(moc_files myobject.h)
add_definitions(${Qt5Core_DEFINITIONS})
qt5_wrap_cpp(moc_files myobject.h)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
# On non-windows, the WIN32 is harmless, and Qt5Core_QTMAIN_LIBRARIES is empty.
# On non-windows, the WIN32 is harmless, and Qt6Core_QTMAIN_LIBRARIES is empty.
# We test that it is harmless on those, and test that it builds on Windows.
# It wouldn't build if WIN32 is used and Qt5Core_QTMAIN_LIBRARIES is empty.
# It wouldn't build if WIN32 is used and Qt6Core_QTMAIN_LIBRARIES is empty.
add_executable(myobject WIN32 myobject.cpp ${moc_files} )
target_link_libraries(myobject ${Qt5Core_LIBRARIES} ${Qt5Core_QTMAIN_LIBRARIES})
target_link_libraries(myobject PRIVATE Qt::Core ${Qt6Core_QTMAIN_LIBRARIES})

View File

@ -1,35 +1,23 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.14)
project(test_testlib_definitions)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
macro(test_testlib_project _module)
find_package(Qt5${_module} REQUIRED)
find_package(Qt5Test REQUIRED)
add_definitions(
${Qt5${_module}_DEFINITIONS}
${Qt5Test_DEFINITIONS}
)
include_directories(
${Qt5${_module}_INCLUDE_DIRS}
${Qt5Test_INCLUDE_DIRS}
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5${_module}_EXECUTABLE_COMPILE_FLAGS}")
find_package(Qt6${_module} REQUIRED)
find_package(Qt6Test REQUIRED)
set(main_file "${CMAKE_CURRENT_SOURCE_DIR}/../main.cpp")
set(moc_file "${CMAKE_CURRENT_BINARY_DIR}/main.moc")
qt5_generate_moc("${main_file}" "${moc_file}")
qt_generate_moc("${main_file}" "${moc_file}")
add_executable(testapp_${_module} "${main_file}" "${moc_file}")
target_link_libraries(testapp_${_module}
${Qt5${_module}_LIBRARIES}
${Qt5Test_LIBRARIES}
Qt::${_module}
Qt::Test
)
endmacro()

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(no_link_gui)
@ -9,25 +9,23 @@ if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
endif()
find_package(Qt5Gui REQUIRED HINTS ${Qt5Tests_PREFIX_PATH})
find_package(Qt5Test REQUIRED HINTS ${Qt5Tests_PREFIX_PATH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
find_package(Qt6Gui REQUIRED HINTS ${Qt6Tests_PREFIX_PATH})
find_package(Qt6Test REQUIRED HINTS ${Qt6Tests_PREFIX_PATH})
include_directories(
${Qt5Gui_INCLUDE_DIRS}
${Qt5Test_INCLUDE_DIRS}
${Qt6Gui_INCLUDE_DIRS}
${Qt6Test_INCLUDE_DIRS}
)
add_definitions(
${Qt5Gui_DEFINITIONS}
${Qt5Test_DEFINITIONS}
${Qt6Gui_DEFINITIONS}
${Qt6Test_DEFINITIONS}
)
set(main_file "main.cpp")
set(moc_file "${CMAKE_CURRENT_BINARY_DIR}/main.moc")
qt5_generate_moc("${main_file}" "${moc_file}")
qt_generate_moc("${main_file}" "${moc_file}")
# The core_test is expected to fail to build because
# QT_GUI_LIB is defined, which affects the contents of
@ -39,12 +37,12 @@ qt5_generate_moc("${main_file}" "${moc_file}")
# be necessary to comment out the core_test and re-run cmake)
add_executable(core_test "${main_file}" "${moc_file}")
target_link_libraries(core_test
${Qt5Core_LIBRARIES}
${Qt5Test_LIBRARIES}
${Qt6Core_LIBRARIES}
${Qt6Test_LIBRARIES}
)
add_executable(gui_test "${main_file}" "${moc_file}")
target_link_libraries(gui_test
${Qt5Gui_LIBRARIES}
${Qt5Test_LIBRARIES}
${Qt6Gui_LIBRARIES}
${Qt6Test_LIBRARIES}
)

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(no_link_widgets)
@ -9,25 +9,23 @@ if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
endif()
find_package(Qt5Widgets REQUIRED HINTS ${Qt5Tests_PREFIX_PATH})
find_package(Qt5Test REQUIRED HINTS ${Qt5Tests_PREFIX_PATH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
find_package(Qt6Widgets REQUIRED HINTS ${Qt6Tests_PREFIX_PATH})
find_package(Qt6Test REQUIRED HINTS ${Qt6Tests_PREFIX_PATH})
include_directories(
${Qt5Widgets_INCLUDE_DIRS}
${Qt5Test_INCLUDE_DIRS}
${Qt6Widgets_INCLUDE_DIRS}
${Qt6Test_INCLUDE_DIRS}
)
add_definitions(
${Qt5Widgets_DEFINITIONS}
${Qt5Test_DEFINITIONS}
${Qt6Widgets_DEFINITIONS}
${Qt6Test_DEFINITIONS}
)
set(main_file "main.cpp")
set(moc_file "${CMAKE_CURRENT_BINARY_DIR}/main.moc")
qt5_generate_moc("${main_file}" "${moc_file}")
qt_generate_moc("${main_file}" "${moc_file}")
# The core_test is expected to fail to build because
# QT_WIDGETS_LIB is defined, which affects the contents of
@ -40,12 +38,12 @@ qt5_generate_moc("${main_file}" "${moc_file}")
# be necessary to comment out the core_test and re-run cmake)
add_executable(core_test "${main_file}" "${moc_file}")
target_link_libraries(core_test
${Qt5Core_LIBRARIES}
${Qt5Test_LIBRARIES}
${Qt6Core_LIBRARIES}
${Qt6Test_LIBRARIES}
)
add_executable(widgets_test "${main_file}" "${moc_file}")
target_link_libraries(widgets_test
${Qt5Widgets_LIBRARIES}
${Qt5Test_LIBRARIES}
${Qt6Widgets_LIBRARIES}
${Qt6Test_LIBRARIES}
)

View File

@ -1,20 +1,20 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_umbrella_config)
add_subdirectory(components_found)
if (Qt5_FOUND)
message(SEND_ERROR "Qt5_FOUND variable leaked!")
if (Qt6_FOUND)
message(SEND_ERROR "Qt6_FOUND variable leaked!")
endif()
if (Qt5Core_FOUND)
message(SEND_ERROR "Qt5Core_FOUND variable leaked!")
if (Qt6Core_FOUND)
message(SEND_ERROR "Qt6Core_FOUND variable leaked!")
endif()
if (TARGET Qt5::Core)
message(SEND_ERROR "Qt5::Core target leaked!")
if (TARGET Qt6::Core)
message(SEND_ERROR "Qt6::Core target leaked!")
endif()
add_subdirectory(components_not_found)

View File

@ -1,18 +1,18 @@
# The module finds its dependencies
find_package(Qt5 5.1.0
find_package(Qt6 6.0.0
COMPONENTS Core
OPTIONAL_COMPONENTS DoesNotExist
)
if (NOT Qt5_FOUND)
message(SEND_ERROR "Qt5 umbrella package not found!")
if (NOT Qt6_FOUND)
message(SEND_ERROR "Qt6 umbrella package not found!")
endif()
if (NOT Qt5Core_FOUND)
message(SEND_ERROR "Qt5Core package not found!")
if (NOT Qt6Core_FOUND)
message(SEND_ERROR "Qt6Core package not found!")
endif()
if (Qt5DoesNotExist_FOUND)
if (Qt6DoesNotExist_FOUND)
message(SEND_ERROR "Non-existent package found!")
endif()

View File

@ -1,17 +1,17 @@
# The module finds its dependencies
find_package(Qt5
find_package(Qt6
COMPONENTS Core DoesNotExist
)
if (Qt5_FOUND)
message(SEND_ERROR "Qt5 umbrella package found, though it should not be!")
if (Qt6_FOUND)
message(SEND_ERROR "Qt6 umbrella package found, though it should not be!")
endif()
if (NOT Qt5Core_FOUND)
message(SEND_ERROR "Qt5Core package not found!")
if (NOT Qt6Core_FOUND)
message(SEND_ERROR "Qt6Core package not found!")
endif()
if (Qt5DoesNotExist_FOUND)
if (Qt6DoesNotExist_FOUND)
message(SEND_ERROR "Non-existent package found!")
endif()

View File

@ -1,13 +1,13 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.14)
project(versionless_targets)
set(QT_NO_CREATE_VERSIONLESS_TARGETS ON)
find_package(Qt5Core REQUIRED)
find_package(Qt6Core REQUIRED)
if (NOT TARGET Qt5::Core)
message(SEND_ERROR "Qt5::Core target not defined!")
if (NOT TARGET Qt6::Core)
message(SEND_ERROR "Qt6::Core target not defined!")
endif()
if (TARGET Qt::Core)
@ -16,7 +16,7 @@ endif()
set(QT_NO_CREATE_VERSIONLESS_TARGETS OFF)
find_package(Qt5Core REQUIRED)
find_package(Qt6Core REQUIRED)
if (NOT TARGET Qt::Core)
message(SEND_ERROR "Qt::Core target not defined!")

View File

@ -1,19 +1,13 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_wrap_cpp_and_resources)
find_package(Qt5Core REQUIRED)
find_package(Qt6Core REQUIRED)
include_directories(${Qt5Core_INCLUDE_DIRS})
qt_wrap_cpp(moc_files myobject.h)
add_definitions(${Qt5Core_DEFINITIONS})
qt5_wrap_cpp(moc_files myobject.h)
qt5_add_resources(rcc_files "test_wrap_cpp_and_resources.qrc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
qt_add_resources(rcc_files "test_wrap_cpp_and_resources.qrc")
add_executable(myobject myobject.cpp ${moc_files} ${rcc_files})
target_link_libraries(myobject ${Qt5Core_LIBRARIES})
target_link_libraries(myobject PRIVATE Qt::Core)

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.14)
project(test_wrap_cpp_options)
@ -7,17 +7,11 @@ if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
endif()
find_package(Qt5Core REQUIRED HINTS ${Qt5Tests_PREFIX_PATH})
include_directories(${Qt5Core_INCLUDE_DIRS})
add_definitions(${Qt5Core_DEFINITIONS})
find_package(Qt6Core REQUIRED HINTS ${Qt6Tests_PREFIX_PATH})
# Test options. The -i option removes the include "myobject.h" from the moc file
# causing a compile failure. -> Options work
qt5_wrap_cpp(moc_files myobject.h OPTIONS -i)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
qt_wrap_cpp(moc_files myobject.h OPTIONS -i)
add_executable(myobject myobject.cpp ${moc_files})
target_link_libraries(myobject ${Qt5Core_LIBRARIES})
target_link_libraries(myobject PRIVATE Qt::Core)