CMake: Generate wrapper shell scripts for all hosts when requested

This is useful for Qt for Android builds, where we want to build Qt on
a single host, but make the Qt installation usable on any host
(Windows, Linux, macOS).

There are only two flavors of shell scripts, unix ones that use sh and
Windows batch files.

If Qt is configured with
-DQT_GENERATE_WRAPPER_SCRIPTS_FOR_ALL_HOSTS=ON
then we generate both of them regardless of the current host platform.

Note that the target_qt.conf file still needs to be patched to specify
a correct HostSpec value so that qmake operates correctly.

Other target_qt.conf values might also need path adjustments depending
on use case (like HostPrefix and HostData).

Pick-to: 6.2 6.3
Task-number: QTBUG-101357
Change-Id: Ic86caaa8b318467528cc82dc7fbfecde998cdb71
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Alexandru Croitor 2022-03-02 17:38:38 +01:00
parent e440fec7fc
commit eec317a138
2 changed files with 70 additions and 27 deletions

View File

@ -130,25 +130,38 @@ HostSpec=${QT_QMAKE_HOST_MKSPEC}
qt_install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${qt_conf_path}" qt_install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${qt_conf_path}"
DESTINATION "${INSTALL_BINDIR}") DESTINATION "${INSTALL_BINDIR}")
if(QT_GENERATE_WRAPPER_SCRIPTS_FOR_ALL_HOSTS)
set(hosts "unix" "non-unix")
elseif(CMAKE_HOST_UNIX)
set(hosts "unix")
else()
set(hosts "non-unix")
endif()
set(wrapper_prefix) set(wrapper_prefix)
set(wrapper_extension)
if(QT_BUILD_TOOLS_WHEN_CROSSCOMPILING) if(QT_BUILD_TOOLS_WHEN_CROSSCOMPILING)
# Avoid collisions with the cross-compiled qmake/qtpaths binaries. # Avoid collisions with the cross-compiled qmake/qtpaths binaries.
set(wrapper_prefix "host-") set(wrapper_prefix "host-")
endif() endif()
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(wrapper_extension ".bat")
endif()
set(wrapper_in_file
"${CMAKE_CURRENT_SOURCE_DIR}/bin/qmake-and-qtpaths-wrapper${wrapper_extension}.in")
set(host_qt_bindir "${host_prefix}/${QT${PROJECT_VERSION_MAJOR}_HOST_INFO_BINDIR}") set(host_qt_bindir "${host_prefix}/${QT${PROJECT_VERSION_MAJOR}_HOST_INFO_BINDIR}")
foreach(tool_name qmake qtpaths) foreach(host_type ${hosts})
set(wrapper "preliminary/${wrapper_prefix}${tool_name}${wrapper_extension}") foreach(tool_name qmake qtpaths)
configure_file("${wrapper_in_file}" "${wrapper}" @ONLY) set(wrapper_extension)
qt_copy_or_install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/${wrapper}"
DESTINATION "${INSTALL_BINDIR}") if(host_type STREQUAL "non-unix")
set(wrapper_extension ".bat")
endif()
set(wrapper_in_file
"${CMAKE_CURRENT_SOURCE_DIR}/bin/qmake-and-qtpaths-wrapper${wrapper_extension}.in")
set(wrapper "preliminary/${wrapper_prefix}${tool_name}${wrapper_extension}")
configure_file("${wrapper_in_file}" "${wrapper}" @ONLY)
qt_copy_or_install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/${wrapper}"
DESTINATION "${INSTALL_BINDIR}")
endforeach()
endforeach() endforeach()
endfunction() endfunction()

View File

@ -6,12 +6,23 @@
# And other helper scripts. # And other helper scripts.
function(qt_internal_create_wrapper_scripts) function(qt_internal_create_wrapper_scripts)
# Provide a convenience cmake wrapper. # Provide a convenience cmake wrapper.
if(CMAKE_HOST_UNIX)
if(QT_GENERATE_WRAPPER_SCRIPTS_FOR_ALL_HOSTS)
set(generate_unix TRUE)
set(generate_non_unix TRUE)
elseif(CMAKE_HOST_UNIX)
set(generate_unix TRUE)
else()
set(generate_non_unix TRUE)
endif()
if(generate_unix)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake.in"
"${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake" @ONLY) "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake" @ONLY)
qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake" qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake"
DESTINATION "${INSTALL_BINDIR}") DESTINATION "${INSTALL_BINDIR}")
else() endif()
if(generate_non_unix)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake.bat.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake.bat.in"
"${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake.bat" @ONLY) "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake.bat" @ONLY)
qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake.bat" qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake.bat"
@ -27,15 +38,16 @@ function(qt_internal_create_wrapper_scripts)
# The private wrapper is more conveient for building Qt itself, because a developer doesn't need # The private wrapper is more conveient for building Qt itself, because a developer doesn't need
# to specify the same options for each qt module built. # to specify the same options for each qt module built.
set(__qt_cmake_extra "-G\"${CMAKE_GENERATOR}\"") set(__qt_cmake_extra "-G\"${CMAKE_GENERATOR}\"")
if(CMAKE_HOST_UNIX) if(generate_unix)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake.in"
"${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake-private" @ONLY) "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake-private" @ONLY)
qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake-private" qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake-private"
DESTINATION "${INSTALL_BINDIR}") DESTINATION "${INSTALL_BINDIR}")
else() endif()
if(generate_non_unix)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake.bat.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake.bat.in"
"${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake-private.bat" @ONLY) "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake-private.bat" @ONLY)
qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake-private.bat" qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake-private.bat"
DESTINATION "${INSTALL_BINDIR}") DESTINATION "${INSTALL_BINDIR}")
endif() endif()
unset(__qt_cmake_extra) unset(__qt_cmake_extra)
@ -50,12 +62,13 @@ function(qt_internal_create_wrapper_scripts)
endif() endif()
file(TO_NATIVE_PATH "${__relative_path_to_cmake_scripts_dir}" file(TO_NATIVE_PATH "${__relative_path_to_cmake_scripts_dir}"
__relative_path_to_cmake_scripts_dir) __relative_path_to_cmake_scripts_dir)
if(CMAKE_HOST_UNIX) if(generate_unix)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-configure-module.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-configure-module.in"
"${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-configure-module" @ONLY) "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-configure-module" @ONLY)
qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-configure-module" qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-configure-module"
DESTINATION "${INSTALL_BINDIR}") DESTINATION "${INSTALL_BINDIR}")
else() endif()
if(generate_non_unix)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-configure-module.bat.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-configure-module.bat.in"
"${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-configure-module.bat" @ONLY) "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-configure-module.bat" @ONLY)
qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-configure-module.bat" qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-configure-module.bat"
@ -92,13 +105,19 @@ function(qt_internal_create_wrapper_scripts)
file(RELATIVE_PATH __qt_cmake_standalone_test_relpath "${rel_base_path}" file(RELATIVE_PATH __qt_cmake_standalone_test_relpath "${rel_base_path}"
"${__qt_cmake_standalone_test_path}") "${__qt_cmake_standalone_test_path}")
if(CMAKE_HOST_UNIX) if(generate_unix)
set(__qt_cmake_standalone_test_os_prelude "#!/bin/sh") set(__qt_cmake_standalone_test_os_prelude "#!/bin/sh")
set(__qt_cmake_standalone_test_script_relpath "SCRIPT_DIR=`dirname $0`") set(__qt_cmake_standalone_test_script_relpath "SCRIPT_DIR=`dirname $0`")
string(PREPEND __qt_cmake_private_relpath "exec $SCRIPT_DIR/") string(PREPEND __qt_cmake_private_relpath "exec $SCRIPT_DIR/")
string(PREPEND __qt_cmake_standalone_test_relpath "$SCRIPT_DIR/") string(PREPEND __qt_cmake_standalone_test_relpath "$SCRIPT_DIR/")
set(__qt_cmake_standalone_passed_args "\"$@\" -DPWD=\"$PWD\"") set(__qt_cmake_standalone_passed_args "\"$@\" -DPWD=\"$PWD\"")
else()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake-standalone-test.in"
"${QT_BUILD_DIR}/${__qt_cmake_standalone_test_bin_path}")
qt_install(PROGRAMS "${QT_BUILD_DIR}/${__qt_cmake_standalone_test_bin_path}"
DESTINATION "${INSTALL_BINDIR}")
endif()
if(generate_non_unix)
set(__qt_cmake_standalone_test_os_prelude "@echo off") set(__qt_cmake_standalone_test_os_prelude "@echo off")
set(__qt_cmake_standalone_test_script_relpath "set SCRIPT_DIR=%~dp0") set(__qt_cmake_standalone_test_script_relpath "set SCRIPT_DIR=%~dp0")
string(APPEND __qt_cmake_standalone_test_bin_path ".bat") string(APPEND __qt_cmake_standalone_test_bin_path ".bat")
@ -106,11 +125,12 @@ function(qt_internal_create_wrapper_scripts)
string(PREPEND __qt_cmake_private_relpath "%SCRIPT_DIR%") string(PREPEND __qt_cmake_private_relpath "%SCRIPT_DIR%")
string(PREPEND __qt_cmake_standalone_test_relpath "%SCRIPT_DIR%") string(PREPEND __qt_cmake_standalone_test_relpath "%SCRIPT_DIR%")
set(__qt_cmake_standalone_passed_args "%* -DPWD=\"%CD%\"") set(__qt_cmake_standalone_passed_args "%* -DPWD=\"%CD%\"")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake-standalone-test.in"
"${QT_BUILD_DIR}/${__qt_cmake_standalone_test_bin_path}")
qt_install(PROGRAMS "${QT_BUILD_DIR}/${__qt_cmake_standalone_test_bin_path}"
DESTINATION "${INSTALL_BINDIR}")
endif() endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake-standalone-test.in"
"${QT_BUILD_DIR}/${__qt_cmake_standalone_test_bin_path}")
qt_install(PROGRAMS "${QT_BUILD_DIR}/${__qt_cmake_standalone_test_bin_path}"
DESTINATION "${INSTALL_BINDIR}")
# Create an installation script that the CI can use to handle installation for both # Create an installation script that the CI can use to handle installation for both
# single and multiple configurations. # single and multiple configurations.
@ -130,6 +150,15 @@ function(qt_internal_create_wrapper_scripts)
endfunction() endfunction()
function(qt_internal_create_qt_configure_tests_wrapper_script) function(qt_internal_create_qt_configure_tests_wrapper_script)
if(QT_GENERATE_WRAPPER_SCRIPTS_FOR_ALL_HOSTS)
set(generate_unix TRUE)
set(generate_non_unix TRUE)
elseif(CMAKE_HOST_UNIX)
set(generate_unix TRUE)
else()
set(generate_non_unix TRUE)
endif()
# Create a private wrapper script to configure and build all standalone tests. # Create a private wrapper script to configure and build all standalone tests.
# #
# The script uses qt-cmake instead of qt-cmake-private on purpose. That's to ensure we build # The script uses qt-cmake instead of qt-cmake-private on purpose. That's to ensure we build
@ -148,13 +177,14 @@ function(qt_internal_create_qt_configure_tests_wrapper_script)
file(TO_NATIVE_PATH "${relative_path_from_libexec_dir_to_bin_dir}" file(TO_NATIVE_PATH "${relative_path_from_libexec_dir_to_bin_dir}"
relative_path_from_libexec_dir_to_bin_dir) relative_path_from_libexec_dir_to_bin_dir)
if(CMAKE_HOST_UNIX) if(generate_unix)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libexec/${script_name}.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libexec/${script_name}.in"
"${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/${script_name}" @ONLY) "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/${script_name}" @ONLY)
qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/${script_name}" qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/${script_name}"
DESTINATION "${INSTALL_LIBEXECDIR}") DESTINATION "${INSTALL_LIBEXECDIR}")
else() endif()
if(generate_non_unix)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libexec/${script_name}.bat.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libexec/${script_name}.bat.in"
"${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/${script_name}.bat" @ONLY) "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/${script_name}.bat" @ONLY)