50 lines · plain
1# We want to clang-format the generated files if possible, since OffloadAPI.h is2# the main public header for liboffload. Generate them in a temporary location,3# then clang-format and copy them to the proper location. If clang-format is4# missing just copy them.5# Ideally we'd just clang-format them in place and avoid the copy but cmake6# gets confused about the same path being a byproduct of two custom commands.7 8set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/OffloadAPI.td)9set(files_to_copy "")10file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)11 12macro(offload_tablegen file)13 tablegen(OFFLOAD generated/${file}.gen ${ARGN})14 list(APPEND files_to_copy ${file})15endmacro()16 17offload_tablegen(OffloadAPI.h -gen-api)18offload_tablegen(OffloadEntryPoints.inc -gen-entry-points)19offload_tablegen(OffloadFuncs.inc -gen-func-names)20offload_tablegen(OffloadImplFuncDecls.inc -gen-impl-func-decls)21offload_tablegen(OffloadPrint.hpp -gen-print-header)22 23add_public_tablegen_target(OffloadGenerate)24 25add_custom_target(OffloadAPI DEPENDS OffloadGenerate)26find_program(clang_format clang-format PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)27if (clang_format)28 foreach(file IN LISTS files_to_copy)29 add_custom_command(30 OUTPUT ${file}31 COMMAND ${clang_format} -i generated/${file}.gen32 COMMAND ${CMAKE_COMMAND} -E copy_if_different generated/${file}.gen ${CMAKE_CURRENT_BINARY_DIR}/${file}33 DEPENDS generated/${file}.gen34 )35 add_custom_target(OffloadAPI.${file} DEPENDS ${file})36 add_dependencies(OffloadAPI OffloadAPI.${file})37 endforeach()38else()39 message(WARNING "clang-format not found, the generated Offload API headers will not be formatted")40 foreach(file IN LISTS files_to_copy)41 add_custom_command(42 OUTPUT ${file}43 COMMAND ${CMAKE_COMMAND} -E copy_if_different generated/${file}.gen ${CMAKE_CURRENT_BINARY_DIR}/${file}44 DEPENDS generated/${file}.gen45 )46 add_custom_target(OffloadAPI.${file} DEPENDS ${file})47 add_dependencies(OffloadAPI OffloadAPI.${file})48 endforeach()49endif()50