[CMake] Use target_link_libraries(INTERFACE|PRIVATE) on CMake-2.8.12 to increase...
authorNAKAMURA Takumi <geek4civic@gmail.com>
Wed, 26 Feb 2014 06:53:16 +0000 (06:53 +0000)
committerNAKAMURA Takumi <geek4civic@gmail.com>
Wed, 26 Feb 2014 06:53:16 +0000 (06:53 +0000)
target_link_libraries(INTERFACE) doesn't bring inter-target dependencies in add_library,
although final targets have dependencies to whole dependent libraries.
It makes most libraries can be built in parallel.

target_link_libraries(PRIVATE) is used to shaared library.
Each dependent library is linked to the target.so, and its user will not see its grandchildren.
For example,

  - libclang.so has sufficient libclang*.a(s).
  - c-index-test requires just only libclang.so.

FIXME: lld is tweaked minimally. Adding INTERFACE in each library would be better thing.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202241 91177308-0d34-0410-b5e6-96231b3b80d8

cmake/modules/AddLLVM.cmake
cmake/modules/LLVM-Config.cmake
lib/Support/CMakeLists.txt

index bce3b2dd760b0052cdf0dd32a7176dfa83c5afa7..543ba93e552fd9d78171c1a6e0b9a70c55fd70c5 100644 (file)
@@ -289,7 +289,12 @@ function(llvm_add_library name)
     endif()
   endif()
 
     endif()
   endif()
 
-  target_link_libraries(${name} ${ARG_LINK_LIBS})
+  if(ARG_STATIC)
+    target_link_libraries(${name} ${cmake_2_8_12_INTERFACE} ${ARG_LINK_LIBS})
+  else()
+    # MODULE|SHARED
+    target_link_libraries(${name} ${cmake_2_8_12_PRIVATE} ${ARG_LINK_LIBS})
+  endif()
 
   llvm_config(${name} ${ARG_LINK_COMPONENTS} ${LLVM_LINK_COMPONENTS})
 
 
   llvm_config(${name} ${ARG_LINK_COMPONENTS} ${LLVM_LINK_COMPONENTS})
 
@@ -330,7 +335,7 @@ macro(add_llvm_library name)
   # name, but using get_property(... SET) doesn't suffice to determine if a
   # property has been set to an empty value.
   get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
   # name, but using get_property(... SET) doesn't suffice to determine if a
   # property has been set to an empty value.
   get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
-  target_link_libraries(${name} ${lib_deps})
+  target_link_libraries(${name} ${cmake_2_8_12_INTERFACE} ${lib_deps})
 endmacro(add_llvm_library name)
 
 macro(add_llvm_loadable_module name)
 endmacro(add_llvm_library name)
 
 macro(add_llvm_loadable_module name)
index 451fc56c6bfafb14a4d75c454e2f14a187b4b20c..2783af807a182b4a39da7fe1053a696677d22cf2 100644 (file)
@@ -39,7 +39,15 @@ function(explicit_llvm_config executable)
   set( link_components ${ARGN} )
 
   llvm_map_components_to_libnames(LIBRARIES ${link_components})
   set( link_components ${ARGN} )
 
   llvm_map_components_to_libnames(LIBRARIES ${link_components})
-  target_link_libraries(${executable} ${LIBRARIES})
+  get_target_property(t ${executable} TYPE)
+  if("${t}" STREQUAL "STATIC_LIBRARY")
+    target_link_libraries(${executable} ${cmake_2_8_12_INTERFACE} ${LIBRARIES})
+  elseif("${t}" STREQUAL "SHARED_LIBRARY" OR "${t}" STREQUAL "MODULE_LIBRARY")
+    target_link_libraries(${executable} ${cmake_2_8_12_PRIVATE} ${LIBRARIES})
+  else()
+    # Use plain form for legacy user.
+    target_link_libraries(${executable} ${LIBRARIES})
+  endif()
 endfunction(explicit_llvm_config)
 
 
 endfunction(explicit_llvm_config)
 
 
index 0b5f623d3a9f5a66b2171d50b5cb2794a8211b4d..a32d238d28779543d8d42ef4e9368dbb87d235aa 100644 (file)
@@ -142,5 +142,5 @@ if( NOT MSVC )
     endif()
   endif( MINGW )
 endif( NOT MSVC )
     endif()
   endif( MINGW )
 endif( NOT MSVC )
-target_link_libraries(LLVMSupport ${system_libs})
+target_link_libraries(LLVMSupport ${cmake_2_8_12_INTERFACE} ${system_libs})
 set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${system_libs}")
 set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${system_libs}")