diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index 15d2b887e20..1244ef4baf4 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -70,8 +70,25 @@ if(QT_WILL_INSTALL) DESTINATION "${__build_internals_install_dir}") endif() +set(__build_internals_extra_files + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtBuildInternals/QtBuildInternalsHelpers.cmake" +) + +qt_copy_or_install( + FILES ${__build_internals_extra_files} + DESTINATION "${__build_internals_install_dir}") + +# In prefix builds we also need to copy the files into the build dir. +if(QT_WILL_INSTALL) + foreach(__build_internals_file ${__build_internals_extra_files}) + file(COPY "${__build_internals_file}" DESTINATION "${__build_internals_install_dir}") + endforeach() +endif() + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtBuildInternals/${__build_internals_standalone_test_template_dir}/CMakeLists.txt") + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtBuildInternals/${__build_internals_standalone_test_template_dir}/CMakeLists.txt" + ${__build_internals_extra_files} +) qt_internal_create_toolchain_file() diff --git a/cmake/QtBaseTopLevelHelpers.cmake b/cmake/QtBaseTopLevelHelpers.cmake index 4b56e9a6646..febffae02d4 100644 --- a/cmake/QtBaseTopLevelHelpers.cmake +++ b/cmake/QtBaseTopLevelHelpers.cmake @@ -34,6 +34,23 @@ endmacro() macro(qt_internal_top_level_setup_after_project) qt_internal_top_level_setup_testing() + qt_internal_top_level_setup_cmake_and_export_namespace() +endmacro() + +# Setting QT_CMAKE_EXPORT_NAMESPACE in the top-level scope is needed for any deferred call that is +# run on the top-level scope (CMAKE_BINARY_DIR). +macro(qt_internal_top_level_setup_cmake_and_export_namespace) + # Include the file that defines qt_internal_setup_cmake_and_export_namespace. + # We don't try to call find_package(QtBuildInternals) because that has a lot more side + # effects. + set(__qt6_build_internals_helpers_path + "${__qt6_qtbase_src_path}/cmake/QtBuildInternals/QtBuildInternalsHelpers.cmake") + if(NOT EXISTS "${__qt6_build_internals_helpers_path}") + message(FATAL_ERROR "Required file does not exist: '${__qt6_build_internals_helpers_path}'") + endif() + include("${__qt6_build_internals_helpers_path}") + + qt_internal_setup_cmake_and_export_namespace() endmacro() macro(qt_internal_top_level_setup_testing) diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index 129f1ebb771..3a1920beb72 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -11,18 +11,7 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/QtBuildInternalsExtra.cmake") include(${CMAKE_CURRENT_LIST_DIR}/QtBuildInternalsExtra.cmake) endif() -macro(qt_internal_setup_cmake_and_export_namespace) - # The variables might have already been set in QtBuildInternalsExtra.cmake if the file is - # included while building a new module and not QtBase. In that case, stop overriding the value. - if(NOT INSTALL_CMAKE_NAMESPACE) - set(INSTALL_CMAKE_NAMESPACE "Qt${PROJECT_VERSION_MAJOR}" - CACHE STRING "CMake namespace [Qt${PROJECT_VERSION_MAJOR}]") - endif() - if(NOT QT_CMAKE_EXPORT_NAMESPACE) - set(QT_CMAKE_EXPORT_NAMESPACE "Qt${PROJECT_VERSION_MAJOR}" - CACHE STRING "CMake namespace used when exporting targets [Qt${PROJECT_VERSION_MAJOR}]") - endif() -endmacro() +include(${CMAKE_CURRENT_LIST_DIR}/QtBuildInternalsHelpers.cmake) macro(qt_set_up_build_internals_paths) # Set up the paths for the cmake modules located in the prefix dir. Prepend, so the paths are diff --git a/cmake/QtBuildInternals/QtBuildInternalsHelpers.cmake b/cmake/QtBuildInternals/QtBuildInternalsHelpers.cmake new file mode 100644 index 00000000000..aa845fd5c36 --- /dev/null +++ b/cmake/QtBuildInternals/QtBuildInternalsHelpers.cmake @@ -0,0 +1,15 @@ +# Copyright (C) 2025 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +macro(qt_internal_setup_cmake_and_export_namespace) + # The variables might have already been set in QtBuildInternalsExtra.cmake if the file is + # included while building a new module and not QtBase. In that case, stop overriding the value. + if(NOT INSTALL_CMAKE_NAMESPACE) + set(INSTALL_CMAKE_NAMESPACE "Qt${PROJECT_VERSION_MAJOR}" + CACHE STRING "CMake namespace [Qt${PROJECT_VERSION_MAJOR}]") + endif() + if(NOT QT_CMAKE_EXPORT_NAMESPACE) + set(QT_CMAKE_EXPORT_NAMESPACE "Qt${PROJECT_VERSION_MAJOR}" + CACHE STRING "CMake namespace used when exporting targets [Qt${PROJECT_VERSION_MAJOR}]") + endif() +endmacro()