Skip to content

Commit 6b37275

Browse files
committed
[libc] move darwin check to Architecture.cmake from CompileOptionsRules.cmake
1 parent 04a52ab commit 6b37275

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

libc/cmake/modules/LLVMLibCArchitectures.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,37 @@ else()
215215
"Unsupported libc target operating system ${LIBC_TARGET_OS}")
216216
endif()
217217

218+
# If the compiler target triple is not the same as the triple specified by
219+
# LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
220+
# if the compiler is clang. If the compiler is GCC we just error out as there
221+
# is no equivalent of an option like --target.
222+
if(explicit_target_triple AND
223+
(NOT (libc_compiler_triple STREQUAL explicit_target_triple)))
224+
set(LIBC_CROSSBUILD TRUE)
225+
if(CMAKE_COMPILER_IS_GNUCXX)
226+
message(FATAL_ERROR
227+
"GCC target triple (${libc_compiler_triple}) and the explicity "
228+
"specified target triple (${explicit_target_triple}) do not match.")
229+
else()
230+
list(APPEND
231+
LIBC_COMPILE_OPTIONS_DEFAULT "--target=${explicit_target_triple}")
232+
endif()
233+
endif()
234+
235+
if(LIBC_TARGET_OS_IS_DARWIN)
236+
execute_process(
237+
COMMAND xcrun --sdk macosx --show-sdk-path
238+
OUTPUT_VARIABLE MACOSX_SDK_PATH
239+
RESULT_VARIABLE MACOSX_SDK_PATH_RESULT
240+
OUTPUT_STRIP_TRAILING_WHITESPACE
241+
)
242+
if(MACOSX_SDK_PATH_RESULT EQUAL 0)
243+
list(APPEND LIBC_COMPILE_OPTIONS_DEFAULT "-I" "${MACOSX_SDK_PATH}/usr/include")
244+
else()
245+
message(WARNING "Could not find macOS SDK path. `xcrun --sdk macosx --show-sdk-path` failed.")
246+
endif()
247+
endif()
248+
218249
# Windows does not support full mode build.
219250
if (LIBC_TARGET_OS_IS_WINDOWS AND LLVM_LIBC_FULL_BUILD)
220251
message(FATAL_ERROR "Windows does not support full mode build.")

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,6 @@ function(_get_common_compile_options output_var flags)
174174
list(APPEND compile_options "-idirafter${LIBC_KERNEL_HEADERS}")
175175
endif()
176176
endif()
177-
if(LIBC_TARGET_OS_IS_DARWIN)
178-
execute_process(
179-
COMMAND xcrun --sdk macosx --show-sdk-path
180-
OUTPUT_VARIABLE MACOSX_SDK_PATH
181-
RESULT_VARIABLE MACOSX_SDK_PATH_RESULT
182-
OUTPUT_STRIP_TRAILING_WHITESPACE
183-
)
184-
if(MACOSX_SDK_PATH_RESULT EQUAL 0)
185-
list(APPEND compile_options "-I" "${MACOSX_SDK_PATH}/usr/include")
186-
else()
187-
message(WARNING "Could not find macOS SDK path. `xcrun --sdk macosx --show-sdk-path` failed.")
188-
endif()
189-
endif()
190177
endif()
191178

192179
if(LIBC_COMPILER_HAS_FIXED_POINT)

0 commit comments

Comments
 (0)