From 043cc54d6c9dedaa6e5316fe5be02f97f16d5d2b Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 23 Feb 2014 06:27:04 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201969 91177308-0d34-0410-b5e6-96231b3b80d8 --- cmake/modules/LLVM-Config.cmake | 35 +++++------------------------------ cmake/modules/LLVMConfig.cmake.in | 5 ----- cmake/modules/Makefile | 14 ++------------ 3 files changed, 7 insertions(+), 47 deletions(-) (limited to 'cmake') diff --git a/cmake/modules/LLVM-Config.cmake b/cmake/modules/LLVM-Config.cmake index af720fcb21..451fc56c6b 100644 --- a/cmake/modules/LLVM-Config.cmake +++ b/cmake/modules/LLVM-Config.cmake @@ -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) diff --git a/cmake/modules/LLVMConfig.cmake.in b/cmake/modules/LLVMConfig.cmake.in index 11857a5384..2f8d037af1 100644 --- a/cmake/modules/LLVMConfig.cmake.in +++ b/cmake/modules/LLVMConfig.cmake.in @@ -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@) diff --git a/cmake/modules/Makefile b/cmake/modules/Makefile index 894067d6f5..8f20ddf4dc 100644 --- a/cmake/modules/Makefile +++ b/cmake/modules/Makefile @@ -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)) -- cgit v1.2.3