diff --git a/cmake/modules/TableGen.cmake b/cmake/modules/TableGen.cmake index 632f69aa338..8d0c5afabe9 100644 --- a/cmake/modules/TableGen.cmake +++ b/cmake/modules/TableGen.cmake @@ -2,10 +2,6 @@ # Extra parameters for `tblgen' may come after `ofn' parameter. # Adds the name of the generated file to TABLEGEN_OUTPUT. -if(LLVM_MAIN_INCLUDE_DIR) - set(LLVM_TABLEGEN_FLAGS -I ${LLVM_MAIN_INCLUDE_DIR}) -endif() - function(tablegen project ofn) # Validate calling context. if(NOT ${project}_TABLEGEN_EXE) @@ -75,6 +71,8 @@ function(tablegen project ofn) set(tblgen_change_flag "--write-if-changed") endif() + get_directory_property(includes "INCLUDE_DIRECTORIES") + list(TRANSFORM includes PREPEND -I) # We need both _TABLEGEN_TARGET and _TABLEGEN_EXE in the DEPENDS list # (both the target and the file) to have .inc files rebuilt on # a tablegen change, as cmake does not propagate file-level dependencies @@ -86,6 +84,7 @@ function(tablegen project ofn) # but lets us having smaller and cleaner code here. add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn} COMMAND ${${project}_TABLEGEN_EXE} ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR} + ${includes} ${LLVM_TABLEGEN_FLAGS} ${LLVM_TARGET_DEFINITIONS_ABSOLUTE} ${tblgen_change_flag}