Skip to content

Commit 6899b49

Browse files
committed
[build] Unify retrieval of MacOS SDK path
Use `xcrun --show-sdk-path` only once to set the CMAKE_OSX_SYSROOT variable and then reuse it also for the modulemap fix on Darwin. Since the modulemap fix needed the `xcrun` command to work anyway, turn the warning previously issued if CMake couldn't find this command to an error.
1 parent 270e43f commit 6899b49

3 files changed

Lines changed: 8 additions & 16 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ if(CMAKE_HOST_APPLE AND (NOT CMAKE_OSX_SYSROOT OR CMAKE_OSX_SYSROOT STREQUAL "")
3434

3535
set(CMAKE_OSX_SYSROOT "${SDK_PATH}" CACHE PATH "SDK path" FORCE)
3636
else()
37-
message(WARNING "The CMAKE_OSX_SYSROOT variable is not set and the 'xcrun' executable is not available. "
38-
"This build of ROOT might not be able to find the correct MacOS SDK.")
37+
message(FATAL_ERROR "The CMAKE_OSX_SYSROOT variable is not set and the 'xcrun' executable is not available. "
38+
"This build of ROOT cannot find the correct MacOS SDK.")
3939
endif()
4040
endif()
4141

cmake/scripts/std_modulemap_darwin_fix.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
import subprocess
55
import sys
66

7-
8-
def get_sdk_path():
9-
result = subprocess.run(["xcrun", "--show-sdk-path"], capture_output=True, text=True)
10-
if result.returncode != 0:
11-
raise RuntimeError("Could not resolve SDK path")
12-
return os.path.realpath(result.stdout.strip())
13-
14-
157
def remove_ctype_module(content):
168
# Break cyclic module dependencies
179
# See: https://github.com/root-project/root/commit/8045591a17125b49c1007787c586868dea764479
@@ -20,11 +12,11 @@ def remove_ctype_module(content):
2012

2113

2214
def main():
23-
if len(sys.argv) < 2:
24-
raise ValueError("Usage: std_modulemap_darwin_fix.py <output_path>")
25-
output_path = sys.argv[1]
26-
sdk = get_sdk_path()
27-
cpp_modulemap = os.path.join(sdk, "usr/include/c++/v1/module.modulemap")
15+
if len(sys.argv) < 3:
16+
raise ValueError("Usage: std_modulemap_darwin_fix.py <sdk_path> <output_path>")
17+
sdk_path = sys.argv[1]
18+
output_path = sys.argv[2]
19+
cpp_modulemap = os.path.join(sdk_path, "usr/include/c++/v1/module.modulemap")
2820
if not os.path.exists(cpp_modulemap):
2921
# Try again if we are running a conda build. conda-forge ships the MacOS SDK stripped of libc++.
3022
# Instead, the standard libraries are shipped as a separate package which must be declared as a build

core/clingutils/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ if (runtime_cxxmodules)
133133

134134
add_custom_command(
135135
OUTPUT ${GENERATED_MODULEMAP}
136-
COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/cmake/scripts/std_modulemap_darwin_fix.py ${GENERATED_MODULEMAP}
136+
COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/cmake/scripts/std_modulemap_darwin_fix.py ${CMAKE_OSX_SYSROOT} ${GENERATED_MODULEMAP}
137137
DEPENDS ${PROJECT_SOURCE_DIR}/cmake/scripts/std_modulemap_darwin_fix.py
138138
COMMENT "Generating wrapped std modulemap for macOS SDK"
139139
)

0 commit comments

Comments
 (0)