[cmake] Don't build Native llvm-config when cross compiling if passed by user.
authorDon Hinton <hintonda@gmail.com>
Sun, 21 Jan 2018 00:29:00 +0000 (00:29 +0000)
committerDon Hinton <hintonda@gmail.com>
Sun, 21 Jan 2018 00:29:00 +0000 (00:29 +0000)
Summary:
Rename LLVM_CONFIG_EXE to LLVM_CONFIG_PATH, and avoid building it if
passed in by user.  This is the same way CLANG_TABLEGEN and
LLVM_TABLEGEN are handled, e.g., when -DLLVM_OPTIMIZED_TABLEGEN=ON is
passed.

Differential Revision: https://reviews.llvm.org/D41806

llvm-svn: 323053

llvm/cmake/modules/LLVMExternalProjectUtils.cmake
llvm/tools/llvm-config/CMakeLists.txt

index 65fbaa4..619550b 100644 (file)
@@ -141,7 +141,7 @@ function(llvm_ExternalProject_Add name source_dir)
                       -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
                       -DCMAKE_AR=${CMAKE_AR}
                       -DCMAKE_RANLIB=${CMAKE_RANLIB})
-    set(llvm_config_path "${LLVM_NATIVE_BUILD}/bin/llvm-config")
+    set(llvm_config_path ${LLVM_CONFIG_PATH})
   else()
     set(llvm_config_path "$<TARGET_FILE:llvm-config>")
   endif()
index 25f99ce..d7bebfc 100644 (file)
@@ -64,18 +64,17 @@ endif()
 # Add the dependency on the generation step.
 add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH})
 
-if(CMAKE_CROSSCOMPILING)
-  set(${project}_LLVM_CONFIG_EXE "${LLVM_NATIVE_BUILD}/bin/llvm-config")
-  set(${project}_LLVM_CONFIG_EXE ${${project}_LLVM_CONFIG_EXE} PARENT_SCOPE)
+if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH)
+  set(LLVM_CONFIG_PATH "${LLVM_NATIVE_BUILD}/bin/llvm-config" CACHE STRING "")
 
-  add_custom_command(OUTPUT "${${project}_LLVM_CONFIG_EXE}"
+  add_custom_command(OUTPUT "${LLVM_CONFIG_PATH}"
     COMMAND ${CMAKE_COMMAND} --build . --target llvm-config --config $<CONFIGURATION>
     DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt
     WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
     COMMENT "Building native llvm-config..."
     USES_TERMINAL)
-  add_custom_target(${project}NativeLLVMConfig DEPENDS ${${project}_LLVM_CONFIG_EXE})
-  add_dependencies(${project}NativeLLVMConfig CONFIGURE_LLVM_NATIVE)
+  add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})
+  add_dependencies(NativeLLVMConfig CONFIGURE_LLVM_NATIVE)
 
-  add_dependencies(llvm-config ${project}NativeLLVMConfig)
-endif(CMAKE_CROSSCOMPILING)
+  add_dependencies(llvm-config NativeLLVMConfig)
+endif()