Skip to content

Commit 4677646

Browse files
committed
fix(cmake): Correct macOS KEXT build using absolute SDK paths
The KEXT (PcmMsrDriver) build failed on macOS because it could not find kernel headers like `<IOKit/IOLib.h>`. This was caused by CMake incorrectly resolving include paths to `/System/Library/...` instead of the correct path inside the macOS SDK. This commit fixes the issue by localizing the solution to the KEXT's `CMakeLists.txt`. It now dynamically detects the active macOS SDK path using `xcrun` and uses it to construct absolute include paths for the KEXT target only. This ensures the KEXT can find its required kernel headers without affecting other user-space targets that may depend on libraries from standard locations like Homebrew. Close: #928
1 parent 1aa4339 commit 4677646

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/MacMSRDriver/PcmMsr/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ add_executable(
1111

1212
set_target_properties(PcmMsrDriver PROPERTIES BUNDLE_EXTENSION kext MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/PcmMsr-Info.plist)
1313

14+
# For KEXT compilation on macOS, we must explicitly point to the Kernel frameworks within the SDK.
15+
if(APPLE)
16+
# Find the active macOS SDK path
17+
execute_process(
18+
COMMAND xcrun --sdk macosx --show-sdk-path
19+
OUTPUT_VARIABLE MACOSX_SDK_PATH
20+
OUTPUT_STRIP_TRAILING_WHITESPACE
21+
)
22+
message(STATUS "Using SDK for KEXT: ${MACOSX_SDK_PATH}")
23+
endif()
1424

1525
target_include_directories(PcmMsrDriver PRIVATE
16-
${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/Kernel.framework/PrivateHeaders
17-
${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/Kernel.framework/Headers
26+
"${MACOSX_SDK_PATH}/System/Library/Frameworks/Kernel.framework/PrivateHeaders"
27+
"${MACOSX_SDK_PATH}/System/Library/Frameworks/Kernel.framework/Headers"
1828
)
1929
target_compile_definitions(PcmMsrDriver PRIVATE
2030
-DKERNEL

0 commit comments

Comments
 (0)