[clang] ae044c5 - [CMAKE] Plumb include_directories() into tablegen()

2020-04-03 Thread Stephen Neuendorffer via cfe-commits

Author: Stephen Neuendorffer
Date: 2020-04-03T10:38:25-07:00
New Revision: ae044c5b0caa095602b6ef4cca40d57efc26a8f6

URL: 
https://github.com/llvm/llvm-project/commit/ae044c5b0caa095602b6ef4cca40d57efc26a8f6
DIFF: 
https://github.com/llvm/llvm-project/commit/ae044c5b0caa095602b6ef4cca40d57efc26a8f6.diff

LOG: [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.

Differential Revision: https://reviews.llvm.org/D77156

Added: 


Modified: 
clang/cmake/modules/AddClang.cmake
llvm/cmake/modules/TableGen.cmake
mlir/cmake/modules/AddMLIR.cmake
mlir/examples/toy/Ch3/CMakeLists.txt
mlir/examples/toy/Ch4/CMakeLists.txt
mlir/examples/toy/Ch4/include/toy/CMakeLists.txt
mlir/examples/toy/Ch5/CMakeLists.txt
mlir/examples/toy/Ch5/include/toy/CMakeLists.txt
mlir/examples/toy/Ch6/CMakeLists.txt
mlir/examples/toy/Ch6/include/toy/CMakeLists.txt
mlir/examples/toy/Ch7/CMakeLists.txt
mlir/examples/toy/Ch7/include/toy/CMakeLists.txt

Removed: 




diff  --git a/clang/cmake/modules/AddClang.cmake 
b/clang/cmake/modules/AddClang.cmake
index 577cc11ab015..c1bb386de6f7 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -17,7 +17,7 @@ function(clang_tablegen)
 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
index 632f69aa3386..8d0c5afabe96 100644
--- 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,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}

diff  --git a/mlir/cmake/modules/AddMLIR.cmake 
b/mlir/cmake/modules/AddMLIR.cmake
index 2adb8f2f2935..7449f54ea877 100644
--- 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
index 4dab5e4d0626..ef70dcbac309 100644
--- 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_LINK_COMPONENTS
   )
 
 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 @@ add_toy_chapter(toyc-ch3
   ToyCh3CombineIncGen
   )
 
-include_directories(include

[clang] f288c21 - Revert "[CMAKE] Plumb include_directories() into tablegen()"

2020-04-03 Thread Stephen Neuendorffer via cfe-commits

Author: Stephen Neuendorffer
Date: 2020-04-03T10:47:36-07:00
New Revision: f288c216875d6cba6465230cbb0677e839775cd9

URL: 
https://github.com/llvm/llvm-project/commit/f288c216875d6cba6465230cbb0677e839775cd9
DIFF: 
https://github.com/llvm/llvm-project/commit/f288c216875d6cba6465230cbb0677e839775cd9.diff

LOG: Revert "[CMAKE] Plumb include_directories() into tablegen()"

This reverts commit ae044c5b0caa095602b6ef4cca40d57efc26a8f6.

This breaks the buildbots, which use an older version of cmake.

Added: 


Modified: 
clang/cmake/modules/AddClang.cmake
llvm/cmake/modules/TableGen.cmake
mlir/cmake/modules/AddMLIR.cmake
mlir/examples/toy/Ch3/CMakeLists.txt
mlir/examples/toy/Ch4/CMakeLists.txt
mlir/examples/toy/Ch4/include/toy/CMakeLists.txt
mlir/examples/toy/Ch5/CMakeLists.txt
mlir/examples/toy/Ch5/include/toy/CMakeLists.txt
mlir/examples/toy/Ch6/CMakeLists.txt
mlir/examples/toy/Ch6/include/toy/CMakeLists.txt
mlir/examples/toy/Ch7/CMakeLists.txt
mlir/examples/toy/Ch7/include/toy/CMakeLists.txt

Removed: 




diff  --git a/clang/cmake/modules/AddClang.cmake 
b/clang/cmake/modules/AddClang.cmake
index c1bb386de6f7..577cc11ab015 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -17,7 +17,7 @@ function(clang_tablegen)
 message(FATAL_ERROR "SOURCE source-file required by clang_tablegen")
   endif()
 
-  set( CLANG_TABLEGEN_ARGUMENTS "" )
+  set( CLANG_TABLEGEN_ARGUMENTS -I ${CLANG_SOURCE_DIR}/include )
   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
index 8d0c5afabe96..632f69aa3386 100644
--- a/llvm/cmake/modules/TableGen.cmake
+++ b/llvm/cmake/modules/TableGen.cmake
@@ -2,6 +2,10 @@
 # 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)
@@ -71,8 +75,6 @@ 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
@@ -84,7 +86,6 @@ 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}

diff  --git a/mlir/cmake/modules/AddMLIR.cmake 
b/mlir/cmake/modules/AddMLIR.cmake
index 7449f54ea877..2adb8f2f2935 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -1,5 +1,5 @@
 function(mlir_tablegen ofn)
-  tablegen(MLIR ${ARGV})
+  tablegen(MLIR ${ARGV} "-I${MLIR_MAIN_SRC_DIR}" "-I${MLIR_INCLUDE_DIR}")
   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
index ef70dcbac309..4dab5e4d0626 100644
--- a/mlir/examples/toy/Ch3/CMakeLists.txt
+++ b/mlir/examples/toy/Ch3/CMakeLists.txt
@@ -1,4 +1,3 @@
-include_directories(include)
 add_subdirectory(include)
 
 set(LLVM_LINK_COMPONENTS
@@ -6,7 +5,7 @@ set(LLVM_LINK_COMPONENTS
   )
 
 set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td)
-mlir_tablegen(ToyCombine.inc -gen-rewriters)
+mlir_tablegen(ToyCombine.inc -gen-rewriters 
"-I${CMAKE_CURRENT_SOURCE_DIR}/include")
 add_public_tablegen_target(ToyCh3CombineIncGen)
 
 add_toy_chapter(toyc-ch3
@@ -21,6 +20,7 @@ add_toy_chapter(toyc-ch3
   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
index ae30a691894e..3589b10645a6 100644
--- a/mlir/examples/toy/Ch4/CMakeLists.txt
+++ b/mlir/examples/toy/Ch4/CMakeLists.txt
@@ -1,4 +1,3 @@
-include_directories(include)
 add_subdirectory(include)
 
 set(LLVM_LINK_COMPONENTS
@@ -6,7 +5,7 @@ set(LLVM_LINK_COMPONENTS
   )
 
 set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td)
-mlir_tablegen(ToyCombine.inc -gen-rewriters)
+mlir_tablegen(ToyCombine.inc -gen-rewriters 
"-I${CMAKE_CURRENT_SOURCE_DIR}/include")
 add_public_tablegen_target(ToyCh4CombineIncGen)
 
 add_toy_chapter(t

[clang] 0c0831f - [CMAKE] Plumb include_directories() into tablegen()

2020-04-03 Thread Stephen Neuendorffer via cfe-commits

Author: Stephen Neuendorffer
Date: 2020-04-03T11:23:38-07:00
New Revision: 0c0831f74b7181268a777a39ee087c9337ffa0c5

URL: 
https://github.com/llvm/llvm-project/commit/0c0831f74b7181268a777a39ee087c9337ffa0c5
DIFF: 
https://github.com/llvm/llvm-project/commit/0c0831f74b7181268a777a39ee087c9337ffa0c5.diff

LOG: [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

Added: 


Modified: 
clang/cmake/modules/AddClang.cmake
llvm/cmake/modules/TableGen.cmake
mlir/cmake/modules/AddMLIR.cmake
mlir/examples/toy/Ch3/CMakeLists.txt
mlir/examples/toy/Ch4/CMakeLists.txt
mlir/examples/toy/Ch4/include/toy/CMakeLists.txt
mlir/examples/toy/Ch5/CMakeLists.txt
mlir/examples/toy/Ch5/include/toy/CMakeLists.txt
mlir/examples/toy/Ch6/CMakeLists.txt
mlir/examples/toy/Ch6/include/toy/CMakeLists.txt
mlir/examples/toy/Ch7/CMakeLists.txt
mlir/examples/toy/Ch7/include/toy/CMakeLists.txt

Removed: 




diff  --git a/clang/cmake/modules/AddClang.cmake 
b/clang/cmake/modules/AddClang.cmake
index 577cc11ab015..c1bb386de6f7 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -17,7 +17,7 @@ function(clang_tablegen)
 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
index 632f69aa3386..65e31d0624f0 100644
--- 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 @@ function(tablegen project ofn)
 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 @@ 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}
+${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
index 2adb8f2f2935..7449f54ea877 100644
--- 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
index 4dab5e4d0626..ef70dcbac309 100644
--- a/mlir/examples/toy/Ch3/CMakeLists.txt
+++ b/mlir/examples/toy/Ch3/CMakeLists.txt
@@ -1,3 +1,4 @@
+include_directories(include)
 add_subdirectory(include)
 

[clang] fce1eef - [clang] fix lib/ASTMatchers for BUILD_SHARED_LIBS=ON

2020-02-04 Thread Stephen Neuendorffer via cfe-commits

Author: Stephen Neuendorffer
Date: 2020-02-04T09:54:28-08:00
New Revision: fce1eefb467e2bc3cd737ce78386e4970beefb7a

URL: 
https://github.com/llvm/llvm-project/commit/fce1eefb467e2bc3cd737ce78386e4970beefb7a
DIFF: 
https://github.com/llvm/llvm-project/commit/fce1eefb467e2bc3cd737ce78386e4970beefb7a.diff

LOG: [clang] fix lib/ASTMatchers for BUILD_SHARED_LIBS=ON

Added: 


Modified: 
clang/lib/ASTMatchers/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/ASTMatchers/CMakeLists.txt 
b/clang/lib/ASTMatchers/CMakeLists.txt
index b49528ede227..cd88d1db9ce4 100644
--- a/clang/lib/ASTMatchers/CMakeLists.txt
+++ b/clang/lib/ASTMatchers/CMakeLists.txt
@@ -9,4 +9,5 @@ add_clang_library(clangASTMatchers
   LINK_LIBS
   clangAST
   clangBasic
+  clangLex
   )



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits