llvm.org GIT mirror llvm / 012d9c2
[CMake] Support cross-compiling with multi-stage builds When using multi-stage builds, we would like support cross-compilation. Example is 2-stage build when the first stage is compiled for host while the second stage is compiled for the target. Normally, the second stage would be also used for compiling runtimes, but that's not possible when cross-compiling, so we use the first stage compiler instead. However, we still want to use the second stage paths. To do so, we set the -resource-dir of the first stage compiler to point to the resource directory of the second stage. We also need compiler tools that support the target architecture. These tools are not guaranteed to be present on the host, but in case of multi-stage build, we can build these tools in the first stage. Differential Revision: https://reviews.llvm.org/D54461 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347025 91177308-0d34-0410-b5e6-96231b3b80d8 Petr Hosek 10 months ago
1 changed file(s) with 28 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
161161 -DCMAKE_OBJDUMP=${CMAKE_OBJDUMP}
162162 -DCMAKE_STRIP=${CMAKE_STRIP})
163163 set(llvm_config_path ${LLVM_CONFIG_PATH})
164
165 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
166 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
167 ${PACKAGE_VERSION})
168 set(resource_dir "${LLVM_LIBRARY_DIR}/clang/${CLANG_VERSION}")
169 set(flag_types ASM C CXX MODULE_LINKER SHARED_LINKER EXE_LINKER)
170 foreach(type ${flag_types})
171 set(${type}_flag -DCMAKE_${type}_FLAGS=-resource-dir=${resource_dir})
172 endforeach()
173 string(REPLACE ";" "|" flag_string "${flag_types}")
174 foreach(arg ${ARG_CMAKE_ARGS})
175 if(arg MATCHES "^-DCMAKE_(${flag_string})_FLAGS")
176 foreach(type ${flag_types})
177 if(arg MATCHES "^-DCMAKE_${type}_FLAGS")
178 string(REGEX REPLACE "^-DCMAKE_${type}_FLAGS=(.*)$" "\\1" flag_value "${arg}")
179 set(${type}_flag "${${type}_flag} ${flag_value}")
180 endif()
181 endforeach()
182 else()
183 list(APPEND cmake_args ${arg})
184 endif()
185 endforeach()
186 foreach(type ${flag_types})
187 list(APPEND cmake_args ${${type}_flag})
188 endforeach()
189 endif()
164190 else()
165191 set(llvm_config_path "$")
192 set(cmake_args ${ARG_CMAKE_ARGS})
166193 endif()
167194
168195 ExternalProject_Add(${name}
186213 -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
187214 -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
188215 -DCMAKE_EXPORT_COMPILE_COMMANDS=1
189 ${ARG_CMAKE_ARGS}
216 ${cmake_args}
190217 ${PASSTHROUGH_VARIABLES}
191218 INSTALL_COMMAND ""
192219 STEP_TARGETS configure build