[cmake] Properly support target properties.
authorStephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Mon, 16 Aug 2021 00:05:25 +0000 (17:05 -0700)
committerStephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Tue, 17 Aug 2021 21:08:21 +0000 (14:08 -0700)
It's sometimes useful to use these directives when dealing with
external projects:
target_link_directories
target_link_libraries
target_include_directories

However, under certain circumstances,
llvm_add_library can generate multiple targets.  We need to transfer
these properties to the new targets.  Note that using a generator
expression is necessary because these properties will only be set
after llvm_add_library is called.

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

llvm/cmake/modules/AddLLVM.cmake

index 3e009f5..2d497d0 100644 (file)
@@ -486,6 +486,9 @@ function(llvm_add_library name)
     # 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")
     if(ARG_DEPENDS)
       add_dependencies(${obj_name} ${ARG_DEPENDS})
@@ -525,6 +528,11 @@ function(llvm_add_library name)
       LINK_LIBS ${ARG_LINK_LIBS}
       LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
       )
+
+    # Bring in the target link info from our original target.
+    target_link_directories(${name_static} PRIVATE $<TARGET_PROPERTY:${name},LINK_DIRECTORIES>)
+    target_link_libraries(${name_static} PRIVATE $<TARGET_PROPERTY:${name},LINK_LIBRARIES>)
+
     # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY.
     set(ARG_STATIC)
   endif()