Skip to content

Commit e9ae5bb

Browse files
committed
[CMake] Move setting of OSX_SYSROOT before project().
According to the documentation, any OSX_SYSROOT needs to be set before the first project call. https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_SYSROOT.html Since the setting came too late, homebrew compilers were missing the include list for homebrew compilers was generated wrongly.
1 parent 3583493 commit e9ae5bb

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ if(WIN32)
1212
cmake_policy(SET CMP0091 OLD)
1313
set(CMAKE_SKIP_TEST_ALL_DEPENDENCY TRUE)
1414
endif()
15+
if(APPLE AND (NOT CMAKE_OSX_SYSROOT OR CMAKE_OSX_SYSROOT STREQUAL ""))
16+
# The SYSROOT *must* be set before the project() call
17+
execute_process(COMMAND xcrun --sdk macosx --show-sdk-path
18+
OUTPUT_VARIABLE SDK_PATH
19+
ERROR_QUIET
20+
OUTPUT_STRIP_TRAILING_WHITESPACE)
21+
22+
if(NOT EXISTS "${SDK_PATH}")
23+
message(FATAL_ERROR "Could not detect macOS SDK path")
24+
endif()
25+
26+
set(CMAKE_OSX_SYSROOT "${SDK_PATH}" CACHE PATH "SDK path" FORCE)
27+
endif()
1528

1629
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT ALLOW_IN_SOURCE)
1730
message(FATAL_ERROR

cmake/modules/SetUpMacOS.cmake

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ if (CMAKE_SYSTEM_NAME MATCHES Darwin)
1313
set(libcxx ON CACHE BOOL "Build using libc++" FORCE)
1414
endif()
1515

16-
if(NOT CMAKE_OSX_SYSROOT OR CMAKE_OSX_SYSROOT STREQUAL "")
17-
execute_process(COMMAND xcrun --sdk macosx --show-sdk-path
18-
OUTPUT_VARIABLE SDK_PATH
19-
ERROR_QUIET
20-
OUTPUT_STRIP_TRAILING_WHITESPACE)
21-
22-
if(NOT EXISTS "${SDK_PATH}")
23-
message(FATAL_ERROR "Could not detect macOS SDK path")
24-
endif()
25-
26-
set(CMAKE_OSX_SYSROOT "${SDK_PATH}" CACHE PATH "SDK path" FORCE)
27-
endif()
28-
message(STATUS "Using SDK path: ${CMAKE_OSX_SYSROOT}")
29-
3016
#TODO: check haveconfig and rpath -> set rpath true
3117
#TODO: check Thread, define link command
3218
#TODO: more stuff check configure script

0 commit comments

Comments
 (0)