[cmake] Some NFC changes in preparation for accomodating `Ninja Multi-Config`

* Use `MATCHES` so that `Ninja Multi-Config` generator also satisfies the Ninja check
* Pull out a couple of values into variables, inside `function(tablegen project ofn)`, NFC

Differential Revision: https://reviews.llvm.org/D118100
This commit is contained in:
Argyrios Kyrtzidis 2022-01-24 17:49:37 -08:00
parent f3ab0ccd00
commit 2868e2677b
3 changed files with 13 additions and 10 deletions

View File

@ -602,7 +602,7 @@ find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold
set(LLVM_BINUTILS_INCDIR "" CACHE PATH
"PATH to binutils/include containing plugin-api.h for gold plugin.")
if(CMAKE_GENERATOR STREQUAL "Ninja")
if(CMAKE_GENERATOR MATCHES "Ninja")
execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version
OUTPUT_VARIABLE NINJA_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
@ -610,7 +610,7 @@ if(CMAKE_GENERATOR STREQUAL "Ninja")
message(STATUS "Ninja version: ${NINJA_VERSION}")
endif()
if(CMAKE_GENERATOR STREQUAL "Ninja" AND
if(CMAKE_GENERATOR MATCHES "Ninja" AND
NOT "${NINJA_VERSION}" VERSION_LESS "1.9.0" AND
CMAKE_HOST_APPLE AND CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER "15.6.0")
set(LLVM_TOUCH_STATIC_LIBRARIES ON)

View File

@ -34,7 +34,7 @@ string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
"Define the maximum number of concurrent compilation jobs (Ninja only).")
if(LLVM_PARALLEL_COMPILE_JOBS)
if(NOT CMAKE_GENERATOR STREQUAL "Ninja")
if(NOT CMAKE_GENERATOR MATCHES "Ninja")
message(WARNING "Job pooling is only available with Ninja generators.")
else()
set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LLVM_PARALLEL_COMPILE_JOBS})
@ -44,7 +44,7 @@ endif()
set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING
"Define the maximum number of concurrent link jobs (Ninja only).")
if(CMAKE_GENERATOR STREQUAL "Ninja")
if(CMAKE_GENERATOR MATCHES "Ninja")
if(NOT LLVM_PARALLEL_LINK_JOBS AND uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
message(STATUS "ThinLTO provides its own parallel linking - limiting parallel link jobs to 2.")
set(LLVM_PARALLEL_LINK_JOBS "2")
@ -920,7 +920,7 @@ add_definitions( -D__STDC_LIMIT_MACROS )
# clang and gcc don't default-print colored diagnostics when invoked from Ninja.
if (UNIX AND
CMAKE_GENERATOR STREQUAL "Ninja" AND
CMAKE_GENERATOR MATCHES "Ninja" AND
(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9))))
@ -928,7 +928,7 @@ if (UNIX AND
endif()
# lld doesn't print colored diagnostics when invoked from Ninja
if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja")
if (UNIX AND CMAKE_GENERATOR MATCHES "Ninja")
include(LLVMCheckLinkerFlag)
llvm_check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS)
append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics"

View File

@ -10,7 +10,7 @@ function(tablegen project ofn)
endif()
# Use depfile instead of globbing arbitrary *.td(s) for Ninja.
if(CMAKE_GENERATOR STREQUAL "Ninja")
if(CMAKE_GENERATOR MATCHES "Ninja")
# Make output path relative to build.ninja, assuming located on
# ${CMAKE_BINARY_DIR}.
# CMake emits build targets as relative paths but Ninja doesn't identify
@ -93,8 +93,11 @@ function(tablegen project ofn)
get_directory_property(tblgen_includes INCLUDE_DIRECTORIES)
list(TRANSFORM tblgen_includes PREPEND -I)
set(tablegen_exe ${${project}_TABLEGEN_EXE})
set(tablegen_depends ${${project}_TABLEGEN_TARGET} ${tablegen_exe})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
COMMAND ${${project}_TABLEGEN_EXE} ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${tablegen_exe} ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR}
${tblgen_includes}
${LLVM_TABLEGEN_FLAGS}
${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
@ -103,7 +106,7 @@ function(tablegen project ofn)
# The file in LLVM_TARGET_DEFINITIONS may be not in the current
# directory and local_tds may not contain it, so we must
# explicitly list it here:
DEPENDS ${${project}_TABLEGEN_TARGET} ${${project}_TABLEGEN_EXE}
DEPENDS ${tablegen_depends}
${local_tds} ${global_tds}
${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
${LLVM_TARGET_DEPENDS}
@ -137,7 +140,7 @@ macro(add_tablegen target project)
set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen)
# CMake doesn't let compilation units depend on their dependent libraries on some generators.
if(NOT CMAKE_GENERATOR STREQUAL "Ninja" AND NOT XCODE)
if(NOT CMAKE_GENERATOR MATCHES "Ninja" AND NOT XCODE)
# FIXME: It leaks to user, callee of add_tablegen.
set(LLVM_ENABLE_OBJLIB ON)
endif()