@@ -94,17 +94,6 @@ if(NOT libc_compiler_target_info)
9494endif ()
9595string (STRIP ${libc_compiler_target_info} libc_compiler_target_info)
9696string (SUBSTRING ${libc_compiler_target_info} 8 -1 libc_compiler_triple)
97- get_arch_and_system_from_triple(${libc_compiler_triple}
98- compiler_arch compiler_sys)
99- if (NOT compiler_arch)
100- message (FATAL_ERROR
101- "libc build: Invalid or unknown libc compiler target triple: "
102- "${libc_compiler_triple} " )
103- endif ()
104-
105- set (LIBC_TARGET_ARCHITECTURE ${compiler_arch} )
106- set (LIBC_TARGET_OS ${compiler_sys} )
107- set (LIBC_CROSSBUILD FALSE )
10897
10998# One should not set LLVM_RUNTIMES_TARGET and LIBC_TARGET_TRIPLE
11099if (LLVM_RUNTIMES_TARGET AND LIBC_TARGET_TRIPLE)
@@ -128,12 +117,40 @@ endif()
128117# architecture.
129118if (explicit_target_triple)
130119 get_arch_and_system_from_triple(${explicit_target_triple} libc_arch libc_sys)
131- if (NOT libc_arch)
120+ if (NOT libc_arch OR NOT libc_sys )
132121 message (FATAL_ERROR
133122 "libc build: Invalid or unknown triple: ${explicit_target_triple} " )
134123 endif ()
135124 set (LIBC_TARGET_ARCHITECTURE ${libc_arch} )
136125 set (LIBC_TARGET_OS ${libc_sys} )
126+ # If the compiler target triple is not the same as the triple specified by
127+ # LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
128+ # if the compiler is clang. If the compiler is GCC we just error out as there
129+ # is no equivalent of an option like --target.
130+ if (NOT libc_compiler_triple STREQUAL explicit_target_triple)
131+ set (LIBC_CROSSBUILD TRUE )
132+ if (CMAKE_COMPILER_IS_GNUCXX)
133+ message (FATAL_ERROR
134+ "GCC target triple (${libc_compiler_triple} ) and the explicity "
135+ "specified target triple (${explicit_target_triple} ) do not match." )
136+ else ()
137+ list (APPEND
138+ LIBC_COMPILE_OPTIONS_DEFAULT "--target=${explicit_target_triple} " )
139+ endif ()
140+ else ()
141+ set (LIBC_CROSSBUILD FALSE )
142+ endif ()
143+ else ()
144+ get_arch_and_system_from_triple(${libc_compiler_triple}
145+ compiler_arch compiler_sys)
146+ if (NOT compiler_arch OR NOT compiler_sys)
147+ message (FATAL_ERROR
148+ "libc build: Unknown compiler default target triple: "
149+ "${libc_compiler_triple} " )
150+ endif ()
151+ set (LIBC_TARGET_ARCHITECTURE ${compiler_arch} )
152+ set (LIBC_TARGET_OS ${compiler_sys} )
153+ set (LIBC_CROSSBUILD FALSE )
137154endif ()
138155
139156if ((LIBC_TARGET_OS STREQUAL "unknown" ) OR (LIBC_TARGET_OS STREQUAL "none" ))
@@ -198,31 +215,11 @@ else()
198215 "Unsupported libc target operating system ${LIBC_TARGET_OS} " )
199216endif ()
200217
201-
202- # If the compiler target triple is not the same as the triple specified by
203- # LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
204- # if the compiler is clang. If the compiler is GCC we just error out as there
205- # is no equivalent of an option like --target.
206- if (explicit_target_triple AND
207- (NOT (libc_compiler_triple STREQUAL explicit_target_triple)))
208- set (LIBC_CROSSBUILD TRUE )
209- if (CMAKE_COMPILER_IS_GNUCXX)
210- message (FATAL_ERROR
211- "GCC target triple (${libc_compiler_triple} ) and the explicity "
212- "specified target triple (${explicit_target_triple} ) do not match." )
213- else ()
214- list (APPEND
215- LIBC_COMPILE_OPTIONS_DEFAULT "--target=${explicit_target_triple} " )
216- endif ()
217- endif ()
218-
219-
220218# Windows does not support full mode build.
221219if (LIBC_TARGET_OS_IS_WINDOWS AND LLVM_LIBC_FULL_BUILD)
222220 message (FATAL_ERROR "Windows does not support full mode build." )
223221endif ()
224222
225-
226223message (STATUS
227- "Building libc for ${LIBC_TARGET_ARCHITECTURE} on ${LIBC_TARGET_OS} with
228- LIBC_COMPILE_OPTIONS_DEFAULT: ${LIBC_COMPILE_OPTIONS_DEFAULT} " )
224+ "Building libc for ${LIBC_TARGET_ARCHITECTURE} on ${LIBC_TARGET_OS} with "
225+ " LIBC_COMPILE_OPTIONS_DEFAULT: ${LIBC_COMPILE_OPTIONS_DEFAULT} " )
0 commit comments