[Lldb-commits] [lldb] [lldb][cmake] Set `CMAKE_OSX_SYSROOT` when building debugserver with CMake 4 (PR #138020)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Apr 30 21:08:53 PDT 2025
================
@@ -154,6 +154,20 @@ endif()
add_definitions(-DLLDB_USE_OS_LOG)
+if(NOT CMAKE_OSX_SYSROOT)
+ execute_process(COMMAND xcodebuild -version -sdk macosx Path
+ OUTPUT_VARIABLE SDKROOT
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if(NOT EXISTS ${SDKROOT})
+ message(FATAL_ERROR "Unable to obtain macOS SDK root, debugserver cannot be built.")
+ endif()
+
+ message(STATUS "Using macOS SDK root: ${SDKROOT}")
+ set(CMAKE_OSX_SYSROOT ${SDKROOT})
+endif()
----------------
JDevlieghere wrote:
I don't think we should try to compute `CMAKE_OSX_SYSROOT` ourselves. If we need an `-isysroot` for the `mig` invocation, it's fine to compute it, but we shouldn't reuse `CMAKE_OSX_SYSROOT` for that. The [documentation](https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_SYSROOT.html) before the `project()` call.
Here's what I think we should do instead:
```
if (CMAKE_OSX_SYSROOT)
set(MIG_SYSROOT ${CMAKE_OSX_SYSROOT})
else()
# Set the sysroot based on the output of `xcrun --show-sdk-path`
endif()
```
And then the mig invocation should use `${MIG_SYSROOT}` instead of `${CMAKE_OSX_SYSROOT}`.
`xcrun` is the usual way to get the SDK path and by not specifying the SDK, it will honor the usual ways of changing the SDK (which matters to us internally).
https://github.com/llvm/llvm-project/pull/138020
More information about the lldb-commits
mailing list