OSDN Git Service

Simplify linking to system libraries
authorNAKAMURA Takumi <geek4civic@gmail.com>
Sun, 23 Feb 2014 06:27:04 +0000 (06:27 +0000)
committerNAKAMURA Takumi <geek4civic@gmail.com>
Sun, 23 Feb 2014 06:27:04 +0000 (06:27 +0000)
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.

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

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

index af720fc..451fc56 100644 (file)
@@ -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)
 
index 11857a5..2f8d037 100644 (file)
@@ -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@)
 
index 894067d..8f20ddf 100644 (file)
@@ -17,10 +17,6 @@ PROJ_cmake := $(DESTDIR)$(PROJ_prefix)/share/llvm/cmake
 
 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: LLVMConfig.cmake.in $(LLVMBuildCMakeFrag)
          -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: $(LLVMBuildCMakeExportsFrag)
            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))
index 1ba1c76..0b5f623 100644 (file)
@@ -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}")
index e653b77..6f29a82 100644 (file)
@@ -4,7 +4,7 @@ set(BUILDVARIABLES_SRCPATH ${CMAKE_CURRENT_SOURCE_DIR}/BuildVariables.inc.in)
 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()