Skip to content

Commit 2c55096

Browse files
TrouffmanRytoEX
authored andcommitted
cmake: Adjust macOS SDK detection
Change in-line with OBS's Master branch : https://github.com/obsproject/obs-studio/blob/master/cmake/macos/compilerconfig.cmake Fix errors when macOS SDK is not detected when using cmake 4.0.0+
1 parent 013ffca commit 2c55096

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

cmake/macos/compilerconfig.cmake

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,48 @@ include(compiler_common)
1515
add_compile_options("$<$<NOT:$<COMPILE_LANGUAGE:Swift>>:-fopenmp-simd>")
1616

1717
# Ensure recent enough Xcode and platform SDK
18-
set(_obs_macos_minimum_sdk 15.0) # Keep in sync with Xcode
19-
set(_obs_macos_minimum_xcode 16.0) # Keep in sync with SDK
20-
message(DEBUG "macOS SDK Path: ${CMAKE_OSX_SYSROOT}")
21-
string(REGEX MATCH ".+/MacOSX.platform/Developer/SDKs/MacOSX([0-9]+\\.[0-9])+\\.sdk$" _ ${CMAKE_OSX_SYSROOT})
22-
set(_obs_macos_current_sdk ${CMAKE_MATCH_1})
23-
message(DEBUG "macOS SDK version: ${_obs_macos_current_sdk}")
24-
if(_obs_macos_current_sdk VERSION_LESS _obs_macos_minimum_sdk)
25-
message(
26-
FATAL_ERROR
27-
"Your macOS SDK version (${_obs_macos_current_sdk}) is too low. "
28-
"The macOS ${_obs_macos_minimum_sdk} SDK (Xcode ${_obs_macos_minimum_xcode}) is required to build OBS."
18+
function(check_sdk_requirements)
19+
set(obs_macos_minimum_sdk 15.0) # Keep in sync with Xcode
20+
set(obs_macos_minimum_xcode 16.0) # Keep in sync with SDK
21+
execute_process(
22+
COMMAND xcrun --sdk macosx --show-sdk-platform-version
23+
OUTPUT_VARIABLE obs_macos_current_sdk
24+
RESULT_VARIABLE result
25+
OUTPUT_STRIP_TRAILING_WHITESPACE
2926
)
30-
endif()
31-
unset(_obs_macos_current_sdk)
32-
unset(_obs_macos_minimum_sdk)
33-
unset(_obs_macos_minimum_xcode)
27+
if(NOT result EQUAL 0)
28+
message(
29+
FATAL_ERROR
30+
"Failed to fetch macOS SDK version. "
31+
"Ensure that the macOS SDK is installed and that xcode-select points at the Xcode developer directory."
32+
)
33+
endif()
34+
message(DEBUG "macOS SDK version: ${obs_macos_current_sdk}")
35+
if(obs_macos_current_sdk VERSION_LESS obs_macos_minimum_sdk)
36+
message(
37+
FATAL_ERROR
38+
"Your macOS SDK version (${obs_macos_current_sdk}) is too low. "
39+
"The macOS ${obs_macos_minimum_sdk} SDK (Xcode ${obs_macos_minimum_xcode}) is required to build OBS."
40+
)
41+
endif()
42+
execute_process(COMMAND xcrun --find xcodebuild OUTPUT_VARIABLE obs_macos_xcodebuild RESULT_VARIABLE result)
43+
if(NOT result EQUAL 0)
44+
message(
45+
FATAL_ERROR
46+
"Xcode was not found. "
47+
"Ensure you have installed Xcode and that xcode-select points at the Xcode developer directory."
48+
)
49+
endif()
50+
message(DEBUG "Path to xcodebuild binary: ${obs_macos_xcodebuild}")
51+
if(XCODE_VERSION VERSION_LESS obs_macos_minimum_xcode)
52+
message(
53+
FATAL_ERROR
54+
"Your Xcode version (${XCODE_VERSION}) is too low. Xcode ${obs_macos_minimum_xcode} is required to build OBS."
55+
)
56+
endif()
57+
endfunction()
58+
59+
check_sdk_requirements()
3460

3561
# Enable dSYM generator for release builds
3662
string(APPEND CMAKE_C_FLAGS_RELEASE " -g")

0 commit comments

Comments
 (0)