summaryrefslogtreecommitdiffstats
path: root/Modules/Platform
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2019-07-26 12:45:56 (GMT)
committerCristian Adam <cristian.adam@gmail.com>2019-12-13 15:35:38 (GMT)
commita9b41195d292cfd0686b6c1f4d22f654728dca0b (patch)
tree4e9d37ef3f1738b54525538d083902b9d1821b71 /Modules/Platform
parent372c89ea38dd56457f93c688f1e8bf30a25bad57 (diff)
downloadCMake-a9b41195d292cfd0686b6c1f4d22f654728dca0b.zip
CMake-a9b41195d292cfd0686b6c1f4d22f654728dca0b.tar.gz
CMake-a9b41195d292cfd0686b6c1f4d22f654728dca0b.tar.bz2
Handle multi-arch sysroots on Apple platforms
Diffstat (limited to 'Modules/Platform')
-rw-r--r--Modules/Platform/Darwin-Initialize.cmake79
1 files changed, 79 insertions, 0 deletions
diff --git a/Modules/Platform/Darwin-Initialize.cmake b/Modules/Platform/Darwin-Initialize.cmake
index 1c51ec9..729217c 100644
--- a/Modules/Platform/Darwin-Initialize.cmake
+++ b/Modules/Platform/Darwin-Initialize.cmake
@@ -133,7 +133,86 @@ function(_apple_resolve_sdk_path sdk_name ret)
)
set(${ret} "${_stdout}" PARENT_SCOPE)
endfunction()
+# Handle multi-arch sysroots. Do this before CMAKE_OSX_SYSROOT is
+# transformed into a path, so that we know the sysroot name.
+function(_apple_resolve_multi_arch_sysroots)
+ if(CMAKE_APPLE_ARCH_SYSROOTS)
+ return() # Already cached
+ endif()
+
+ list(LENGTH CMAKE_OSX_ARCHITECTURES _num_archs)
+ if(NOT (_num_archs GREATER 1))
+ return() # Only apply to multi-arch
+ endif()
+
+ if(CMAKE_OSX_SYSROOT STREQUAL "macosx")
+ # macOS doesn't have a simulator sdk / sysroot, so there is no need to handle per-sdk arches.
+ return()
+ endif()
+
+ if(IS_DIRECTORY "${CMAKE_OSX_SYSROOT}")
+ if(NOT CMAKE_OSX_SYSROOT STREQUAL _CMAKE_OSX_SYSROOT_DEFAULT)
+ message(WARNING "Can not resolve multi-arch sysroots with CMAKE_OSX_SYSROOT set to path (${CMAKE_OSX_SYSROOT})")
+ endif()
+ return()
+ endif()
+
+ string(REPLACE "os" "simulator" _simulator_sdk ${CMAKE_OSX_SYSROOT})
+ set(_sdks "${CMAKE_OSX_SYSROOT};${_simulator_sdk}")
+ foreach(sdk ${_sdks})
+ _apple_resolve_sdk_path(${sdk} _sdk_path)
+ if(NOT IS_DIRECTORY "${_sdk_path}")
+ message(WARNING "Failed to resolve SDK path for '${sdk}'")
+ continue()
+ endif()
+
+ execute_process(
+ COMMAND plutil -extract SupportedTargets.${sdk}.Archs json ${_sdk_path}/SDKSettings.plist -o -
+ OUTPUT_VARIABLE _sdk_archs_json
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE _stderr
+ RESULT_VARIABLE _failed
+ )
+ if(_failed)
+ # Failure to extract supported architectures for an SDK means that the installed SDK is old
+ # and does not provide such information (SDKs that come with Xcode >= 10.x started providing
+ # the information). In such a case, return early, and handle multi-arch builds the old way
+ # (no per-sdk arches).
+ return()
+ endif()
+
+ # Poor man's JSON decoding
+ string(REGEX REPLACE "[]\\[\"]" "" _sdk_archs ${_sdk_archs_json})
+ string(REPLACE "," ";" _sdk_archs ${_sdk_archs})
+
+ set(_sdk_archs_${sdk} ${_sdk_archs})
+ set(_sdk_path_${sdk} ${_sdk_path})
+ endforeach()
+
+ foreach(arch ${CMAKE_OSX_ARCHITECTURES})
+ set(_arch_sysroot "")
+ foreach(sdk ${_sdks})
+ list(FIND _sdk_archs_${sdk} ${arch} arch_index)
+ if(NOT arch_index EQUAL -1)
+ set(_arch_sysroot ${_sdk_path_${sdk}})
+ break()
+ endif()
+ endforeach()
+ if(_arch_sysroot)
+ list(APPEND _arch_sysroots ${_arch_sysroot})
+ else()
+ message(WARNING "No SDK found for architecture '${arch}'")
+ list(APPEND _arch_sysroots "") # Placeholder
+ endif()
+ endforeach()
+
+ set(CMAKE_APPLE_ARCH_SYSROOTS "${_arch_sysroots}" CACHE INTERNAL
+ "Architecture dependent sysroots, one per CMAKE_OSX_ARCHITECTURES")
+endfunction()
+
+_apple_resolve_multi_arch_sysroots()
+# Transform CMAKE_OSX_SYSROOT to absolute path
set(_CMAKE_OSX_SYSROOT_PATH "")
if(CMAKE_OSX_SYSROOT)
if("x${CMAKE_OSX_SYSROOT}" MATCHES "/")