Files
Markus Böck d6a4b2ad0b [CMake][NFC] Add llvm_tablegen and use it instead of tablegen(LLVM ...) (#235796)
Other subprojects invoke their TableGen through a project-specific
wrapper (clang_tablegen, mlir_tablegen, lldb_tablegen). Add
llvm_tablegen for llvm-tblgen and replace every tablegen(LLVM ...) call
with it.

The llvm-tblgen-specific logic in tablegen() moves into llvm_tablegen:
the DAGISel/GlobalISel coverage and -omit-comments flags, and the extra
outputs of -gen-register-info, which tablegen() now accepts generically
through a new EXTRA_OUTPUTS argument.

My motivation is general cleanliness but also as a use-case to add the
`EXTRA_OUTPUTS` cmake option to the `tablegen` command
2026-11-03 10:07:33 +01:00

50 lines
2.1 KiB
CMake

# We want to clang-format the generated files if possible, since OffloadAPI.h is
# the main public header for liboffload. Generate them in a temporary location,
# then clang-format and copy them to the proper location. If clang-format is
# missing just copy them.
# Ideally we'd just clang-format them in place and avoid the copy but cmake
# gets confused about the same path being a byproduct of two custom commands.
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/OffloadAPI.td)
set(files_to_copy "")
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
macro(offload_api_tablegen file)
offload_tablegen(generated/${file}.gen ${ARGN})
list(APPEND files_to_copy ${file})
endmacro()
offload_api_tablegen(OffloadAPI.h -gen-api)
offload_api_tablegen(OffloadEntryPoints.inc -gen-entry-points)
offload_api_tablegen(OffloadFuncs.inc -gen-func-names)
offload_api_tablegen(OffloadImplFuncDecls.inc -gen-impl-func-decls)
offload_api_tablegen(OffloadPrint.hpp -gen-print-header)
add_public_tablegen_target(OffloadGenerate)
add_custom_target(OffloadAPI DEPENDS OffloadGenerate)
find_program(clang_format clang-format PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
if (clang_format)
foreach(file IN LISTS files_to_copy)
add_custom_command(
OUTPUT ${file}
COMMAND ${clang_format} -i generated/${file}.gen
COMMAND ${CMAKE_COMMAND} -E copy_if_different generated/${file}.gen ${CMAKE_CURRENT_BINARY_DIR}/${file}
DEPENDS generated/${file}.gen
)
add_custom_target(OffloadAPI.${file} DEPENDS ${file})
add_dependencies(OffloadAPI OffloadAPI.${file})
endforeach()
else()
message(WARNING "clang-format not found, the generated Offload API headers will not be formatted")
foreach(file IN LISTS files_to_copy)
add_custom_command(
OUTPUT ${file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different generated/${file}.gen ${CMAKE_CURRENT_BINARY_DIR}/${file}
DEPENDS generated/${file}.gen
)
add_custom_target(OffloadAPI.${file} DEPENDS ${file})
add_dependencies(OffloadAPI OffloadAPI.${file})
endforeach()
endif()