@@ -215,6 +215,37 @@ else()
215215 "Unsupported libc target operating system ${LIBC_TARGET_OS} " )
216216endif ()
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.
219250if (LIBC_TARGET_OS_IS_WINDOWS AND LLVM_LIBC_FULL_BUILD)
220251 message (FATAL_ERROR "Windows does not support full mode build." )
0 commit comments