OSDN Git Service

[cmake] Pass TARGETS_TO_BUILD through to host tools build
authorJustin Bogner <mail@justinbogner.com>
Mon, 11 Dec 2017 19:53:23 +0000 (19:53 +0000)
committerJustin Bogner <mail@justinbogner.com>
Mon, 11 Dec 2017 19:53:23 +0000 (19:53 +0000)
In r319620, the host build was changed to use Native for
TARGETS_TO_BUILD because passing semicolons through add_custom_command
is surprisingly difficult. However, Native really doesn't make any
sense here, and it only works because we don't technically do any
codegen in the host tools so pretty well anything will "work".

The problem here is that passing something other than the correct
value is very fragile - as evidence note how the llvm-config in the
host tools acts differently than the target one now, and misreports
the targets to build. Similarly, if there is any logic conditional on
the targets in tablegen (now or in the future), it will do the wrong
thing.

To fix this, we need to escape the semicolons in the targets string
and pass it through to the child cmake invocation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320413 91177308-0d34-0410-b5e6-96231b3b80d8

cmake/modules/CrossCompile.cmake

index 3f3a9a8..117eda7 100644 (file)
@@ -36,11 +36,16 @@ function(llvm_create_cross_target_internal target_name toolchain buildtype)
   add_custom_target(CREATE_LLVM_${target_name}
                     DEPENDS ${LLVM_${target_name}_BUILD})
 
+  # Escape semicolons in the targets list so that cmake doesn't expand
+  # them to spaces.
+  string(REPLACE ";" "$<SEMICOLON>" targets_to_build_arg
+         "${LLVM_TARGETS_TO_BUILD}")
+
   add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD}/CMakeCache.txt
     COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
         ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_SOURCE_DIR}
         -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE
-        -DLLVM_TARGETS_TO_BUILD=Native
+        -DLLVM_TARGETS_TO_BUILD="${targets_to_build_arg}"
         ${build_type_flags} ${linker_flag} ${external_clang_dir}
     WORKING_DIRECTORY ${LLVM_${target_name}_BUILD}
     DEPENDS CREATE_LLVM_${target_name}