llvm.org GIT mirror llvm / 043cc54
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 NAKAMURA Takumi 5 years ago
5 changed file(s) with 34 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
0 function(get_system_libs return_var)
1 # Returns in `return_var' a list of system libraries used by LLVM.
2 if( NOT MSVC )
3 if( MINGW )
4 set(system_libs ${system_libs} imagehlp psapi shell32)
5 elseif( CMAKE_HOST_UNIX )
6 if( HAVE_LIBRT )
7 set(system_libs ${system_libs} rt)
8 endif()
9 if( HAVE_LIBDL )
10 set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
11 endif()
12 if(LLVM_ENABLE_TERMINFO)
13 if(HAVE_TERMINFO)
14 set(system_libs ${system_libs} ${TERMINFO_LIBS})
15 endif()
16 endif()
17 if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
18 set(system_libs ${system_libs} pthread)
19 endif()
20 if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ )
21 set(system_libs ${system_libs} z)
22 endif()
23 endif( MINGW )
24 endif( NOT MSVC )
25 set(${return_var} ${system_libs} PARENT_SCOPE)
26 endfunction(get_system_libs)
1 message(AUTHOR_WARNING "get_system_libs no longer needed")
2 set(${return_var} "" PARENT_SCOPE)
3 endfunction()
274
285
296 function(link_system_libs target)
30 get_system_libs(llvm_system_libs)
31 target_link_libraries(${target} ${llvm_system_libs})
32 endfunction(link_system_libs)
7 message(AUTHOR_WARNING "link_system_libs no longer needed")
8 endfunction()
339
3410
3511 function(is_llvm_target_library library return_var)
6945 # This is a variant intended for the final user:
7046 function(llvm_map_components_to_libraries OUT_VAR)
7147 explicit_map_components_to_libraries(result ${ARGN})
72 get_system_libs(sys_result)
7348 set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE )
7449 endfunction(llvm_map_components_to_libraries)
7550
2929
3030 set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@)
3131
32 set(HAVE_TERMINFO @HAVE_TERMINFO@)
33 set(TERMINFO_LIBS @TERMINFO_LIBS@)
34 set(HAVE_LIBDL @HAVE_LIBDL@)
35 set(HAVE_LIBPTHREAD @HAVE_LIBPTHREAD@)
36 set(HAVE_LIBZ @HAVE_LIBZ@)
3732 set(LLVM_ON_UNIX @LLVM_ON_UNIX@)
3833 set(LLVM_ON_WIN32 @LLVM_ON_WIN32@)
3934
1515 PROJ_cmake := $(DESTDIR)$(PROJ_prefix)/share/llvm/cmake
1616
1717 OBJMODS := LLVMConfig.cmake LLVMConfigVersion.cmake LLVMExports.cmake
18
19 # TODO: Teach LLVM-Config.cmake to work without explicit terminfo libs.
20 TERMINFO_LIBS := tinfo terminfo curses ncurses ncursesw
21 TERMINFO_LIBS := $(filter $(TERMINFO_LIBS),$(subst -l,,$(LIBS)))
2218
2319 $(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in $(LLVMBuildCMakeFrag)
2420 $(Echo) 'Generating LLVM CMake package config file'
3935 -e 's/@LLVM_ENABLE_ZLIB@/'"$(ENABLE_ZLIB)"'/' \
4036 -e 's/@LLVM_NATIVE_ARCH@/'"$(LLVM_NATIVE_ARCH)"'/' \
4137 -e 's/@LLVM_ENABLE_PIC@/'"$(ENABLE_PIC)"'/' \
42 -e 's/@HAVE_TERMINFO@/'"$(HAVE_TERMINFO)"'/' \
43 -e 's/@TERMINFO_LIBS@/'"$(TERMINFO_LIBS)"'/' \
44 -e 's/@HAVE_LIBDL@/'"$(HAVE_DLOPEN)"'/' \
45 -e 's/@HAVE_LIBPTHREAD@/'"$(HAVE_PTHREAD)"'/' \
46 -e 's/@HAVE_LIBZ@/'"$(HAVE_LIBZ)"'/' \
4738 -e 's/@LLVM_ON_UNIX@/'"$(LLVM_ON_UNIX)"'/' \
4839 -e 's/@LLVM_ON_WIN32@/'"$(LLVM_ON_WIN32)"'/' \
4940 -e 's/@LLVM_CONFIG_INCLUDE_DIRS@/'"$(subst /,\/,$(PROJ_includedir))"'/' \
6960 echo 'add_library('"$$lib"' STATIC IMPORTED)' && \
7061 echo 'set_property(TARGET '"$$lib"' PROPERTY IMPORTED_LOCATION "'"$(PROJ_libdir)/lib$$lib.a"'")' ; \
7162 done && \
72 cat "$(LLVMBuildCMakeExportsFrag)" \
73 && echo '# System libs depend on LLVMSupport.' \
74 && echo 'set_property(TARGET LLVMSupport PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES $(patsubst -l%,%,$(LIBS)))' \
63 cat "$(LLVMBuildCMakeExportsFrag)" && \
64 echo 'set_property(TARGET LLVMSupport APPEND PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES '"$(subst -l,,$(LIBS))"')' \
7565 ) | grep -v gtest > $@
7666
7767 all-local:: $(addprefix $(PROJ_OBJ_DIR)/, $(OBJMODS))
117117 Windows/TimeValue.inc
118118 Windows/Watchdog.inc
119119 )
120
121 link_system_libs(LLVMSupport)
120 set(system_libs)
121 if( NOT MSVC )
122 if( MINGW )
123 set(system_libs ${system_libs} imagehlp psapi shell32)
124 elseif( CMAKE_HOST_UNIX )
125 if( HAVE_LIBRT )
126 set(system_libs ${system_libs} rt)
127 endif()
128 if( HAVE_LIBDL )
129 set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
130 endif()
131 if(LLVM_ENABLE_TERMINFO)
132 if(HAVE_TERMINFO)
133 set(system_libs ${system_libs} ${TERMINFO_LIBS})
134 endif()
135 endif()
136 if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
137 set(system_libs ${system_libs} pthread)
138 endif()
139 if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ )
140 set(system_libs ${system_libs} z)
141 endif()
142 endif( MINGW )
143 endif( NOT MSVC )
144 target_link_libraries(LLVMSupport ${system_libs})
145 set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${system_libs}")
33 set(BUILDVARIABLES_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.inc)
44
55 # Compute the substitution values for various items.
6 get_system_libs(LLVM_SYSTEM_LIBS_LIST)
6 get_property(LLVM_SYSTEM_LIBS_LIST TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS)
77 foreach(l ${LLVM_SYSTEM_LIBS_LIST})
88 set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
99 endforeach()