[PATCH] D120788: [cmake] Add INTERFACE_INCLUDE_DIRECTORIES to LLVM and MLIR.

Stella Laurenzo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 1 20:09:09 PST 2022


stellaraccident created this revision.
Herald added subscribers: sdasgup3, wenzhicui, wrengr, Chia-hungDuan, dcaballe, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini, mgorny.
Herald added a project: All.
stellaraccident requested review of this revision.
Herald added subscribers: llvm-commits, stephenneuendorffer, nicolasvasilache.
Herald added projects: MLIR, LLVM.

We've long needed to do this and it really helps out of tree projects since it eliminates the need to set up include paths when taking a source dep on LLVM or MLIR libraries (every external project I work on has some ~dozen lines of include path hackery to make it work, and this eliminates it).

In the future, as the project structures evolve, we could bootstrap the public include paths off of directory properties if that helps (I've seen repo restructuring proposals that may need this flexibility). In any case, we should not require clients of libraries to know those details.

This will let me roll back some hacks from out of tree projects, which will leave a couple of things (likely tablegen related), which we can also look to fix.

This patch has no effect on installed deps (that is what the `$<BUILD_INTERFACE:>` expression does -- scopes it to source deps in the build system). We may also want to use the `$<INSTALL_INTERFACE:>` expression to make installed builds automatic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120788

Files:
  llvm/cmake/modules/AddLLVM.cmake
  mlir/cmake/modules/AddMLIR.cmake


Index: mlir/cmake/modules/AddMLIR.cmake
===================================================================
--- mlir/cmake/modules/AddMLIR.cmake
+++ mlir/cmake/modules/AddMLIR.cmake
@@ -145,7 +145,15 @@
   endforeach()
 
   list(APPEND ARG_DEPENDS mlir-generic-headers)
-  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs} DEPENDS ${ARG_DEPENDS} LINK_COMPONENTS ${ARG_LINK_COMPONENTS} LINK_LIBS ${ARG_LINK_LIBS})
+  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs}
+      DEPENDS ${ARG_DEPENDS}
+      LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
+      LINK_LIBS ${ARG_LINK_LIBS})
+
+  target_include_directories(${name} PUBLIC
+    $<BUILD_INTERFACE:${MLIR_SOURCE_DIR}/include>
+    $<BUILD_INTERFACE:${MLIR_INCLUDE_DIR}>
+  )
 
   if(TARGET ${name})
     target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -492,10 +492,13 @@
     # Do add_dependencies(obj) later due to CMake issue 14747.
     list(APPEND objlibs ${obj_name})
 
-    # Bring in the target include directories from our original target.
-    target_include_directories(${obj_name} PRIVATE $<TARGET_PROPERTY:${name},INCLUDE_DIRECTORIES>)
-
-    set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
+    # Mirror the private and interface include directories from the original
+    # target.
+    set_target_properties(${obj_name} PROPERTIES
+      INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:${name},INCLUDE_DIRECTORIES>"
+      INTERFACE_INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:${name},INTERFACE_INCLUDE_DIRECTORIES>"
+      FOLDER "Object Libraries"
+    )
     if(ARG_DEPENDS)
       add_dependencies(${obj_name} ${ARG_DEPENDS})
     endif()
@@ -812,6 +815,11 @@
     llvm_add_library(${name} ${ARG_UNPARSED_ARGUMENTS})
   endif()
 
+  target_include_directories(${name} PUBLIC
+    $<BUILD_INTERFACE:${LLVM_MAIN_INCLUDE_DIR}>
+    $<BUILD_INTERFACE:${LLVM_INCLUDE_DIR}>
+  )
+
   # Libraries that are meant to only be exposed via the build tree only are
   # never installed and are only exported as a target in the special build tree
   # config file.
@@ -1850,7 +1858,7 @@
 function(add_lit_testsuites project directory)
   if (NOT LLVM_ENABLE_IDE)
     cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" "PARAMS;DEPENDS;ARGS" ${ARGN})
-    
+
     if (NOT ARG_FOLDER)
       set(ARG_FOLDER "Test Subdirectories")
     endif()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120788.412313.patch
Type: text/x-patch
Size: 2552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220302/4307ee5a/attachment.bin>


More information about the llvm-commits mailing list