45 lines
1.7 KiB
CMake
45 lines
1.7 KiB
CMake
# cmake/toolchains/homebrew-llvm.toolchain.cmake
|
|
#
|
|
# CMake Toolchain File for using the Homebrew LLVM/Clang installation on macOS.
|
|
# This ensures that the main project and all dependencies (like gRPC) use the
|
|
# correct compiler and header search paths.
|
|
|
|
# 1. Set the target system (macOS)
|
|
set(CMAKE_SYSTEM_NAME Darwin)
|
|
|
|
# 2. Find the Homebrew LLVM installation path
|
|
# We use execute_process to make this portable across machine architectures.
|
|
execute_process(
|
|
COMMAND brew --prefix llvm@18
|
|
OUTPUT_VARIABLE HOMEBREW_LLVM_PREFIX
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
)
|
|
|
|
if(NOT EXISTS "${HOMEBREW_LLVM_PREFIX}")
|
|
message(FATAL_ERROR "Homebrew LLVM not found. Please run 'brew install llvm'. Path: ${HOMEBREW_LLVM_PREFIX}")
|
|
endif()
|
|
|
|
message(STATUS "Using Homebrew LLVM from: ${HOMEBREW_LLVM_PREFIX}")
|
|
|
|
# 3. Set the C and C++ compilers
|
|
set(CMAKE_C_COMPILER "${HOMEBREW_LLVM_PREFIX}/bin/clang")
|
|
set(CMAKE_CXX_COMPILER "${HOMEBREW_LLVM_PREFIX}/bin/clang++")
|
|
|
|
# 4. Set the system root (sysroot) to the macOS SDK
|
|
# This correctly points to the system-level headers and libraries.
|
|
execute_process(
|
|
COMMAND xcrun --show-sdk-path
|
|
OUTPUT_VARIABLE CMAKE_OSX_SYSROOT
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
)
|
|
set(CMAKE_SYSROOT "${CMAKE_OSX_SYSROOT}")
|
|
message(STATUS "Using macOS SDK at: ${CMAKE_SYSROOT}")
|
|
|
|
# 5. **[THE CRITICAL FIX]** Explicitly define the C++ standard library include directory.
|
|
# This forces CMake to add Homebrew's libc++ headers to the search path *before*
|
|
# any other system paths, resolving the header conflict for the main project
|
|
# and all dependencies.
|
|
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES "${HOMEBREW_LLVM_PREFIX}/include/c++/v1")
|
|
|
|
# 6. Set the default installation path for macOS frameworks
|
|
set(CMAKE_FIND_FRAMEWORK FIRST) |