[llvm] r201969 - Simplify linking to system libraries

NAKAMURA Takumi geek4civic at gmail.com
Sat Feb 22 22:27:04 PST 2014


Author: chapuni
Date: Sun Feb 23 00:27:04 2014
New Revision: 201969

URL: http://llvm.org/viewvc/llvm-project?rev=201969&view=rev
Log:
Simplify linking to system libraries

The LLVMSupport library implementation consolidates all dependencies on
system libraries.  Move the logic gathering system libraries out of
'cmake/modules/LLVM-Config.cmake' and into 'lib/Support/CMakeLists.txt'.
Use the target_link_libraries() command there to tell CMake about the
link dependencies of the LLVMSupport implementation.  CMake will
automatically propagate this to all targets that link LLVMSupport
directly or indirectly.

We still need to build knowledge of system library dependencies into
'llvm-config'.  Store the list of libraries needed in a property on
LLVMSupport and teach 'tools/llvm-config/CMakeLists.txt' to retrieve it
from there.

Drop all calls to 'link_system_libs' and 'get_system_libs' from our
CMake code.  Replace their implementations with a warning that explains
the calls are no longer necessary.  Also drop from 'LLVMConfig.cmake'
the HAVE_* and related variables that were published there only to allow
'get_system_libs' to run outside our build process.

Contributed by Brad King.

Modified:
    llvm/trunk/cmake/modules/LLVM-Config.cmake
    llvm/trunk/cmake/modules/LLVMConfig.cmake.in
    llvm/trunk/cmake/modules/Makefile
    llvm/trunk/lib/Support/CMakeLists.txt
    llvm/trunk/tools/llvm-config/CMakeLists.txt

Modified: llvm/trunk/cmake/modules/LLVM-Config.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/LLVM-Config.cmake?rev=201969&r1=201968&r2=201969&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/LLVM-Config.cmake (original)
+++ llvm/trunk/cmake/modules/LLVM-Config.cmake Sun Feb 23 00:27:04 2014
@@ -1,36 +1,12 @@
 function(get_system_libs return_var)
-  # Returns in `return_var' a list of system libraries used by LLVM.
-  if( NOT MSVC )
-    if( MINGW )
-      set(system_libs ${system_libs} imagehlp psapi shell32)
-    elseif( CMAKE_HOST_UNIX )
-      if( HAVE_LIBRT )
-        set(system_libs ${system_libs} rt)
-      endif()
-      if( HAVE_LIBDL )
-        set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
-      endif()
-      if(LLVM_ENABLE_TERMINFO)
-        if(HAVE_TERMINFO)
-          set(system_libs ${system_libs} ${TERMINFO_LIBS})
-        endif()
-      endif()
-      if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
-        set(system_libs ${system_libs} pthread)
-      endif()
-      if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ )
-        set(system_libs ${system_libs} z)
-      endif()
-    endif( MINGW )
-  endif( NOT MSVC )
-  set(${return_var} ${system_libs} PARENT_SCOPE)
-endfunction(get_system_libs)
+  message(AUTHOR_WARNING "get_system_libs no longer needed")
+  set(${return_var} "" PARENT_SCOPE)
+endfunction()
 
 
 function(link_system_libs target)
-  get_system_libs(llvm_system_libs)
-  target_link_libraries(${target} ${llvm_system_libs})
-endfunction(link_system_libs)
+  message(AUTHOR_WARNING "link_system_libs no longer needed")
+endfunction()
 
 
 function(is_llvm_target_library library return_var)
@@ -70,7 +46,6 @@ endfunction(explicit_llvm_config)
 # This is a variant intended for the final user:
 function(llvm_map_components_to_libraries OUT_VAR)
   explicit_map_components_to_libraries(result ${ARGN})
-  get_system_libs(sys_result)
   set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE )
 endfunction(llvm_map_components_to_libraries)
 

Modified: llvm/trunk/cmake/modules/LLVMConfig.cmake.in
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/LLVMConfig.cmake.in?rev=201969&r1=201968&r2=201969&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/LLVMConfig.cmake.in (original)
+++ llvm/trunk/cmake/modules/LLVMConfig.cmake.in Sun Feb 23 00:27:04 2014
@@ -30,11 +30,6 @@ set(LLVM_NATIVE_ARCH @LLVM_NATIVE_ARCH@)
 
 set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@)
 
-set(HAVE_TERMINFO @HAVE_TERMINFO@)
-set(TERMINFO_LIBS @TERMINFO_LIBS@)
-set(HAVE_LIBDL @HAVE_LIBDL@)
-set(HAVE_LIBPTHREAD @HAVE_LIBPTHREAD@)
-set(HAVE_LIBZ @HAVE_LIBZ@)
 set(LLVM_ON_UNIX @LLVM_ON_UNIX@)
 set(LLVM_ON_WIN32 @LLVM_ON_WIN32@)
 

Modified: llvm/trunk/cmake/modules/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/Makefile?rev=201969&r1=201968&r2=201969&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/Makefile (original)
+++ llvm/trunk/cmake/modules/Makefile Sun Feb 23 00:27:04 2014
@@ -17,10 +17,6 @@ PROJ_cmake := $(DESTDIR)$(PROJ_prefix)/s
 
 OBJMODS := LLVMConfig.cmake LLVMConfigVersion.cmake LLVMExports.cmake
 
-# TODO: Teach LLVM-Config.cmake to work without explicit terminfo libs.
-TERMINFO_LIBS := tinfo terminfo curses ncurses ncursesw
-TERMINFO_LIBS := $(filter $(TERMINFO_LIBS),$(subst -l,,$(LIBS)))
-
 $(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in $(LLVMBuildCMakeFrag)
 	$(Echo) 'Generating LLVM CMake package config file'
 	$(Verb) ( \
@@ -40,11 +36,6 @@ $(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMCo
 	  -e 's/@LLVM_ENABLE_ZLIB@/'"$(ENABLE_ZLIB)"'/' \
 	  -e 's/@LLVM_NATIVE_ARCH@/'"$(LLVM_NATIVE_ARCH)"'/' \
 	  -e 's/@LLVM_ENABLE_PIC@/'"$(ENABLE_PIC)"'/' \
-	  -e 's/@HAVE_TERMINFO@/'"$(HAVE_TERMINFO)"'/' \
-	  -e 's/@TERMINFO_LIBS@/'"$(TERMINFO_LIBS)"'/' \
-	  -e 's/@HAVE_LIBDL@/'"$(HAVE_DLOPEN)"'/' \
-	  -e 's/@HAVE_LIBPTHREAD@/'"$(HAVE_PTHREAD)"'/' \
-	  -e 's/@HAVE_LIBZ@/'"$(HAVE_LIBZ)"'/' \
 	  -e 's/@LLVM_ON_UNIX@/'"$(LLVM_ON_UNIX)"'/' \
 	  -e 's/@LLVM_ON_WIN32@/'"$(LLVM_ON_WIN32)"'/' \
 	  -e 's/@LLVM_CONFIG_INCLUDE_DIRS@/'"$(subst /,\/,$(PROJ_includedir))"'/' \
@@ -70,9 +61,8 @@ $(PROJ_OBJ_DIR)/LLVMExports.cmake: $(LLV
 	    echo 'add_library('"$$lib"' STATIC IMPORTED)' && \
 	    echo 'set_property(TARGET '"$$lib"' PROPERTY IMPORTED_LOCATION "'"$(PROJ_libdir)/lib$$lib.a"'")' ; \
 	  done && \
-	  cat "$(LLVMBuildCMakeExportsFrag)" \
-	  && echo '# System libs depend on LLVMSupport.' \
-	  && echo 'set_property(TARGET LLVMSupport PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES $(patsubst -l%,%,$(LIBS)))' \
+	  cat "$(LLVMBuildCMakeExportsFrag)" && \
+	  echo 'set_property(TARGET LLVMSupport APPEND PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES '"$(subst -l,,$(LIBS))"')' \
 	) | grep -v gtest > $@
 
 all-local:: $(addprefix $(PROJ_OBJ_DIR)/, $(OBJMODS))

Modified: llvm/trunk/lib/Support/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CMakeLists.txt?rev=201969&r1=201968&r2=201969&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CMakeLists.txt (original)
+++ llvm/trunk/lib/Support/CMakeLists.txt Sun Feb 23 00:27:04 2014
@@ -118,5 +118,29 @@ add_llvm_library(LLVMSupport
   Windows/TimeValue.inc
   Windows/Watchdog.inc
   )
-
-link_system_libs(LLVMSupport)
+set(system_libs)
+if( NOT MSVC )
+  if( MINGW )
+    set(system_libs ${system_libs} imagehlp psapi shell32)
+  elseif( CMAKE_HOST_UNIX )
+    if( HAVE_LIBRT )
+      set(system_libs ${system_libs} rt)
+    endif()
+    if( HAVE_LIBDL )
+      set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
+    endif()
+    if(LLVM_ENABLE_TERMINFO)
+      if(HAVE_TERMINFO)
+        set(system_libs ${system_libs} ${TERMINFO_LIBS})
+      endif()
+    endif()
+    if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
+      set(system_libs ${system_libs} pthread)
+    endif()
+    if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ )
+      set(system_libs ${system_libs} z)
+    endif()
+  endif( MINGW )
+endif( NOT MSVC )
+target_link_libraries(LLVMSupport ${system_libs})
+set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${system_libs}")

Modified: llvm/trunk/tools/llvm-config/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/CMakeLists.txt?rev=201969&r1=201968&r2=201969&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-config/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-config/CMakeLists.txt Sun Feb 23 00:27:04 2014
@@ -4,7 +4,7 @@ set(BUILDVARIABLES_SRCPATH ${CMAKE_CURRE
 set(BUILDVARIABLES_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.inc)
 
 # Compute the substitution values for various items.
-get_system_libs(LLVM_SYSTEM_LIBS_LIST)
+get_property(LLVM_SYSTEM_LIBS_LIST TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS)
 foreach(l ${LLVM_SYSTEM_LIBS_LIST})
   set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
 endforeach()





More information about the llvm-commits mailing list