summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-04-17 12:07:14 +0000
committerKitware Robot <kwrobot@kitware.com>2020-04-17 08:07:29 -0400
commitee79216b828196e8e4ff0a92ee0c481faddc4709 (patch)
tree0eb9ead1721595e51fecb2b53d6cd654455b0302
parente4aed8b9cdba8913cef61f2b1ec04dc4d08b8b1d (diff)
parent170e598add5c7bbfab2c40f4e2db1ceaec32417e (diff)
downloadcmake-ee79216b828196e8e4ff0a92ee0c481faddc4709.tar.gz
Merge topic 'ios_multi_arch_fix' into release-3.17
170e598add iOS: Fix detection of supported SDK architectures Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Alexander Köplinger <alex.koeplinger@outlook.com> Merge-request: !4615
-rw-r--r--Modules/Platform/Darwin-Initialize.cmake87
1 files changed, 76 insertions, 11 deletions
diff --git a/Modules/Platform/Darwin-Initialize.cmake b/Modules/Platform/Darwin-Initialize.cmake
index 80e668e5a6..80e9a40195 100644
--- a/Modules/Platform/Darwin-Initialize.cmake
+++ b/Modules/Platform/Darwin-Initialize.cmake
@@ -133,6 +133,80 @@ function(_apple_resolve_sdk_path sdk_name ret)
)
set(${ret} "${_stdout}" PARENT_SCOPE)
endfunction()
+
+function(_apple_resolve_supported_archs_for_sdk_from_system_lib sdk_path ret ret_failed)
+ # Detect the supported SDK architectures by inspecting the main libSystem library.
+ set(common_lib_prefix "${sdk_path}/usr/lib/libSystem")
+ set(system_lib_dylib_path "${common_lib_prefix}.dylib")
+ set(system_lib_tbd_path "${common_lib_prefix}.tbd")
+
+ # Newer SDKs ship text based dylib stub files which contain the architectures supported by the
+ # library in text form.
+ if(EXISTS "${system_lib_tbd_path}")
+ file(STRINGS "${system_lib_tbd_path}" tbd_lines REGEX "^archs: +\\[.+\\]")
+ if(NOT tbd_lines)
+ set(${ret_failed} TRUE PARENT_SCOPE)
+ return()
+ endif()
+
+ # The tbd architectures line looks like the following:
+ # archs: [ armv7, armv7s, arm64, arm64e ]
+ list(GET tbd_lines 0 first_arch_line)
+ string(REGEX REPLACE
+ "archs: +\\[ (.+) \\]" "\\1" arches_comma_separated "${first_arch_line}")
+ string(STRIP "${arches_comma_separated}" arches_comma_separated)
+ string(REPLACE "," ";" arch_list "${arches_comma_separated}")
+ string(REPLACE " " "" arch_list "${arch_list}")
+ if(NOT arch_list)
+ set(${ret_failed} TRUE PARENT_SCOPE)
+ return()
+ endif()
+ set(${ret} "${arch_list}" PARENT_SCOPE)
+ elseif(EXISTS "${system_lib_dylib_path}")
+ # Old SDKs (Xcode < 7) ship dylib files, use lipo to inspect the supported architectures.
+ # Can't use -archs because the option is not available in older Xcode versions.
+ execute_process(
+ COMMAND lipo -info ${system_lib_dylib_path}
+ OUTPUT_VARIABLE lipo_output
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE _stderr
+ RESULT_VARIABLE _failed
+ )
+ if(_failed OR NOT lipo_output OR NOT lipo_output MATCHES "(Non-fat file:|Architectures in the fat file:)")
+ set(${ret_failed} TRUE PARENT_SCOPE)
+ return()
+ endif()
+
+ # The lipo output looks like the following:
+ # Non-fat file: <path> is architecture: i386
+ # Architectures in the fat file: <path> are: i386 x86_64
+ string(REGEX REPLACE
+ "^(.+)is architecture:(.+)" "\\2" arches_space_separated "${lipo_output}")
+ string(REGEX REPLACE
+ "^(.+)are:(.+)" "\\2" arches_space_separated "${arches_space_separated}")
+
+ # Need to clean up the arches, with Xcode 4.6.3 the output of lipo -info contains some
+ # additional info, e.g.
+ # Architectures in the fat file: <path> are: armv7 (cputype (12) cpusubtype (11))
+ string(REGEX REPLACE
+ "\\(.+\\)" "" arches_space_separated "${arches_space_separated}")
+
+ # The output is space separated.
+ string(STRIP "${arches_space_separated}" arches_space_separated)
+ string(REPLACE " " ";" arch_list "${arches_space_separated}")
+
+ if(NOT arch_list)
+ set(${ret_failed} TRUE PARENT_SCOPE)
+ return()
+ endif()
+ set(${ret} "${arch_list}" PARENT_SCOPE)
+ else()
+ # This shouldn't happen, but keep it for safety.
+ message(WARNING "No way to find architectures for given sdk_path '${sdk_path}'")
+ set(${ret_failed} TRUE PARENT_SCOPE)
+ endif()
+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)
@@ -166,13 +240,8 @@ function(_apple_resolve_multi_arch_sysroots)
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
- )
+ _apple_resolve_supported_archs_for_sdk_from_system_lib(${_sdk_path} _sdk_archs _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
@@ -181,10 +250,6 @@ function(_apple_resolve_multi_arch_sysroots)
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()