diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt --- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt @@ -3,7 +3,21 @@ Support ) -set(CLANG_TIDY_CONFUSABLE_CHARS_GEN "clang-tidy-confusable-chars-gen" CACHE +set(CLANG_TIDY_CONFUSABLE_CHARS_GEN_DEFAULT "clang-tidy-confusable-chars-gen") + +if (LLVM_NATIVE_TOOL_DIR) + if (CMAKE_HOST_WIN32) + set(HOST_EXECUTABLE_SUFFIX ".exe") + else() + set(HOST_EXECUTABLE_SUFFIX "") + endif() + if (EXISTS "${LLVM_NATIVE_TOOL_DIR}/clang-tidy-confusable-chars-gen${HOST_EXECUTABLE_SUFFIX}") + set(CLANG_TIDY_CONFUSABLE_CHARS_GEN_DEFAULT "${LLVM_NATIVE_TOOL_DIR}/clang-tidy-confusable-chars-gen${HOST_EXECUTABLE_SUFFIX}") + endif() +endif() + + +set(CLANG_TIDY_CONFUSABLE_CHARS_GEN "${CLANG_TIDY_CONFUSABLE_CHARS_GEN_DEFAULT}" CACHE STRING "Host clang-tidy-confusable-chars-gen executable. Saves building if cross-compiling.") if(NOT CLANG_TIDY_CONFUSABLE_CHARS_GEN STREQUAL "clang-tidy-confusable-chars-gen") diff --git a/clang-tools-extra/pseudo/include/CMakeLists.txt b/clang-tools-extra/pseudo/include/CMakeLists.txt --- a/clang-tools-extra/pseudo/include/CMakeLists.txt +++ b/clang-tools-extra/pseudo/include/CMakeLists.txt @@ -1,7 +1,20 @@ # The cxx.bnf grammar file set(cxx_bnf ${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxx/cxx.bnf) -set(CLANG_PSEUDO_GEN "clang-pseudo-gen" CACHE +set(CLANG_PSEUDO_GEN_DEFAULT "clang-pseudo-gen") + +if (LLVM_NATIVE_TOOL_DIR) + if (CMAKE_HOST_WIN32) + set(HOST_EXECUTABLE_SUFFIX ".exe") + else() + set(HOST_EXECUTABLE_SUFFIX "") + endif() + if (EXISTS "${LLVM_NATIVE_TOOL_DIR}/clang-pseudo-gen${HOST_EXECUTABLE_SUFFIX}") + set(CLANG_PSEUDO_GEN_DEFAULT "${LLVM_NATIVE_TOOL_DIR}/clang-pseudo-gen${HOST_EXECUTABLE_SUFFIX}") + endif() +endif() + +set(CLANG_PSEUDO_GEN "${CLANG_PSEUDO_GEN_DEFAULT}" CACHE STRING "Host clang-pseudo-gen executable. Saves building if cross-compiling.") if(NOT CLANG_PSEUDO_GEN STREQUAL "clang-pseudo-gen") diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -598,6 +598,7 @@ if( WIN32 AND NOT CYGWIN ) set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") endif() +set(LLVM_NATIVE_TOOL_DIR "" CACHE PATH "Path to a directory containing prebuilt matching native tools (such as llvm-tblgen)") set(LLVM_INTEGRATED_CRT_ALLOC "" CACHE PATH "Replace the Windows CRT allocator with any of {rpmalloc|mimalloc|snmalloc}. Only works with /MT enabled.") if(LLVM_INTEGRATED_CRT_ALLOC) diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake --- a/llvm/cmake/modules/TableGen.cmake +++ b/llvm/cmake/modules/TableGen.cmake @@ -152,7 +152,18 @@ add_llvm_executable(${target} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN}) set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS}) - set(${project}_TABLEGEN "${target}" CACHE + set(${project}_TABLEGEN_DEFAULT "${target}") + if (LLVM_NATIVE_TOOL_DIR) + if (CMAKE_HOST_WIN32) + set(HOST_EXECUTABLE_SUFFIX ".exe") + else() + set(HOST_EXECUTABLE_SUFFIX "") + endif() + if (EXISTS "${LLVM_NATIVE_TOOL_DIR}/${target}${HOST_EXECUTABLE_SUFFIX}") + set(${project}_TABLEGEN_DEFAULT "${LLVM_NATIVE_TOOL_DIR}/${target}${HOST_EXECUTABLE_SUFFIX}") + endif() + endif() + set(${project}_TABLEGEN "${${project}_TABLEGEN_DEFAULT}" CACHE STRING "Native TableGen executable. Saves building one when cross-compiling.") # Effective tblgen executable to be used: diff --git a/llvm/tools/llvm-config/CMakeLists.txt b/llvm/tools/llvm-config/CMakeLists.txt --- a/llvm/tools/llvm-config/CMakeLists.txt +++ b/llvm/tools/llvm-config/CMakeLists.txt @@ -82,10 +82,23 @@ # Add the dependency on the generation step. add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH}) -if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH) - build_native_tool(llvm-config LLVM_CONFIG_PATH) - set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "") +if(CMAKE_CROSSCOMPILING) + if (LLVM_NATIVE_TOOL_DIR AND NOT LLVM_CONFIG_PATH) + if (CMAKE_HOST_WIN32) + set(HOST_EXECUTABLE_SUFFIX ".exe") + else() + set(HOST_EXECUTABLE_SUFFIX "") + endif() + if (EXISTS "${LLVM_NATIVE_TOOL_DIR}/llvm-config${HOST_EXECUTABLE_SUFFIX}") + set(LLVM_CONFIG_PATH "${LLVM_NATIVE_TOOL_DIR}/llvm-config${HOST_EXECUTABLE_SUFFIX}") + endif() + endif() + + if (NOT LLVM_CONFIG_PATH) + build_native_tool(llvm-config LLVM_CONFIG_PATH) + set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "") - add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH}) - add_dependencies(llvm-config NativeLLVMConfig) + add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH}) + add_dependencies(llvm-config NativeLLVMConfig) + endif() endif()