about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorMartin Nowack <m.nowack@imperial.ac.uk>2020-12-01 17:22:22 +0000
committerMartinNowack <2443641+MartinNowack@users.noreply.github.com>2020-12-02 15:11:39 +0000
commitd450b92e6faa361dae7f425e285b42b6792691d0 (patch)
treee3bdb5a665283a9d3ba682c72ad8fc949e5f6c2a
parent26b13da1c032ff3426012f43b17a8fa86598857b (diff)
downloadklee-d450b92e6faa361dae7f425e285b42b6792691d0.tar.gz
Detect system include headers on macOS
System header files on macOS are not part of `/usr/include` since
Catalina. Instead, multiple locations are possible and depend on the
selected SDK.

Use `xcrun` to automatically detect the correct path on macOS.
-rw-r--r--test/CMakeLists.txt10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index f850d745..a5418a51 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -18,6 +18,16 @@ set(NATIVE_CC "${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -I ${CMAKE_SOURCE_DIR}/inclu
 set(NATIVE_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} -I ${CMAKE_SOURCE_DIR}/include")
 set(TARGET_TRIPLE "${TARGET_TRIPLE}")
 
+# Extend native compiler invocation on macOS to point to the currently selected systems directory
+if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+  execute_process(
+          COMMAND xcrun --sdk macosx --show-sdk-path
+          OUTPUT_VARIABLE MAC_OS_SDK_PATH
+          OUTPUT_STRIP_TRAILING_WHITESPACE)
+  set(NATIVE_CC "${NATIVE_CC} -isysroot ${MAC_OS_SDK_PATH}")
+  set(NATIVE_CXX "${NATIVE_CXX} -isysroot ${MAC_OS_SDK_PATH}")
+endif()
+
 # FIXME: Do this to avoid changing the template file that
 # is shared by both build systems.
 if (ENABLE_POSIX_RUNTIME)