@@ -21,6 +21,13 @@ function(tablegen project ofn)
2121 message (FATAL_ERROR "${project} _TABLEGEN_EXE not set" )
2222 endif ()
2323
24+ # Set the include directories
25+ get_directory_property (tblgen_includes INCLUDE_DIRECTORIES )
26+ list (PREPEND tblgen_includes ${ARG_EXTRA_INCLUDES} )
27+ list (PREPEND tblgen_includes ${CMAKE_CURRENT_SOURCE_DIR} )
28+ # Filter out any empty include items.
29+ list (REMOVE_ITEM tblgen_includes "" )
30+
2431 # Use depfile instead of globbing arbitrary *.td(s) for Ninja. We force
2532 # CMake versions older than v3.30 on Windows to use the fallback behavior
2633 # due to a depfile parsing bug on Windows paths in versions prior to 3.30.
@@ -42,22 +49,16 @@ function(tablegen project ofn)
4249 -d ${ofn} .d
4350 DEPFILE ${ofn} .d
4451 )
45- set (local_tds)
4652 set (global_tds)
4753 else ()
48- file (GLOB local_tds "*.td" )
49- file (GLOB_RECURSE global_tds "${LLVM_MAIN_INCLUDE_DIR} /llvm/*.td" )
54+ set (include_td_dirs "${tblgen_includes} " )
55+ list (TRANSFORM include_td_dirs APPEND "/*.td" )
56+ file (GLOB global_tds ${include_td_dirs} )
5057 set (additional_cmdline
5158 -o ${CMAKE_CURRENT_BINARY_DIR} /${ofn}
5259 )
5360 endif ()
5461
55- if (IS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS} )
56- set (LLVM_TARGET_DEFINITIONS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS} )
57- else ()
58- set (LLVM_TARGET_DEFINITIONS_ABSOLUTE
59- ${CMAKE_CURRENT_SOURCE_DIR} /${LLVM_TARGET_DEFINITIONS} )
60- endif ()
6162 if (LLVM_ENABLE_DAGISEL_COV AND "-gen-dag-isel" IN_LIST ARGN)
6263 list (APPEND LLVM_TABLEGEN_FLAGS "-instrument-coverage" )
6364 endif ()
@@ -92,44 +93,34 @@ function(tablegen project ofn)
9293 list (APPEND LLVM_TABLEGEN_FLAGS "-no-warn-on-unused-template-args" )
9394 endif ()
9495
95- # We need both _TABLEGEN_TARGET and _TABLEGEN_EXE in the DEPENDS list
96- # (both the target and the file) to have .inc files rebuilt on
97- # a tablegen change, as cmake does not propagate file-level dependencies
98- # of custom targets. See the following ticket for more information:
99- # https://cmake.org/Bug/view.php?id=15858
100- # The dependency on both, the target and the file, produces the same
101- # dependency twice in the result file when
102- # ("${${project}_TABLEGEN_TARGET}" STREQUAL "${${project}_TABLEGEN_EXE}")
103- # but lets us having smaller and cleaner code here.
104- get_directory_property (tblgen_includes INCLUDE_DIRECTORIES )
105- list (APPEND tblgen_includes ${ARG_EXTRA_INCLUDES} )
106-
107- # Get the current set of include paths for this td file.
108- cmake_parse_arguments (ARG "" "" "DEPENDS;EXTRA_INCLUDES" ${ARGN} )
109- get_directory_property (tblgen_includes INCLUDE_DIRECTORIES )
110- list (APPEND tblgen_includes ${ARG_EXTRA_INCLUDES} )
111- # Filter out any empty include items.
112- list (REMOVE_ITEM tblgen_includes "" )
113-
11496 # Build the absolute path for the current input file.
11597 if (IS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS} )
11698 set (LLVM_TARGET_DEFINITIONS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS} )
11799 else ()
118- set (LLVM_TARGET_DEFINITIONS_ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR} /${LLVM_TARGET_DEFINITIONS} )
100+ set (LLVM_TARGET_DEFINITIONS_ABSOLUTE
101+ ${CMAKE_CURRENT_SOURCE_DIR} /${LLVM_TARGET_DEFINITIONS} )
119102 endif ()
120103
121104 # Append this file and its includes to the compile commands file.
122105 # This file is used by the TableGen LSP Language Server (tblgen-lsp-server).
123106 file (APPEND ${CMAKE_BINARY_DIR} /tablegen_compile_commands.yml
124107 "--- !FileInfo:\n "
125108 " filepath: \" ${LLVM_TARGET_DEFINITIONS_ABSOLUTE} \"\n "
126- " includes: \" ${CMAKE_CURRENT_SOURCE_DIR} ; ${ tblgen_includes}\"\n "
109+ " includes: \" ${tblgen_includes} \"\n "
127110 )
128111
129- # Filter out empty items before prepending each entry with -I
130- list (REMOVE_ITEM tblgen_includes "" )
112+ # Prepend each include entry with -I for arguments.
131113 list (TRANSFORM tblgen_includes PREPEND -I)
132114
115+ # We need both _TABLEGEN_TARGET and _TABLEGEN_EXE in the DEPENDS list
116+ # (both the target and the file) to have .inc files rebuilt on
117+ # a tablegen change, as cmake does not propagate file-level dependencies
118+ # of custom targets. See the following ticket for more information:
119+ # https://cmake.org/Bug/view.php?id=15858
120+ # The dependency on both, the target and the file, produces the same
121+ # dependency twice in the result file when
122+ # ("${${project}_TABLEGEN_TARGET}" STREQUAL "${${project}_TABLEGEN_EXE}")
123+ # but lets us having smaller and cleaner code here.
133124 set (tablegen_exe ${${project} _TABLEGEN_EXE})
134125 set (tablegen_depends ${${project} _TABLEGEN_TARGET} ${tablegen_exe} )
135126
@@ -140,7 +131,7 @@ function(tablegen project ofn)
140131 endif ()
141132
142133 add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /${ofn}
143- COMMAND ${tablegen_exe} ${ARG_UNPARSED_ARGUMENTS} -I ${CMAKE_CURRENT_SOURCE_DIR}
134+ COMMAND ${tablegen_exe} ${ARG_UNPARSED_ARGUMENTS}
144135 ${tblgen_includes}
145136 ${LLVM_TABLEGEN_FLAGS}
146137 ${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
@@ -150,7 +141,7 @@ function(tablegen project ofn)
150141 # directory and local_tds may not contain it, so we must
151142 # explicitly list it here:
152143 DEPENDS ${ARG_DEPENDS} ${tablegen_depends}
153- ${local_tds} ${ global_tds}
144+ ${global_tds}
154145 ${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
155146 ${LLVM_TARGET_DEPENDS}
156147 ${LLVM_TABLEGEN_JOB_POOL}
0 commit comments