|
4 | 4 | # Adds the name of the generated file to TABLEGEN_OUTPUT.
|
5 | 5 | include(LLVMDistributionSupport)
|
6 | 6 |
|
| 7 | +# Clear out any pre-existing compile_commands file before processing. This |
| 8 | +# allows for generating a clean compile_commands on each configure. |
| 9 | +file(REMOVE ${CMAKE_BINARY_DIR}/tablegen_compile_commands.yml) |
| 10 | + |
7 | 11 | function(tablegen project ofn)
|
8 | 12 | cmake_parse_arguments(ARG "" "" "DEPENDS;EXTRA_INCLUDES" ${ARGN})
|
9 | 13 |
|
@@ -91,6 +95,29 @@ function(tablegen project ofn)
|
91 | 95 | # but lets us having smaller and cleaner code here.
|
92 | 96 | get_directory_property(tblgen_includes INCLUDE_DIRECTORIES)
|
93 | 97 | list(APPEND tblgen_includes ${ARG_EXTRA_INCLUDES})
|
| 98 | + |
| 99 | + # Get the current set of include paths for this td file. |
| 100 | + cmake_parse_arguments(ARG "" "" "DEPENDS;EXTRA_INCLUDES" ${ARGN}) |
| 101 | + get_directory_property(tblgen_includes INCLUDE_DIRECTORIES) |
| 102 | + list(APPEND tblgen_includes ${ARG_EXTRA_INCLUDES}) |
| 103 | + # Filter out any empty include items. |
| 104 | + list(REMOVE_ITEM tblgen_includes "") |
| 105 | + |
| 106 | + # Build the absolute path for the current input file. |
| 107 | + if (IS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS}) |
| 108 | + set(LLVM_TARGET_DEFINITIONS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS}) |
| 109 | + else() |
| 110 | + set(LLVM_TARGET_DEFINITIONS_ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/${LLVM_TARGET_DEFINITIONS}) |
| 111 | + endif() |
| 112 | + |
| 113 | + # Append this file and its includes to the compile commands file. |
| 114 | + # This file is used by the TableGen LSP Language Server (tblgen-lsp-server). |
| 115 | + file(APPEND ${CMAKE_BINARY_DIR}/tablegen_compile_commands.yml |
| 116 | + "--- !FileInfo:\n" |
| 117 | + " filepath: \"${LLVM_TARGET_DEFINITIONS_ABSOLUTE}\"\n" |
| 118 | + " includes: \"${CMAKE_CURRENT_SOURCE_DIR};${tblgen_includes}\"\n" |
| 119 | + ) |
| 120 | + |
94 | 121 | # Filter out empty items before prepending each entry with -I
|
95 | 122 | list(REMOVE_ITEM tblgen_includes "")
|
96 | 123 | list(TRANSFORM tblgen_includes PREPEND -I)
|
|
0 commit comments