summaryrefslogtreecommitdiffstats
path: root/cmake/QtAutoDetect.cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-04-08 17:23:57 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-12-03 13:35:59 +0000
commit55a15a1c1b93d36d705fc69e44b5c806b807dd55 (patch)
tree5b98c29c723bda2f298a394ee46e63f3c23ec74f /cmake/QtAutoDetect.cmake
parentc800a6240353eb54bd7a2ad06c455ac9374c2476 (diff)
Add initial support for cross-building to iOS
Tested locally with the following configurations: - iOS device builds (arm64) - iOS simulator builds (x86_64) - iOS simulator_and_device builds (fat arm64 and x86_64 archives) All iOS builds currently require a custom vcpkg fork which contains fixes for building the required 3rd party libraries. qtsvg, qtdeclarative, qtgraphicaleffects and qtquickcontrols2 have also been tested to build successfully. simulator_and_device builds are also supported, but require an umerged patch in upstream CMake as well as further patches to vcpkg. Task-number: QTBUG-75576 Change-Id: Icd29913fbbd52a60e07ea5253fd9c7af7f8ce44c Reviewed-by: Cristian Adam <cristian.adam@qt.io> Reviewed-by: Qt CMake Build Bot Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Diffstat (limited to 'cmake/QtAutoDetect.cmake')
-rw-r--r--cmake/QtAutoDetect.cmake97
1 files changed, 97 insertions, 0 deletions
diff --git a/cmake/QtAutoDetect.cmake b/cmake/QtAutoDetect.cmake
index 7864d40501..1823d1e572 100644
--- a/cmake/QtAutoDetect.cmake
+++ b/cmake/QtAutoDetect.cmake
@@ -59,6 +59,103 @@ function(qt_auto_detect_vpckg)
endif()
endfunction()
+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.")
+ # 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()
+ endif()
+endfunction()
+
+qt_auto_detect_ios()
qt_auto_detect_android()
qt_auto_detect_vpckg()