From de3a806def4b9a754825a2233c9d4952a9b2d0eb Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 1 Nov 2019 11:48:23 +0100 Subject: 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 --- CMakeLists.txt | 97 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 45 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 273a169aee..bb3cedc953 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) - -## Should this Qt be built with Werror? -option(WARNINGS_ARE_ERRORS "Build Qt with warnings as errors" ${FEATURE_developer_build}) +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 Qt be built using PCH? -option(BUILD_WITH_PCH "Build Qt using precompiled headers?" ON) + ## Should this Qt be built with Werror? + option(WARNINGS_ARE_ERRORS "Build Qt with warnings as errors" ${FEATURE_developer_build}) -## QtBase specific configure tests: -include(QtBaseConfigureTests) + ## Should Qt be built using PCH? + option(BUILD_WITH_PCH "Build Qt using precompiled headers?" ON) -## Build System tests: -include(QtBaseCMakeTesting) + ## QtBase specific configure tests: + include(QtBaseConfigureTests) -## Targets for global features, etc.: -include(QtBaseGlobalTargets) + ## Build System tests: + include(QtBaseCMakeTesting) -qt_set_language_standards() + ## Targets for global features, etc.: + include(QtBaseGlobalTargets) -## Decide whether tools will be built. -qt_check_if_tools_will_be_built() + ## Set language standards after QtBaseGlobalTargets, because that's when the relevant + ## feature variables are available. + qt_set_language_standards() -## Visit all the directories: -add_subdirectory(src) + ## Visit all the directories: + add_subdirectory(src) +endif() -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() -- cgit v1.2.3