@@ -92,17 +92,6 @@ if(NOT libc_compiler_target_info)
9292endif ()
9393string (STRIP ${libc_compiler_target_info} libc_compiler_target_info)
9494string (SUBSTRING ${libc_compiler_target_info} 8 -1 libc_compiler_triple)
95- get_arch_and_system_from_triple(${libc_compiler_triple}
96- compiler_arch compiler_sys)
97- if (NOT compiler_arch)
98- message (FATAL_ERROR
99- "libc build: Invalid or unknown libc compiler target triple: "
100- "${libc_compiler_triple} " )
101- endif ()
102-
103- set (LIBC_TARGET_ARCHITECTURE ${compiler_arch} )
104- set (LIBC_TARGET_OS ${compiler_sys} )
105- set (LIBC_CROSSBUILD FALSE )
10695
10796# One should not set LLVM_RUNTIMES_TARGET and LIBC_TARGET_TRIPLE
10897if (LLVM_RUNTIMES_TARGET AND LIBC_TARGET_TRIPLE)
@@ -126,12 +115,40 @@ endif()
126115# architecture.
127116if (explicit_target_triple)
128117 get_arch_and_system_from_triple(${explicit_target_triple} libc_arch libc_sys)
129- if (NOT libc_arch)
118+ if (NOT libc_arch OR NOT libc_sys )
130119 message (FATAL_ERROR
131120 "libc build: Invalid or unknown triple: ${explicit_target_triple} " )
132121 endif ()
133122 set (LIBC_TARGET_ARCHITECTURE ${libc_arch} )
134123 set (LIBC_TARGET_OS ${libc_sys} )
124+ # If the compiler target triple is not the same as the triple specified by
125+ # LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
126+ # if the compiler is clang. If the compiler is GCC we just error out as there
127+ # is no equivalent of an option like --target.
128+ if (NOT libc_compiler_triple STREQUAL explicit_target_triple)
129+ set (LIBC_CROSSBUILD TRUE )
130+ if (CMAKE_COMPILER_IS_GNUCXX)
131+ message (FATAL_ERROR
132+ "GCC target triple (${libc_compiler_triple} ) and the explicity "
133+ "specified target triple (${explicit_target_triple} ) do not match." )
134+ else ()
135+ list (APPEND
136+ LIBC_COMPILE_OPTIONS_DEFAULT "--target=${explicit_target_triple} " )
137+ endif ()
138+ else ()
139+ set (LIBC_CROSSBUILD FALSE )
140+ endif ()
141+ else ()
142+ get_arch_and_system_from_triple(${libc_compiler_triple}
143+ compiler_arch compiler_sys)
144+ if (NOT compiler_arch OR NOT compiler_sys)
145+ message (FATAL_ERROR
146+ "libc build: Unknown compiler default target triple: "
147+ "${libc_compiler_triple} " )
148+ endif ()
149+ set (LIBC_TARGET_ARCHITECTURE ${compiler_arch} )
150+ set (LIBC_TARGET_OS ${compiler_sys} )
151+ set (LIBC_CROSSBUILD FALSE )
135152endif ()
136153
137154if ((LIBC_TARGET_OS STREQUAL "unknown" ) OR (LIBC_TARGET_OS STREQUAL "none" ))
@@ -188,31 +205,11 @@ else()
188205 "Unsupported libc target operating system ${LIBC_TARGET_OS} " )
189206endif ()
190207
191-
192- # If the compiler target triple is not the same as the triple specified by
193- # LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
194- # if the compiler is clang. If the compiler is GCC we just error out as there
195- # is no equivalent of an option like --target.
196- if (explicit_target_triple AND
197- (NOT (libc_compiler_triple STREQUAL explicit_target_triple)))
198- set (LIBC_CROSSBUILD TRUE )
199- if (CMAKE_COMPILER_IS_GNUCXX)
200- message (FATAL_ERROR
201- "GCC target triple (${libc_compiler_triple} ) and the explicity "
202- "specified target triple (${explicit_target_triple} ) do not match." )
203- else ()
204- list (APPEND
205- LIBC_COMPILE_OPTIONS_DEFAULT "--target=${explicit_target_triple} " )
206- endif ()
207- endif ()
208-
209-
210208# Windows does not support full mode build.
211209if (LIBC_TARGET_OS_IS_WINDOWS AND LLVM_LIBC_FULL_BUILD)
212210 message (FATAL_ERROR "Windows does not support full mode build." )
213211endif ()
214212
215-
216213message (STATUS
217- "Building libc for ${LIBC_TARGET_ARCHITECTURE} on ${LIBC_TARGET_OS} with
218- LIBC_COMPILE_OPTIONS_DEFAULT: ${LIBC_COMPILE_OPTIONS_DEFAULT} " )
214+ "Building libc for ${LIBC_TARGET_ARCHITECTURE} on ${LIBC_TARGET_OS} with "
215+ " LIBC_COMPILE_OPTIONS_DEFAULT: ${LIBC_COMPILE_OPTIONS_DEFAULT} " )
0 commit comments