|
4 | 4 |
|
5 | 5 | function(detect_osx_archs) |
6 | 6 | find_library(LIB_SYSTEM_PATH NAMES libSystem.B.tbd libSystem.B.dylib) |
7 | | - IF(NOT LIB_SYSTEM_PATH OR NOT EXISTS "${LIB_SYSTEM_PATH}") |
8 | | - MESSAGE(FATAL_ERROR "No libSystem.B.* found while trying to detect the architecture") |
| 7 | + if(NOT LIB_SYSTEM_PATH OR NOT EXISTS "${LIB_SYSTEM_PATH}") |
| 8 | + message(FATAL_ERROR "No libSystem.B.* found while trying to detect the architecture") |
9 | 9 | endif() |
10 | | - MESSAGE(STATUS "Checking ${LIB_SYSTEM_PATH} for possible architectures") |
11 | | - |
| 10 | + message(STATUS "Checking ${LIB_SYSTEM_PATH} for possible architectures") |
| 11 | + |
12 | 12 | get_filename_component(LIBSYSTEM_EXT "${LIB_SYSTEM_PATH}" EXT) |
13 | 13 | if(LIBSYSTEM_EXT STREQUAL ".B.dylib") |
14 | 14 | # find lipo |
15 | 15 | set(LIPO_NAMES apple-lipo lipo) |
16 | | - if(${CMAKE_CXX_COMPILER} MATCHES "^(.*)-[^-]+$" OR ${CMAKE_C_COMPILER} MATCHES "^(.*)-[^-]+$") |
| 16 | + if(CMAKE_CXX_COMPILER MATCHES "^(.*)-[^-]+$" OR CMAKE_C_COMPILER MATCHES "^(.*)-[^-]+$") |
17 | 17 | # Prefer lipo that has the same prefix as the compiler |
18 | 18 | list(INSERT LIPO_NAMES 0 "${CMAKE_MATCH_1}-lipo") |
19 | 19 | endif() |
20 | | - FIND_PROGRAM(LIPO NAMES ${LIPO_NAMES}) |
21 | | - set(_cmd "${LIPO}") |
22 | | - set(_args -info) |
23 | | - ELSE() |
24 | | - # Newer OSX have only a text file *.tbd instead of the dylib file |
25 | | - set(_cmd grep) |
26 | | - set(_args archs) |
27 | | - ENDIF() |
28 | | - |
29 | | - # read supported platforms |
30 | | - EXECUTE_PROCESS( |
31 | | - COMMAND "${_cmd}" ${_args} "${LIB_SYSTEM_PATH}" |
32 | | - RESULT_VARIABLE _RESULT |
33 | | - ERROR_VARIABLE _ERROR |
34 | | - OUTPUT_VARIABLE _OUTPUT |
| 20 | + find_program(LIPO NAMES ${LIPO_NAMES}) |
| 21 | + set(cmd "${LIPO}") |
| 22 | + set(args -info) |
| 23 | + else() |
| 24 | + # Newer OSX have only a text file *.tbd instead of the dylib file |
| 25 | + set(cmd grep) |
| 26 | + set(args archs) |
| 27 | + endif() |
| 28 | + |
| 29 | + # read supported platforms |
| 30 | + execute_process( |
| 31 | + COMMAND "${cmd}" ${args} "${LIB_SYSTEM_PATH}" |
| 32 | + RESULT_VARIABLE cmdResult |
| 33 | + ERROR_VARIABLE cmdStdErr |
| 34 | + OUTPUT_VARIABLE cmdStdOut |
35 | 35 | ) |
36 | | - if(NOT _RESULT EQUAL 0) |
37 | | - message(FATAL_ERROR "Command '${_cmd}' failed with status ${_RESULT} and output: ${_ERROR}") |
| 36 | + if(NOT cmdResult EQUAL 0 AND cmd STREQUAL "grep") |
| 37 | + # Try again for newer XCode (seen on version 12) |
| 38 | + execute_process( |
| 39 | + COMMAND grep target "${LIB_SYSTEM_PATH}" |
| 40 | + RESULT_VARIABLE cmdResult |
| 41 | + ERROR_VARIABLE cmdStdErr |
| 42 | + OUTPUT_VARIABLE cmdStdOut |
| 43 | + ) |
| 44 | + endif() |
| 45 | + if(NOT cmdResult EQUAL 0) |
| 46 | + if(LIBSYSTEM_EXT STREQUAL ".B.tbd") |
| 47 | + file(READ "${LIB_SYSTEM_PATH}" tbdContents) |
| 48 | + set(tbdContents " TBD: ${tbdContents}") |
| 49 | + else() |
| 50 | + set(tbdContents "") |
| 51 | + endif() |
| 52 | + message(WARNING "Command '${cmd}' failed with status ${cmdResult} and output: ${cmdStdOut} ${cmdStdErr}" |
| 53 | + "Assuming at least x86_64 is supported.${tbdContents}") |
| 54 | + set(cmdStdOut x86_64) |
38 | 55 | endif() |
39 | 56 |
|
40 | 57 | set(OSX_POSSIBLE_ARCHS x86_64 i386 i686 ppc) |
41 | | - set(OSX_DETECTED_ARCHS) |
| 58 | + set(OSX_DETECTED_ARCHS) |
42 | 59 | foreach(arch IN LISTS OSX_POSSIBLE_ARCHS) |
43 | | - IF(${_OUTPUT} MATCHES ${arch}) |
| 60 | + if(cmdStdOut MATCHES "${arch}") |
44 | 61 | list(APPEND OSX_DETECTED_ARCHS ${arch}) |
45 | | - ENDIF() |
| 62 | + endif() |
46 | 63 | endforeach() |
47 | | - |
48 | | - IF(NOT OSX_DETECTED_ARCHS) |
49 | | - MESSAGE(FATAL_ERROR "woooops: this should not happen! your system has no known architecture!") |
50 | | - ENDIF() |
51 | 64 |
|
52 | | - MESSAGE(STATUS "Possible architectures: ${OSX_DETECTED_ARCHS}") |
| 65 | + if(NOT OSX_DETECTED_ARCHS) |
| 66 | + message(FATAL_ERROR "woooops: this should not happen! your system has no known architecture!") |
| 67 | + endif() |
| 68 | + |
| 69 | + message(STATUS "Possible architectures: ${OSX_DETECTED_ARCHS}") |
53 | 70 | set(OSX_POSSIBLE_ARCHS ${OSX_POSSIBLE_ARCHS} PARENT_SCOPE) |
54 | 71 | set(OSX_DETECTED_ARCHS ${OSX_DETECTED_ARCHS} PARENT_SCOPE) |
55 | 72 | endfunction() |
0 commit comments