diff options
author | Vladislav Vaintroub <vvaintroub@koala> | 2009-12-07 02:16:05 +0100 |
---|---|---|
committer | Vladislav Vaintroub <vvaintroub@koala> | 2009-12-07 02:16:05 +0100 |
commit | 9fcef3c45bd936b7da20679a1bb160c22f4945ff (patch) | |
tree | be34c035a12551aff48f3bcdb4fcbf4754f8b3f0 /cmake/libutils.cmake | |
parent | 2e6270311467f557a424a15b03d8d52c5b0ea92d (diff) | |
download | mariadb-git-9fcef3c45bd936b7da20679a1bb160c22f4945ff.tar.gz |
On Linux, support -Wl,--no-undefined (only client shared library)
and --Wl,--as-needed (all shared modules). The later will remove
unused dependencies (also from gcc and C++ runtime)
Diffstat (limited to 'cmake/libutils.cmake')
-rw-r--r-- | cmake/libutils.cmake | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/cmake/libutils.cmake b/cmake/libutils.cmake index dc151bc12f2..8f2b66f73c3 100644 --- a/cmake/libutils.cmake +++ b/cmake/libutils.cmake @@ -132,25 +132,31 @@ MACRO(MERGE_STATIC_LIBS TARGET OUTPUT_NAME LIBS_TO_MERGE) ADD_LIBRARY(${TARGET} STATIC ${SOURCE_FILE}) SET_TARGET_PROPERTIES(${TARGET} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME}) + SET(OSLIBS) FOREACH(LIB ${LIBS_TO_MERGE}) GET_TARGET_PROPERTY(LIB_LOCATION ${LIB} LOCATION) GET_TARGET_PROPERTY(LIB_TYPE ${LIB} TYPE) IF(NOT LIB_LOCATION) # 3rd party library like libz.so. Make sure that everything # that links to our library links to this one as well. - TARGET_LINK_LIBRARIES(${TARGET} ${LIB}) + LIST(APPEND OSLIBS ${LIB}) ELSE() # This is a target in current project # (can be a static or shared lib) IF(LIB_TYPE STREQUAL "STATIC_LIBRARY") SET(STATIC_LIBS ${STATIC_LIBS} ${LIB_LOCATION}) ADD_DEPENDENCIES(${TARGET} ${LIB}) + # Extract dependend OS libraries + GET_DEPENDEND_OS_LIBS(${LIB} LIB_OSLIBS) + LIST(APPEND OSLIBS ${LIB_OSLIBS}) ELSE() # This is a shared library our static lib depends on. - TARGET_LINK_LIBRARIES(${TARGET} ${LIB}) + LIST(APPEND OSLIBS ${LIB}) ENDIF() ENDIF() ENDFOREACH() + LIST(REMOVE_DUPLICATES OSLIBS) + TARGET_LINK_LIBRARIES(${TARGET} ${OSLIBS}) # Make the generated dummy source file depended on all static input # libs. If input lib changes,the source file is touched @@ -249,16 +255,27 @@ MACRO(MERGE_LIBRARIES) IF(ARG_OUTPUT_NAME) SET_TARGET_PROPERTIES(${TARGET} PROPERTIES OUTPUT_NAME "${ARG_OUTPUT_NAME}") ENDIF() - # Disallow undefined symbols in shared libraries, but allow for modules - # (they export from loading executable) - IF(LIBTYPE MATCHES "SHARED" AND CMAKE_SYSTEM_TYPE MATCHES "Linux") - SET_TARGET_PROPERTIES(${TARGET} PROPERTIES LINK_FLAGS "-Wl,--no-undefined") - ENDIF() ELSE() MESSAGE(FATAL_ERROR "Unknown library type") ENDIF() ENDMACRO() +FUNCTION(GET_DEPENDEND_OS_LIBS target result) + SET(deps ${${target}_LIB_DEPENDS}) + IF(deps) + FOREACH(lib ${deps}) + # Filter out keywords for used for debug vs optimized builds + IF(NOT lib MATCHES "general" AND NOT lib MATCHES "debug" AND NOT lib MATCHES "optimized") + GET_TARGET_PROPERTY(lib_location ${lib} LOCATION) + IF(NOT lib_location) + SET(ret ${ret} ${lib}) + ENDIF() + ENDIF() + ENDFOREACH() + ENDIF() + SET(${result} ${ret} PARENT_SCOPE) +ENDFUNCTION() + MACRO(RESTRICT_SYMBOL_EXPORTS target) IF(CMAKE_COMPILER_IS_GNUCXX AND UNIX) GET_TARGET_PROPERTY(COMPILE_FLAGS ${target} COMPILE_FLAGS) |