diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake --- a/clang/cmake/modules/AddClang.cmake +++ b/clang/cmake/modules/AddClang.cmake @@ -17,7 +17,7 @@ message(FATAL_ERROR "SOURCE source-file required by clang_tablegen") endif() - set( CLANG_TABLEGEN_ARGUMENTS -I ${CLANG_SOURCE_DIR}/include ) + set( CLANG_TABLEGEN_ARGUMENTS "" ) set( LLVM_TARGET_DEFINITIONS ${CTG_SOURCE} ) tablegen(CLANG ${CTG_UNPARSED_ARGUMENTS} ${CLANG_TABLEGEN_ARGUMENTS}) diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake --- a/llvm/cmake/modules/TableGen.cmake +++ b/llvm/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,14 @@ set(tblgen_change_flag "--write-if-changed") endif() + # With CMake 3.12 this can be reduced to: + # get_directory_property(tblgen_includes "INCLUDE_DIRECTORIES") + # list(TRANSFORM tblgen_includes PREPEND -I) + set(tblgen_includes) + get_directory_property(includes "INCLUDE_DIRECTORIES") + foreach(include ${includes}) + list(APPEND tblgen_includes -I ${include}) + endforeach() # 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 +90,7 @@ # 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} + ${tblgen_includes} ${LLVM_TABLEGEN_FLAGS} ${LLVM_TARGET_DEFINITIONS_ABSOLUTE} ${tblgen_change_flag} diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake --- a/mlir/cmake/modules/AddMLIR.cmake +++ b/mlir/cmake/modules/AddMLIR.cmake @@ -1,5 +1,5 @@ function(mlir_tablegen ofn) - tablegen(MLIR ${ARGV} "-I${MLIR_MAIN_SRC_DIR}" "-I${MLIR_INCLUDE_DIR}") + tablegen(MLIR ${ARGV}) set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn} PARENT_SCOPE) endfunction() diff --git a/mlir/examples/toy/Ch3/CMakeLists.txt b/mlir/examples/toy/Ch3/CMakeLists.txt --- a/mlir/examples/toy/Ch3/CMakeLists.txt +++ b/mlir/examples/toy/Ch3/CMakeLists.txt @@ -1,3 +1,4 @@ +include_directories(include) add_subdirectory(include) set(LLVM_LINK_COMPONENTS @@ -5,7 +6,7 @@ ) set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) -mlir_tablegen(ToyCombine.inc -gen-rewriters "-I${CMAKE_CURRENT_SOURCE_DIR}/include") +mlir_tablegen(ToyCombine.inc -gen-rewriters) add_public_tablegen_target(ToyCh3CombineIncGen) add_toy_chapter(toyc-ch3 @@ -20,7 +21,6 @@ ToyCh3CombineIncGen ) -include_directories(include/) include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) target_link_libraries(toyc-ch3 diff --git a/mlir/examples/toy/Ch4/CMakeLists.txt b/mlir/examples/toy/Ch4/CMakeLists.txt --- a/mlir/examples/toy/Ch4/CMakeLists.txt +++ b/mlir/examples/toy/Ch4/CMakeLists.txt @@ -1,3 +1,4 @@ +include_directories(include) add_subdirectory(include) set(LLVM_LINK_COMPONENTS @@ -5,7 +6,7 @@ ) set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) -mlir_tablegen(ToyCombine.inc -gen-rewriters "-I${CMAKE_CURRENT_SOURCE_DIR}/include") +mlir_tablegen(ToyCombine.inc -gen-rewriters) add_public_tablegen_target(ToyCh4CombineIncGen) add_toy_chapter(toyc-ch4 @@ -22,7 +23,6 @@ ToyCh4CombineIncGen ) -include_directories(include/) include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) target_link_libraries(toyc-ch4 diff --git a/mlir/examples/toy/Ch4/include/toy/CMakeLists.txt b/mlir/examples/toy/Ch4/include/toy/CMakeLists.txt --- a/mlir/examples/toy/Ch4/include/toy/CMakeLists.txt +++ b/mlir/examples/toy/Ch4/include/toy/CMakeLists.txt @@ -1,6 +1,6 @@ set(LLVM_TARGET_DEFINITIONS Ops.td) -mlir_tablegen(Ops.h.inc -gen-op-decls "-I${CMAKE_CURRENT_SOURCE_DIR}/..") -mlir_tablegen(Ops.cpp.inc -gen-op-defs "-I${CMAKE_CURRENT_SOURCE_DIR}/..") +mlir_tablegen(Ops.h.inc -gen-op-decls) +mlir_tablegen(Ops.cpp.inc -gen-op-defs) add_public_tablegen_target(ToyCh4OpsIncGen) set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td) diff --git a/mlir/examples/toy/Ch5/CMakeLists.txt b/mlir/examples/toy/Ch5/CMakeLists.txt --- a/mlir/examples/toy/Ch5/CMakeLists.txt +++ b/mlir/examples/toy/Ch5/CMakeLists.txt @@ -1,3 +1,4 @@ +include_directories(include) add_subdirectory(include) set(LLVM_LINK_COMPONENTS @@ -5,7 +6,7 @@ ) set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) -mlir_tablegen(ToyCombine.inc -gen-rewriters "-I${CMAKE_CURRENT_SOURCE_DIR}/include") +mlir_tablegen(ToyCombine.inc -gen-rewriters) add_public_tablegen_target(ToyCh5CombineIncGen) add_toy_chapter(toyc-ch5 @@ -23,7 +24,6 @@ ToyCh5CombineIncGen ) -include_directories(include/) include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) diff --git a/mlir/examples/toy/Ch5/include/toy/CMakeLists.txt b/mlir/examples/toy/Ch5/include/toy/CMakeLists.txt --- a/mlir/examples/toy/Ch5/include/toy/CMakeLists.txt +++ b/mlir/examples/toy/Ch5/include/toy/CMakeLists.txt @@ -1,6 +1,6 @@ set(LLVM_TARGET_DEFINITIONS Ops.td) -mlir_tablegen(Ops.h.inc -gen-op-decls "-I${CMAKE_CURRENT_SOURCE_DIR}/..") -mlir_tablegen(Ops.cpp.inc -gen-op-defs "-I${CMAKE_CURRENT_SOURCE_DIR}/..") +mlir_tablegen(Ops.h.inc -gen-op-decls) +mlir_tablegen(Ops.cpp.inc -gen-op-defs) add_public_tablegen_target(ToyCh5OpsIncGen) set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td) diff --git a/mlir/examples/toy/Ch6/CMakeLists.txt b/mlir/examples/toy/Ch6/CMakeLists.txt --- a/mlir/examples/toy/Ch6/CMakeLists.txt +++ b/mlir/examples/toy/Ch6/CMakeLists.txt @@ -1,3 +1,4 @@ +include_directories(include) add_subdirectory(include) set(LLVM_LINK_COMPONENTS @@ -6,7 +7,7 @@ ) set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) -mlir_tablegen(ToyCombine.inc -gen-rewriters "-I${CMAKE_CURRENT_SOURCE_DIR}/include") +mlir_tablegen(ToyCombine.inc -gen-rewriters) add_public_tablegen_target(ToyCh6CombineIncGen) add_toy_chapter(toyc-ch6 @@ -25,7 +26,6 @@ ToyCh6CombineIncGen ) -include_directories(include/) include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) diff --git a/mlir/examples/toy/Ch6/include/toy/CMakeLists.txt b/mlir/examples/toy/Ch6/include/toy/CMakeLists.txt --- a/mlir/examples/toy/Ch6/include/toy/CMakeLists.txt +++ b/mlir/examples/toy/Ch6/include/toy/CMakeLists.txt @@ -1,6 +1,6 @@ set(LLVM_TARGET_DEFINITIONS Ops.td) -mlir_tablegen(Ops.h.inc -gen-op-decls "-I${CMAKE_CURRENT_SOURCE_DIR}/..") -mlir_tablegen(Ops.cpp.inc -gen-op-defs "-I${CMAKE_CURRENT_SOURCE_DIR}/..") +mlir_tablegen(Ops.h.inc -gen-op-decls) +mlir_tablegen(Ops.cpp.inc -gen-op-defs) add_public_tablegen_target(ToyCh6OpsIncGen) set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td) diff --git a/mlir/examples/toy/Ch7/CMakeLists.txt b/mlir/examples/toy/Ch7/CMakeLists.txt --- a/mlir/examples/toy/Ch7/CMakeLists.txt +++ b/mlir/examples/toy/Ch7/CMakeLists.txt @@ -1,3 +1,4 @@ +include_directories(include) add_subdirectory(include) set(LLVM_LINK_COMPONENTS @@ -6,7 +7,7 @@ ) set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) -mlir_tablegen(ToyCombine.inc -gen-rewriters "-I${CMAKE_CURRENT_SOURCE_DIR}/include") +mlir_tablegen(ToyCombine.inc -gen-rewriters) add_public_tablegen_target(ToyCh7CombineIncGen) add_toy_chapter(toyc-ch7 @@ -25,7 +26,6 @@ ToyCh7CombineIncGen ) -include_directories(include/) include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) diff --git a/mlir/examples/toy/Ch7/include/toy/CMakeLists.txt b/mlir/examples/toy/Ch7/include/toy/CMakeLists.txt --- a/mlir/examples/toy/Ch7/include/toy/CMakeLists.txt +++ b/mlir/examples/toy/Ch7/include/toy/CMakeLists.txt @@ -1,6 +1,6 @@ set(LLVM_TARGET_DEFINITIONS Ops.td) -mlir_tablegen(Ops.h.inc -gen-op-decls "-I${CMAKE_CURRENT_SOURCE_DIR}/..") -mlir_tablegen(Ops.cpp.inc -gen-op-defs "-I${CMAKE_CURRENT_SOURCE_DIR}/..") +mlir_tablegen(Ops.h.inc -gen-op-decls) +mlir_tablegen(Ops.cpp.inc -gen-op-defs) add_public_tablegen_target(ToyCh7OpsIncGen) set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td)