diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -661,7 +661,12 @@ endif() option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF) -if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND (LLVM_ENABLE_ASSERTIONS OR CMAKE_CONFIGURATION_TYPES))) +if (LLVM_OPTIMIZED_TABLEGEN AND NOT CMAKE_CROSSCOMPILING AND CMAKE_GENERATOR STREQUAL "Ninja Multi-Config" AND "Release" IN_LIST CMAKE_CROSS_CONFIGS) + # "Ninja Multi-Config" generator allows using release tablegen binaries + # without needing a separate configured build directory for them. + set(LLVM_OPTIMIZED_TABLEGEN_VIA_NINJA_MULTI_CONFIG TRUE) +endif() +if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND NOT LLVM_OPTIMIZED_TABLEGEN_VIA_NINJA_MULTI_CONFIG AND (LLVM_ENABLE_ASSERTIONS OR CMAKE_CONFIGURATION_TYPES))) set(LLVM_USE_HOST_TOOLS ON) endif() 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 @@ -96,6 +96,13 @@ set(tablegen_exe ${${project}_TABLEGEN_EXE}) set(tablegen_depends ${${project}_TABLEGEN_TARGET} ${tablegen_exe}) + if (LLVM_OPTIMIZED_TABLEGEN_VIA_NINJA_MULTI_CONFIG) + set(tablegen_exe "${CMAKE_BINARY_DIR}/Release/bin/${${project}_TABLEGEN_EXE}") + # Only depend on the release executable; if we also depend on the target + # we'll build for both release and debug. + set(tablegen_depends ${tablegen_exe}) + endif() + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn} COMMAND ${tablegen_exe} ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR} ${tblgen_includes}