Skip to content

Commit 0c0831f

Browse files
[CMAKE] Plumb include_directories() into tablegen()
Previously, the tablegen() cmake command, which defines custom commands for running tablegen, included several hardcoded paths. This becomes unwieldy as there are more users for which these paths are insufficient. For most targets, cmake uses include_directories() and the INCLUDE_DIRECTORIES directory property to specify include paths. This change picks up the INCLUDE_DIRECTORIES property and adds it to the include path used when running tablegen. As a side effect, this allows us to remove several hard coded paths to tablegen that are redundant with specified include_directories(). I haven't removed the hardcoded path to CMAKE_CURRENT_SOURCE_DIR, which seems generically useful. There are several users in clang which apparently don't have the current directory as an include_directories(). This could be considered separately. The new version of this path uses list APPEND rather than list TRANSFORM, in order to be compatible with cmake 3.4.3. If we update to cmake 3.12 then we can use list TRANSFORM instead. Differential Revision: https://reviews.llvm.org/D77156
1 parent 0462795 commit 0c0831f

File tree

12 files changed

+29
-24
lines changed

12 files changed

+29
-24
lines changed

clang/cmake/modules/AddClang.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function(clang_tablegen)
1717
message(FATAL_ERROR "SOURCE source-file required by clang_tablegen")
1818
endif()
1919

20-
set( CLANG_TABLEGEN_ARGUMENTS -I ${CLANG_SOURCE_DIR}/include )
20+
set( CLANG_TABLEGEN_ARGUMENTS "" )
2121
set( LLVM_TARGET_DEFINITIONS ${CTG_SOURCE} )
2222
tablegen(CLANG ${CTG_UNPARSED_ARGUMENTS} ${CLANG_TABLEGEN_ARGUMENTS})
2323

llvm/cmake/modules/TableGen.cmake

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
# Extra parameters for `tblgen' may come after `ofn' parameter.
33
# Adds the name of the generated file to TABLEGEN_OUTPUT.
44

5-
if(LLVM_MAIN_INCLUDE_DIR)
6-
set(LLVM_TABLEGEN_FLAGS -I ${LLVM_MAIN_INCLUDE_DIR})
7-
endif()
8-
95
function(tablegen project ofn)
106
# Validate calling context.
117
if(NOT ${project}_TABLEGEN_EXE)
@@ -75,6 +71,14 @@ function(tablegen project ofn)
7571
set(tblgen_change_flag "--write-if-changed")
7672
endif()
7773

74+
# With CMake 3.12 this can be reduced to:
75+
# get_directory_property(tblgen_includes "INCLUDE_DIRECTORIES")
76+
# list(TRANSFORM tblgen_includes PREPEND -I)
77+
set(tblgen_includes)
78+
get_directory_property(includes "INCLUDE_DIRECTORIES")
79+
foreach(include ${includes})
80+
list(APPEND tblgen_includes -I ${include})
81+
endforeach()
7882
# We need both _TABLEGEN_TARGET and _TABLEGEN_EXE in the DEPENDS list
7983
# (both the target and the file) to have .inc files rebuilt on
8084
# a tablegen change, as cmake does not propagate file-level dependencies
@@ -86,6 +90,7 @@ function(tablegen project ofn)
8690
# but lets us having smaller and cleaner code here.
8791
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
8892
COMMAND ${${project}_TABLEGEN_EXE} ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR}
93+
${tblgen_includes}
8994
${LLVM_TABLEGEN_FLAGS}
9095
${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
9196
${tblgen_change_flag}

mlir/cmake/modules/AddMLIR.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function(mlir_tablegen ofn)
2-
tablegen(MLIR ${ARGV} "-I${MLIR_MAIN_SRC_DIR}" "-I${MLIR_INCLUDE_DIR}")
2+
tablegen(MLIR ${ARGV})
33
set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
44
PARENT_SCOPE)
55
endfunction()

mlir/examples/toy/Ch3/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
include_directories(include)
12
add_subdirectory(include)
23

34
set(LLVM_LINK_COMPONENTS
45
Support
56
)
67

78
set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td)
8-
mlir_tablegen(ToyCombine.inc -gen-rewriters "-I${CMAKE_CURRENT_SOURCE_DIR}/include")
9+
mlir_tablegen(ToyCombine.inc -gen-rewriters)
910
add_public_tablegen_target(ToyCh3CombineIncGen)
1011

1112
add_toy_chapter(toyc-ch3
@@ -20,7 +21,6 @@ add_toy_chapter(toyc-ch3
2021
ToyCh3CombineIncGen
2122
)
2223

23-
include_directories(include/)
2424
include_directories(${CMAKE_CURRENT_BINARY_DIR})
2525
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
2626
target_link_libraries(toyc-ch3

mlir/examples/toy/Ch4/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
include_directories(include)
12
add_subdirectory(include)
23

34
set(LLVM_LINK_COMPONENTS
45
Support
56
)
67

78
set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td)
8-
mlir_tablegen(ToyCombine.inc -gen-rewriters "-I${CMAKE_CURRENT_SOURCE_DIR}/include")
9+
mlir_tablegen(ToyCombine.inc -gen-rewriters)
910
add_public_tablegen_target(ToyCh4CombineIncGen)
1011

1112
add_toy_chapter(toyc-ch4
@@ -22,7 +23,6 @@ add_toy_chapter(toyc-ch4
2223
ToyCh4CombineIncGen
2324
)
2425

25-
include_directories(include/)
2626
include_directories(${CMAKE_CURRENT_BINARY_DIR})
2727
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
2828
target_link_libraries(toyc-ch4

mlir/examples/toy/Ch4/include/toy/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set(LLVM_TARGET_DEFINITIONS Ops.td)
2-
mlir_tablegen(Ops.h.inc -gen-op-decls "-I${CMAKE_CURRENT_SOURCE_DIR}/..")
3-
mlir_tablegen(Ops.cpp.inc -gen-op-defs "-I${CMAKE_CURRENT_SOURCE_DIR}/..")
2+
mlir_tablegen(Ops.h.inc -gen-op-decls)
3+
mlir_tablegen(Ops.cpp.inc -gen-op-defs)
44
add_public_tablegen_target(ToyCh4OpsIncGen)
55

66
set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td)

mlir/examples/toy/Ch5/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
include_directories(include)
12
add_subdirectory(include)
23

34
set(LLVM_LINK_COMPONENTS
45
Support
56
)
67

78
set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td)
8-
mlir_tablegen(ToyCombine.inc -gen-rewriters "-I${CMAKE_CURRENT_SOURCE_DIR}/include")
9+
mlir_tablegen(ToyCombine.inc -gen-rewriters)
910
add_public_tablegen_target(ToyCh5CombineIncGen)
1011

1112
add_toy_chapter(toyc-ch5
@@ -23,7 +24,6 @@ add_toy_chapter(toyc-ch5
2324
ToyCh5CombineIncGen
2425
)
2526

26-
include_directories(include/)
2727
include_directories(${CMAKE_CURRENT_BINARY_DIR})
2828
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
2929
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)

mlir/examples/toy/Ch5/include/toy/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set(LLVM_TARGET_DEFINITIONS Ops.td)
2-
mlir_tablegen(Ops.h.inc -gen-op-decls "-I${CMAKE_CURRENT_SOURCE_DIR}/..")
3-
mlir_tablegen(Ops.cpp.inc -gen-op-defs "-I${CMAKE_CURRENT_SOURCE_DIR}/..")
2+
mlir_tablegen(Ops.h.inc -gen-op-decls)
3+
mlir_tablegen(Ops.cpp.inc -gen-op-defs)
44
add_public_tablegen_target(ToyCh5OpsIncGen)
55

66
set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td)

mlir/examples/toy/Ch6/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
include_directories(include)
12
add_subdirectory(include)
23

34
set(LLVM_LINK_COMPONENTS
@@ -6,7 +7,7 @@ set(LLVM_LINK_COMPONENTS
67
)
78

89
set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td)
9-
mlir_tablegen(ToyCombine.inc -gen-rewriters "-I${CMAKE_CURRENT_SOURCE_DIR}/include")
10+
mlir_tablegen(ToyCombine.inc -gen-rewriters)
1011
add_public_tablegen_target(ToyCh6CombineIncGen)
1112

1213
add_toy_chapter(toyc-ch6
@@ -25,7 +26,6 @@ add_toy_chapter(toyc-ch6
2526
ToyCh6CombineIncGen
2627
)
2728

28-
include_directories(include/)
2929
include_directories(${CMAKE_CURRENT_BINARY_DIR})
3030
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
3131
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)

mlir/examples/toy/Ch6/include/toy/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set(LLVM_TARGET_DEFINITIONS Ops.td)
2-
mlir_tablegen(Ops.h.inc -gen-op-decls "-I${CMAKE_CURRENT_SOURCE_DIR}/..")
3-
mlir_tablegen(Ops.cpp.inc -gen-op-defs "-I${CMAKE_CURRENT_SOURCE_DIR}/..")
2+
mlir_tablegen(Ops.h.inc -gen-op-decls)
3+
mlir_tablegen(Ops.cpp.inc -gen-op-defs)
44
add_public_tablegen_target(ToyCh6OpsIncGen)
55

66
set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td)

mlir/examples/toy/Ch7/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
include_directories(include)
12
add_subdirectory(include)
23

34
set(LLVM_LINK_COMPONENTS
@@ -6,7 +7,7 @@ set(LLVM_LINK_COMPONENTS
67
)
78

89
set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td)
9-
mlir_tablegen(ToyCombine.inc -gen-rewriters "-I${CMAKE_CURRENT_SOURCE_DIR}/include")
10+
mlir_tablegen(ToyCombine.inc -gen-rewriters)
1011
add_public_tablegen_target(ToyCh7CombineIncGen)
1112

1213
add_toy_chapter(toyc-ch7
@@ -25,7 +26,6 @@ add_toy_chapter(toyc-ch7
2526
ToyCh7CombineIncGen
2627
)
2728

28-
include_directories(include/)
2929
include_directories(${CMAKE_CURRENT_BINARY_DIR})
3030
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
3131
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)

mlir/examples/toy/Ch7/include/toy/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set(LLVM_TARGET_DEFINITIONS Ops.td)
2-
mlir_tablegen(Ops.h.inc -gen-op-decls "-I${CMAKE_CURRENT_SOURCE_DIR}/..")
3-
mlir_tablegen(Ops.cpp.inc -gen-op-defs "-I${CMAKE_CURRENT_SOURCE_DIR}/..")
2+
mlir_tablegen(Ops.h.inc -gen-op-decls)
3+
mlir_tablegen(Ops.cpp.inc -gen-op-defs)
44
add_public_tablegen_target(ToyCh7OpsIncGen)
55

66
set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td)

0 commit comments

Comments
 (0)