@@ -21,6 +21,13 @@ function(tablegen project ofn)
21
21
message (FATAL_ERROR "${project} _TABLEGEN_EXE not set" )
22
22
endif ()
23
23
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
+
24
31
# Use depfile instead of globbing arbitrary *.td(s) for Ninja. We force
25
32
# CMake versions older than v3.30 on Windows to use the fallback behavior
26
33
# due to a depfile parsing bug on Windows paths in versions prior to 3.30.
@@ -42,22 +49,16 @@ function(tablegen project ofn)
42
49
-d ${ofn} .d
43
50
DEPFILE ${ofn} .d
44
51
)
45
- set (local_tds )
46
52
set (global_tds )
47
53
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} )
50
57
set (additional_cmdline
51
58
-o ${CMAKE_CURRENT_BINARY_DIR} /${ofn}
52
59
)
53
60
endif ()
54
61
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 ()
61
62
if (LLVM_ENABLE_DAGISEL_COV AND "-gen-dag-isel" IN_LIST ARGN )
62
63
list (APPEND LLVM_TABLEGEN_FLAGS "-instrument-coverage" )
63
64
endif ()
@@ -92,44 +93,34 @@ function(tablegen project ofn)
92
93
list (APPEND LLVM_TABLEGEN_FLAGS "-no-warn-on-unused-template-args" )
93
94
endif ()
94
95
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
-
114
96
# Build the absolute path for the current input file.
115
97
if (IS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS} )
116
98
set (LLVM_TARGET_DEFINITIONS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS} )
117
99
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} )
119
102
endif ()
120
103
121
104
# Append this file and its includes to the compile commands file.
122
105
# This file is used by the TableGen LSP Language Server (tblgen-lsp-server).
123
106
file (APPEND ${CMAKE_BINARY_DIR} /tablegen_compile_commands.yml
124
107
"--- !FileInfo:\n "
125
108
" filepath: \" ${LLVM_TARGET_DEFINITIONS_ABSOLUTE} \"\n "
126
- " includes: \" ${CMAKE_CURRENT_SOURCE_DIR} ; ${ tblgen_includes}\"\n "
109
+ " includes: \" ${tblgen_includes} \"\n "
127
110
)
128
111
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.
131
113
list (TRANSFORM tblgen_includes PREPEND -I )
132
114
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.
133
124
set (tablegen_exe ${${project}_TABLEGEN_EXE} )
134
125
set (tablegen_depends ${${project}_TABLEGEN_TARGET} ${tablegen_exe} )
135
126
@@ -140,7 +131,7 @@ function(tablegen project ofn)
140
131
endif ()
141
132
142
133
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}
144
135
${tblgen_includes}
145
136
${LLVM_TABLEGEN_FLAGS}
146
137
${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
@@ -150,7 +141,7 @@ function(tablegen project ofn)
150
141
# directory and local_tds may not contain it, so we must
151
142
# explicitly list it here:
152
143
DEPENDS ${ARG_DEPENDS} ${tablegen_depends}
153
- ${local_tds} ${ global_tds}
144
+ ${global_tds}
154
145
${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
155
146
${LLVM_TARGET_DEPENDS}
156
147
${LLVM_TABLEGEN_JOB_POOL}
0 commit comments