2019-06-27 13:27:14 +00:00
|
|
|
#
|
2020-03-11 16:12:08 +00:00
|
|
|
# Collection of auto detection routines to improve the user experience when
|
2019-06-27 13:27:14 +00:00
|
|
|
# building Qt from source.
|
|
|
|
#
|
2019-11-01 10:48:23 +00:00
|
|
|
# Make sure to not run detection when building standalone tests, because the detection was already
|
|
|
|
# done when initially configuring qtbase.
|
2019-06-27 13:27:14 +00:00
|
|
|
|
|
|
|
function(qt_auto_detect_android)
|
2019-11-01 10:48:23 +00:00
|
|
|
if(DEFINED CMAKE_TOOLCHAIN_FILE AND NOT DEFINED QT_AUTODETECT_ANDROID
|
|
|
|
AND NOT QT_BUILD_STANDALONE_TESTS)
|
2019-06-27 13:27:14 +00:00
|
|
|
|
|
|
|
file(READ ${CMAKE_TOOLCHAIN_FILE} toolchain_file_content OFFSET 0 LIMIT 80)
|
|
|
|
string(FIND ${toolchain_file_content} "The Android Open Source Project" find_result REVERSE)
|
|
|
|
if (NOT ${find_result} EQUAL -1)
|
|
|
|
set(android_detected TRUE)
|
|
|
|
else()
|
|
|
|
set(android_detected FALSE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(android_detected)
|
|
|
|
message(STATUS "Android toolchain file detected, checking configuration defaults...")
|
|
|
|
if(NOT DEFINED ANDROID_NATIVE_API_LEVEL)
|
|
|
|
message(STATUS "ANDROID_NATIVE_API_LEVEL was not specified, using API level 21 as default")
|
|
|
|
set(ANDROID_NATIVE_API_LEVEL 21 CACHE STRING "")
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED ANDROID_STL)
|
|
|
|
set(ANDROID_STL "c++_shared" CACHE STRING "")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
set(QT_AUTODETECT_ANDROID ${android_detected} CACHE STRING "")
|
|
|
|
elseif (QT_AUTODETECT_ANDROID)
|
|
|
|
message(STATUS "Android toolchain file detected")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(qt_auto_detect_vpckg)
|
2019-11-01 10:48:23 +00:00
|
|
|
if(DEFINED ENV{VCPKG_ROOT} AND NOT QT_BUILD_STANDALONE_TESTS)
|
2019-06-27 13:27:14 +00:00
|
|
|
set(vcpkg_toolchain_file "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
|
|
|
|
get_filename_component(vcpkg_toolchain_file "${vcpkg_toolchain_file}" ABSOLUTE)
|
|
|
|
|
|
|
|
if(DEFINED CMAKE_TOOLCHAIN_FILE)
|
|
|
|
get_filename_component(supplied_toolchain_file "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE)
|
|
|
|
if(NOT supplied_toolchain_file STREQUAL vcpkg_toolchain_file)
|
|
|
|
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" CACHE STRING "")
|
|
|
|
endif()
|
|
|
|
unset(supplied_toolchain_file)
|
|
|
|
endif()
|
|
|
|
set(CMAKE_TOOLCHAIN_FILE "${vcpkg_toolchain_file}" CACHE STRING "" FORCE)
|
|
|
|
message(STATUS "Using vcpkg from $ENV{VCPKG_ROOT}")
|
|
|
|
if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
|
|
|
|
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
|
|
|
|
message(STATUS "Using vcpkg triplet ${VCPKG_TARGET_TRIPLET}")
|
|
|
|
endif()
|
|
|
|
unset(vcpkg_toolchain_file)
|
2019-11-01 10:48:23 +00:00
|
|
|
message(STATUS "CMAKE_TOOLCHAIN_FILE is: ${CMAKE_TOOLCHAIN_FILE}")
|
|
|
|
if(DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
|
|
|
|
message(STATUS "VCPKG_CHAINLOAD_TOOLCHAIN_FILE is: ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
|
|
|
|
endif()
|
2019-06-27 13:27:14 +00:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2019-04-08 15:23:57 +00:00
|
|
|
function(qt_auto_detect_ios)
|
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL iOS
|
|
|
|
OR CMAKE_SYSTEM_NAME STREQUAL watchOS
|
|
|
|
OR CMAKE_SYSTEM_NAME STREQUAL tvOS)
|
|
|
|
message(STATUS "Using internal CMake ${CMAKE_SYSTEM_NAME} toolchain file.")
|
2019-06-27 13:27:14 +00:00
|
|
|
|
2019-04-08 15:23:57 +00:00
|
|
|
# The QT_UIKIT_SDK check simulates the input.sdk condition for simulator_and_device in
|
|
|
|
# configure.json.
|
|
|
|
# If the variable is explicitly provided, assume simulator_and_device to be off.
|
|
|
|
if(QT_UIKIT_SDK)
|
|
|
|
set(simulator_and_device OFF)
|
|
|
|
elseif(QT_FORCE_SIMULATOR_AND_DEVICE)
|
|
|
|
# TODO: Once we get simulator_and_device support in upstream CMake, only then allow
|
|
|
|
# usage of simulator_and_device without forcing.
|
|
|
|
set(simulator_and_device ON)
|
|
|
|
else()
|
|
|
|
# If QT_UIKIT_SDK is not provided, default to simulator.
|
|
|
|
set(simulator_and_device OFF)
|
|
|
|
set(QT_UIKIT_SDK "iphonesimulator" CACHE "STRING" "Chosen uikit SDK.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
message(STATUS "simulator_and_device set to: \"${simulator_and_device}\".")
|
|
|
|
|
|
|
|
# Choose relevant architectures.
|
|
|
|
# Using a non xcode generator requires explicit setting of the
|
|
|
|
# architectures, otherwise compilation fails with unknown defines.
|
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL iOS)
|
|
|
|
if(simulator_and_device)
|
|
|
|
set(osx_architectures "arm64;x86_64")
|
|
|
|
elseif(QT_UIKIT_SDK STREQUAL "iphoneos")
|
|
|
|
set(osx_architectures "arm64")
|
|
|
|
elseif(QT_UIKIT_SDK STREQUAL "iphonesimulator")
|
|
|
|
set(osx_architectures "x86_64")
|
|
|
|
else()
|
|
|
|
if(NOT DEFINED QT_UIKIT_SDK)
|
|
|
|
message(FATAL_ERROR "Please proviude a value for -DQT_UIKIT_SDK."
|
|
|
|
" Possible values: iphoneos, iphonesimulator.")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"Unknown SDK argument given to QT_UIKIT_SDK: ${QT_UIKIT_SDK}.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL tvOS)
|
|
|
|
if(simulator_and_device)
|
|
|
|
set(osx_architectures "arm64;x86_64")
|
|
|
|
elseif(QT_UIKIT_SDK STREQUAL "appletvos")
|
|
|
|
set(osx_architectures "arm64")
|
|
|
|
elseif(QT_UIKIT_SDK STREQUAL "appletvsimulator")
|
|
|
|
set(osx_architectures "x86_64")
|
|
|
|
else()
|
|
|
|
if(NOT DEFINED QT_UIKIT_SDK)
|
|
|
|
message(FATAL_ERROR "Please proviude a value for -DQT_UIKIT_SDK."
|
|
|
|
" Possible values: appletvos, appletvsimulator.")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"Unknown SDK argument given to QT_UIKIT_SDK: ${QT_UIKIT_SDK}.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL watchOS)
|
|
|
|
if(simulator_and_device)
|
|
|
|
set(osx_architectures "armv7k;i386")
|
|
|
|
elseif(QT_UIKIT_SDK STREQUAL "watchos")
|
|
|
|
set(osx_architectures "armv7k")
|
|
|
|
elseif(QT_UIKIT_SDK STREQUAL "watchsimulator")
|
|
|
|
set(osx_architectures "i386")
|
|
|
|
else()
|
|
|
|
if(NOT DEFINED QT_UIKIT_SDK)
|
|
|
|
message(FATAL_ERROR "Please proviude a value for -DQT_UIKIT_SDK."
|
|
|
|
" Possible values: watchos, watchsimulator.")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"Unknown SDK argument given to QT_UIKIT_SDK: ${QT_UIKIT_SDK}.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# For non simulator_and_device builds, we need to explicitly set the SYSROOT aka the sdk
|
|
|
|
# value.
|
|
|
|
if(QT_UIKIT_SDK)
|
|
|
|
set(CMAKE_OSX_SYSROOT "${QT_UIKIT_SDK}" CACHE STRING "")
|
|
|
|
endif()
|
|
|
|
message(STATUS "CMAKE_OSX_SYSROOT set to: \"${CMAKE_OSX_SYSROOT}\".")
|
|
|
|
|
|
|
|
message(STATUS "CMAKE_OSX_ARCHITECTURES set to: \"${osx_architectures}\".")
|
|
|
|
set(CMAKE_OSX_ARCHITECTURES "${osx_architectures}" CACHE STRING "")
|
|
|
|
|
|
|
|
if(NOT DEFINED BUILD_SHARED_LIBS)
|
|
|
|
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build Qt statically or dynamically" FORCE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"Building Qt for ${CMAKE_SYSTEM_NAME} as shared libraries is not supported.")
|
|
|
|
endif()
|
CMake: Handle automatic rpath embedding correctly
Instead of using CMAKE_INSTALL_RPATH to embed an absolute path
to prefix/libdir into all targets, use the more sophisticated aproach
that qmake does.
For certain targets (modules, plugins, tools) use relative rpaths.
Otherwise embed absolute paths (examples, regular binaries).
Installed tests currently have no rpaths.
On certain platforms rpaths are not used (Windows, Android,
iOS / uikit).
Frameworks, app bundles and shallow bundles should also be handled
correctly.
Additional rpaths can be provided via QT_EXTRA_RPATHS variable
(similar to the -R option that configure takes).
Automatic embedding can be disabled either via QT_FEATURE_rpath=OFF
or QT_DISABLE_RPATH=ON.
Note that installed examples are not relocatable at the moment (due
to always having an absolute path rpath), so this is a missing feature
compared to qmake. This is due to missing information on where
examples will be installed, so a relative rpath can not be computed.
By default a Qt installation is relocatable, so there is no need to
pass -DQT_EXTRA_RPATHS=. like Coin used to do with qmake e.g. -R .
Relative rpaths will have the appropriate 'relative base' prefixed
to them (e.g $ORIGIN on linux and @loader_path on darwin platforms).
There is currently no support for other platforms that might have a
different 'relative base' than the ones mentioned above.
Any extra rpaths are saved to BuildInternalsExtra which are re-used
when building other repositories.
configurejson2cmake modified to include correct conditions for the
rpath feature.
It's very likely that we will need a new qt_add_internal_app()
function for gui apps that are to be installed to prefix/bin.
For example for Assistant from qttools. Currently such apps
use qt_add_executable().
The distinction is necessary to make sure that relative rpaths are
embedded into apps, but not executables (which tests are part of).
Amends e835a6853b9c0fb7af32798ed8965de3adf0e15b
Task-number: QTBUG-83497
Change-Id: I3510f63c0a59489741116cc8ec3ef6a0a7704f25
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-04-15 16:48:26 +00:00
|
|
|
|
|
|
|
# Disable qt rpaths for iOS, just like mkspecs/common/uikit.conf does, due to those
|
|
|
|
# bundles not being able to use paths outside the app bundle. Not sure this is strictly
|
|
|
|
# needed though.
|
|
|
|
set(QT_DISABLE_RPATH "OFF" CACHE BOOL "Disable automatic Qt rpath handling." FORCE)
|
2019-04-08 15:23:57 +00:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2019-12-06 14:12:17 +00:00
|
|
|
function(qt_auto_detect_cmake_config)
|
|
|
|
if(CMAKE_CONFIGURATION_TYPES)
|
|
|
|
# Allow users to specify this option.
|
|
|
|
if(NOT QT_MULTI_CONFIG_FIRST_CONFIG)
|
|
|
|
list(GET CMAKE_CONFIGURATION_TYPES 0 first_config_type)
|
|
|
|
set(QT_MULTI_CONFIG_FIRST_CONFIG "${first_config_type}")
|
|
|
|
set(QT_MULTI_CONFIG_FIRST_CONFIG "${first_config_type}" PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CMAKE_TRY_COMPILE_CONFIGURATION "${QT_MULTI_CONFIG_FIRST_CONFIG}" PARENT_SCOPE)
|
|
|
|
if(CMAKE_GENERATOR STREQUAL "Ninja Multi-Config")
|
2020-03-02 13:16:38 +00:00
|
|
|
set(CMAKE_CROSS_CONFIGS "all" CACHE STRING "")
|
|
|
|
set(CMAKE_DEFAULT_BUILD_TYPE "${QT_MULTI_CONFIG_FIRST_CONFIG}" CACHE STRING "")
|
2019-12-06 14:12:17 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2020-02-14 10:40:03 +00:00
|
|
|
function(qt_auto_detect_darwin)
|
|
|
|
if(APPLE)
|
2020-03-06 12:59:29 +00:00
|
|
|
# If no CMAKE_OSX_DEPLOYMENT_TARGET is provided, default to a value that Qt defines.
|
|
|
|
# This replicates the behavior in mkspecs/common/macx.conf where
|
2020-02-14 10:40:03 +00:00
|
|
|
# QMAKE_MACOSX_DEPLOYMENT_TARGET is set.
|
2020-03-06 12:59:29 +00:00
|
|
|
set(description
|
|
|
|
"Minimum OS X version to target for deployment (at runtime); newer APIs weak linked. Set to empty string for default value.")
|
|
|
|
if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
|
|
|
|
if(NOT CMAKE_SYSTEM_NAME)
|
|
|
|
# macOS
|
|
|
|
set(version "10.14")
|
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL iOS)
|
|
|
|
set(version "12.0")
|
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL watchOS)
|
|
|
|
set(version "5.0")
|
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL tvOS)
|
|
|
|
set(version "12.0")
|
|
|
|
endif()
|
|
|
|
if(version)
|
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "${version}" CACHE STRING "${description}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
if(CMAKE_OSX_DEPLOYMENT_TARGET)
|
|
|
|
message(STATUS
|
|
|
|
"CMAKE_OSX_DEPLOYMENT_TARGET set to: \"${CMAKE_OSX_DEPLOYMENT_TARGET}\".")
|
2020-02-14 10:40:03 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2020-03-24 10:19:21 +00:00
|
|
|
function(qt_auto_detect_pch)
|
|
|
|
set(default_value "ON")
|
|
|
|
|
2020-04-03 12:23:18 +00:00
|
|
|
if(CMAKE_OSX_ARCHITECTURES AND CMAKE_VERSION VERSION_LESS 3.18.0 AND NOT QT_FORCE_PCH)
|
2020-03-24 10:19:21 +00:00
|
|
|
list(LENGTH CMAKE_OSX_ARCHITECTURES arch_count)
|
2020-04-03 12:23:18 +00:00
|
|
|
# CMake versions lower than 3.18 don't support PCH when multiple architectures are set.
|
|
|
|
# This is the case for simulator_and_device builds.
|
2020-03-24 10:19:21 +00:00
|
|
|
if(arch_count GREATER 1)
|
|
|
|
set(default_value "OFF")
|
|
|
|
message(WARNING "PCH support disabled due to usage of multiple architectures.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
option(BUILD_WITH_PCH "Build Qt using precompiled headers?" "${default_value}")
|
|
|
|
endfunction()
|
|
|
|
|
2019-12-06 14:12:17 +00:00
|
|
|
qt_auto_detect_cmake_config()
|
2020-02-14 10:40:03 +00:00
|
|
|
qt_auto_detect_darwin()
|
2019-04-08 15:23:57 +00:00
|
|
|
qt_auto_detect_ios()
|
2019-06-27 13:27:14 +00:00
|
|
|
qt_auto_detect_android()
|
|
|
|
qt_auto_detect_vpckg()
|
2020-03-24 10:19:21 +00:00
|
|
|
qt_auto_detect_pch()
|