Commit b44c5e4d authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

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)
parent 171f50af
...@@ -132,25 +132,31 @@ MACRO(MERGE_STATIC_LIBS TARGET OUTPUT_NAME LIBS_TO_MERGE) ...@@ -132,25 +132,31 @@ MACRO(MERGE_STATIC_LIBS TARGET OUTPUT_NAME LIBS_TO_MERGE)
ADD_LIBRARY(${TARGET} STATIC ${SOURCE_FILE}) ADD_LIBRARY(${TARGET} STATIC ${SOURCE_FILE})
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME}) SET_TARGET_PROPERTIES(${TARGET} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME})
SET(OSLIBS)
FOREACH(LIB ${LIBS_TO_MERGE}) FOREACH(LIB ${LIBS_TO_MERGE})
GET_TARGET_PROPERTY(LIB_LOCATION ${LIB} LOCATION) GET_TARGET_PROPERTY(LIB_LOCATION ${LIB} LOCATION)
GET_TARGET_PROPERTY(LIB_TYPE ${LIB} TYPE) GET_TARGET_PROPERTY(LIB_TYPE ${LIB} TYPE)
IF(NOT LIB_LOCATION) IF(NOT LIB_LOCATION)
# 3rd party library like libz.so. Make sure that everything # 3rd party library like libz.so. Make sure that everything
# that links to our library links to this one as well. # that links to our library links to this one as well.
TARGET_LINK_LIBRARIES(${TARGET} ${LIB}) LIST(APPEND OSLIBS ${LIB})
ELSE() ELSE()
# This is a target in current project # This is a target in current project
# (can be a static or shared lib) # (can be a static or shared lib)
IF(LIB_TYPE STREQUAL "STATIC_LIBRARY") IF(LIB_TYPE STREQUAL "STATIC_LIBRARY")
SET(STATIC_LIBS ${STATIC_LIBS} ${LIB_LOCATION}) SET(STATIC_LIBS ${STATIC_LIBS} ${LIB_LOCATION})
ADD_DEPENDENCIES(${TARGET} ${LIB}) ADD_DEPENDENCIES(${TARGET} ${LIB})
# Extract dependend OS libraries
GET_DEPENDEND_OS_LIBS(${LIB} LIB_OSLIBS)
LIST(APPEND OSLIBS ${LIB_OSLIBS})
ELSE() ELSE()
# This is a shared library our static lib depends on. # This is a shared library our static lib depends on.
TARGET_LINK_LIBRARIES(${TARGET} ${LIB}) LIST(APPEND OSLIBS ${LIB})
ENDIF() ENDIF()
ENDIF() ENDIF()
ENDFOREACH() ENDFOREACH()
LIST(REMOVE_DUPLICATES OSLIBS)
TARGET_LINK_LIBRARIES(${TARGET} ${OSLIBS})
# Make the generated dummy source file depended on all static input # Make the generated dummy source file depended on all static input
# libs. If input lib changes,the source file is touched # libs. If input lib changes,the source file is touched
...@@ -249,16 +255,27 @@ MACRO(MERGE_LIBRARIES) ...@@ -249,16 +255,27 @@ MACRO(MERGE_LIBRARIES)
IF(ARG_OUTPUT_NAME) IF(ARG_OUTPUT_NAME)
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES OUTPUT_NAME "${ARG_OUTPUT_NAME}") SET_TARGET_PROPERTIES(${TARGET} PROPERTIES OUTPUT_NAME "${ARG_OUTPUT_NAME}")
ENDIF() 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() ELSE()
MESSAGE(FATAL_ERROR "Unknown library type") MESSAGE(FATAL_ERROR "Unknown library type")
ENDIF() ENDIF()
ENDMACRO() 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) MACRO(RESTRICT_SYMBOL_EXPORTS target)
IF(CMAKE_COMPILER_IS_GNUCXX AND UNIX) IF(CMAKE_COMPILER_IS_GNUCXX AND UNIX)
GET_TARGET_PROPERTY(COMPILE_FLAGS ${target} COMPILE_FLAGS) GET_TARGET_PROPERTY(COMPILE_FLAGS ${target} COMPILE_FLAGS)
......
...@@ -125,7 +125,11 @@ MACRO(MYSQL_ADD_PLUGIN) ...@@ -125,7 +125,11 @@ MACRO(MYSQL_ADD_PLUGIN)
DTRACE_INSTRUMENT(${target}) DTRACE_INSTRUMENT(${target})
SET_TARGET_PROPERTIES (${target} PROPERTIES PREFIX "" SET_TARGET_PROPERTIES (${target} PROPERTIES PREFIX ""
COMPILE_DEFINITIONS "MYSQL_DYNAMIC_PLUGIN") COMPILE_DEFINITIONS "MYSQL_DYNAMIC_PLUGIN")
IF(ARG_LINK_LIBRARIES)
TARGET_LINK_LIBRARIES (${target} ${ARG_LINK_LIBRARIES})
ENDIF()
TARGET_LINK_LIBRARIES (${target} mysqlservices) TARGET_LINK_LIBRARIES (${target} mysqlservices)
# Plugin uses symbols defined in mysqld executable. # Plugin uses symbols defined in mysqld executable.
# Some operating systems like Windows and OSX and are pretty strict about # Some operating systems like Windows and OSX and are pretty strict about
# unresolved symbols. Others are less strict and allow unresolved symbols # unresolved symbols. Others are less strict and allow unresolved symbols
......
...@@ -94,9 +94,6 @@ IF(CMAKE_COMPILER_IS_GNUCXX) ...@@ -94,9 +94,6 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
ENDIF() ENDIF()
ENDIF(CMAKE_COMPILER_IS_GNUCXX) ENDIF(CMAKE_COMPILER_IS_GNUCXX)
IF(WIN32)
SET(CAN_CONVERT_STATIC_TO_SHARED_LIB 1)
ENDIF()
# Large files # Large files
SET(_LARGEFILE_SOURCE 1) SET(_LARGEFILE_SOURCE 1)
...@@ -134,13 +131,9 @@ IF(CMAKE_GENERATOR MATCHES "Visual Studio 7") ...@@ -134,13 +131,9 @@ IF(CMAKE_GENERATOR MATCHES "Visual Studio 7")
# VS2003 needs the /Op compiler option to disable floating point # VS2003 needs the /Op compiler option to disable floating point
# optimizations # optimizations
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Op") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Op")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Op") SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /Op")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Op") ENDIF()
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Op")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Op")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /Op")
ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio 7")
IF(CMAKE_SYSTEM_NAME STREQUAL "HP-UX" ) IF(CMAKE_SYSTEM_NAME STREQUAL "HP-UX" )
...@@ -148,7 +141,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "HP-UX" ) ...@@ -148,7 +141,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "HP-UX" )
# HPUX linker crashes building plugins # HPUX linker crashes building plugins
SET(WITHOUT_DYNAMIC_PLUGINS TRUE) SET(WITHOUT_DYNAMIC_PLUGINS TRUE)
ENDIF() ENDIF()
# If not PA-RISC make shared library suffix .so # If Itanium make shared library suffix .so
# OS understands both .sl and .so. CMake would # OS understands both .sl and .so. CMake would
# use .sl, however MySQL prefers .so # use .sl, however MySQL prefers .so
IF(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "9000") IF(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "9000")
...@@ -157,6 +150,24 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "HP-UX" ) ...@@ -157,6 +150,24 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "HP-UX" )
ENDIF() ENDIF()
ENDIF() ENDIF()
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# Ensure we have clean build for shared libraries
# without extra dependencies and without unresolved symbols
FOREACH(LANG C CXX)
STRING(REPLACE "-rdynamic" ""
CMAKE_SHARED_LIBRARY_LINK_${LANG}_FLAGS
${CMAKE_SHARED_LIBRARY_LINK_${LANG}_FLAGS}
)
ENDFOREACH()
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
SET(LINK_FLAG_NO_UNDEFINED "--Wl,--no-undefined")
ENDIF()
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
SET(LINK_FLAG_NO_UNDEFINED "-z defs")
ENDIF()
#Some OS specific hacks #Some OS specific hacks
IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
ADD_DEFINITIONS(-DNET_RETRY_COUNT=1000000) ADD_DEFINITIONS(-DNET_RETRY_COUNT=1000000)
...@@ -244,48 +255,41 @@ IF(WIN32) ...@@ -244,48 +255,41 @@ IF(WIN32)
LINK_LIBRARIES(ws2_32) LINK_LIBRARIES(ws2_32)
ENDIF() ENDIF()
# Searches function in libraries
# if function is found, sets output parameter result to the name of the library
MACRO(MY_CHECK_LIB func lib found) # if function is found in libc, result will be empty
SET(${found} 0) FUNCTION(MY_SEARCH_LIBS func libs result)
CHECK_FUNCTION_EXISTS(${func} HAVE_${func}_IN_LIBC) CHECK_FUNCTION_EXISTS(${func} HAVE_${func}_IN_LIBC)
CHECK_LIBRARY_EXISTS(${lib} ${func} "" HAVE_${func}_IN_${lib}) IF(HAVE_${func}_IN_LIBC)
IF (HAVE_${func}_IN_${lib}) SET(${result} "" PARENT_SCOPE)
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${lib}) RETURN()
LINK_LIBRARIES(${lib})
STRING(TOUPPER ${lib} upper_lib)
SET(HAVE_LIB${upper_lib} 1 CACHE INTERNAL "Library check")
SET(${found} 1)
ENDIF() ENDIF()
ENDMACRO() FOREACH(lib ${libs})
CHECK_LIBRARY_EXISTS(${lib} ${func} "" HAVE_${func}_IN_${lib})
MACRO(MY_SEARCH_LIBS func lib found) IF(HAVE_${func}_IN_${lib})
SET(${found} 0) SET(${result} ${lib} PARENT_SCOPE)
CHECK_FUNCTION_EXISTS(${func} HAVE_${func}_IN_LIBC) ENDIF()
IF(NOT HAVE_${func}_IN_LIBC) RETURN()
MY_CHECK_LIB(${func} ${lib} ${found}) ENDFOREACH()
ELSE() ENDFUNCTION()
SET(${found} 1)
ENDIF()
ENDMACRO()
IF(UNIX) IF(UNIX)
MY_CHECK_LIB(floor m found) MY_SEARCH_LIBS(floor m LIBM)
IF(NOT found) IF(NOT LIBM)
MY_CHECK_LIB( __infinity m found) MY_SEARCH_LIBS(__infinity m LIBM)
ENDIF()
MY_CHECK_LIB(gethostbyname_r nsl_r found)
IF (NOT found)
MY_CHECK_LIB(gethostbyname_r nsl found)
ENDIF() ENDIF()
MY_SEARCH_LIBS(bind bind found) MY_SEARCH_LIBS(gethostbyname_r "nsl_r;nsl" LIBNLS)
MY_SEARCH_LIBS(crypt crypt found) MY_SEARCH_LIBS(bind bind LIBBIND)
MY_SEARCH_LIBS(setsockopt socket found) MY_SEARCH_LIBS(crypt crypt LIBCRYPT)
MY_SEARCH_LIBS(aio_read rt found) MY_SEARCH_LIBS(setsockopt socket LIBSOCKET)
MY_SEARCH_LIBS(sched_yield posix4 found) MY_SEARCH_LIBS(dlopen dl LIBDL)
MY_CHECK_LIB(pthread_create pthread found) FIND_PACKAGE(Threads)
MY_SEARCH_LIBS(dlopen dl found)
SET(CMAKE_REQUIRED_LIBRARIES
${LIBNLS} ${LIBBIND} ${LIBCRYPT} ${LIBSOCKET} ${LIBDL} ${CMAKE_THREAD_LIBS_INIT})
LINK_LIBRARIES(${CMAKE_THREAD_LIBS_INIT})
OPTION(WITH_LIBWRAP "Compile with tcp wrappers support" OFF) OPTION(WITH_LIBWRAP "Compile with tcp wrappers support" OFF)
IF(WITH_LIBWRAP) IF(WITH_LIBWRAP)
SET(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) SET(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
...@@ -303,7 +307,7 @@ IF(UNIX) ...@@ -303,7 +307,7 @@ IF(UNIX)
SET(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES}) SET(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES})
IF(HAVE_LIBWRAP) IF(HAVE_LIBWRAP)
SET(MYSYS_LIBWRAP_SOURCE ${CMAKE_SOURCE_DIR}/mysys/my_libwrap.c) SET(MYSYS_LIBWRAP_SOURCE ${CMAKE_SOURCE_DIR}/mysys/my_libwrap.c)
SET(LIBWRAP_LIBRARY "wrap") SET(LIBWRAP "wrap")
ENDIF() ENDIF()
ENDIF() ENDIF()
ENDIF() ENDIF()
......
...@@ -167,7 +167,14 @@ IF(NOT DISABLE_SHARED) ...@@ -167,7 +167,14 @@ IF(NOT DISABLE_SHARED)
OUTPUT_NAME mysqlclient OUTPUT_NAME mysqlclient
VERSION "${SHARED_LIB_MAJOR_VERSION}.0.0" VERSION "${SHARED_LIB_MAJOR_VERSION}.0.0"
SOVERSION "${SHARED_LIB_MAJOR_VERSION}") SOVERSION "${SHARED_LIB_MAJOR_VERSION}")
IF(LINK_FLAG_NO_UNDEFINED)
GET_TARGET_PROPERTY(libmysql_link_flags libmysql LINK_FLAGS)
IF(NOT libmysql_link_flag)
SET(libmysql_link_flags)
ENDIF()
SET_TARGET_PROPERTIES(libmysql PROPERTIES LINK_FLAGS
"${libmysql_link_flags} ${LINK_FLAG_NO_UNDEFINED}")
ENDIF()
# clean direct output needs to be set several targets have the same name # clean direct output needs to be set several targets have the same name
#(mysqlclient in this case) #(mysqlclient in this case)
SET_TARGET_PROPERTIES(mysqlclient PROPERTIES CLEAN_DIRECT_OUTPUT 1) SET_TARGET_PROPERTIES(mysqlclient PROPERTIES CLEAN_DIRECT_OUTPUT 1)
......
...@@ -100,7 +100,8 @@ ENDIF() ...@@ -100,7 +100,8 @@ ENDIF()
SET(LIBS SET(LIBS
dbug strings regex mysys vio dbug strings regex mysys vio
${ZLIB_LIBRARY} ${SSL_LIBRARIES} ${LIBWRAP_LIBRARY} ${ZLIB_LIBRARY} ${SSL_LIBRARIES}
${LIBWRAP} ${LIBCRYPT} ${LIBDL}
${MYSQLD_STATIC_PLUGIN_LIBS} ${NDB_CLIENT_LIBS} ${MYSQLD_STATIC_PLUGIN_LIBS} ${NDB_CLIENT_LIBS}
sql_embedded sql_embedded
) )
......
...@@ -63,5 +63,6 @@ IF(UNIX) ...@@ -63,5 +63,6 @@ IF(UNIX)
SET(MYSYS_SOURCES ${MYSYS_SOURCES} my_port.c) SET(MYSYS_SOURCES ${MYSYS_SOURCES} my_port.c)
ENDIF() ENDIF()
ADD_CONVENIENCE_LIBRARY(mysys ${MYSYS_SOURCES}) ADD_CONVENIENCE_LIBRARY(mysys ${MYSYS_SOURCES})
TARGET_LINK_LIBRARIES(mysys dbug strings ${ZLIB_LIBRARY}) TARGET_LINK_LIBRARIES(mysys dbug strings ${ZLIB_LIBRARY}
${LIBNLS} ${LIBM})
DTRACE_INSTRUMENT(mysys) DTRACE_INSTRUMENT(mysys)
...@@ -130,7 +130,8 @@ SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE) ...@@ -130,7 +130,8 @@ SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE)
SET_TARGET_PROPERTIES(mysqld PROPERTIES OUTPUT_NAME mysqld${MYSQLD_EXE_SUFFIX}) SET_TARGET_PROPERTIES(mysqld PROPERTIES OUTPUT_NAME mysqld${MYSQLD_EXE_SUFFIX})
TARGET_LINK_LIBRARIES(mysqld ${MYSQLD_STATIC_PLUGIN_LIBS} TARGET_LINK_LIBRARIES(mysqld ${MYSQLD_STATIC_PLUGIN_LIBS}
mysys dbug strings vio regex ${SQL_LIB} mysys dbug strings vio regex ${SQL_LIB}
${LIBWRAP_LIBRARY} ${ZLIB_LIBRARY} ${SSL_LIBRARIES}) ${LIBWRAP} ${LIBCRYPT} ${LIBDL}
${ZLIB_LIBRARY} ${SSL_LIBRARIES})
INSTALL(TARGETS mysqld DESTINATION bin) INSTALL(TARGETS mysqld DESTINATION bin)
INSTALL_DEBUG_SYMBOLS(mysqld) INSTALL_DEBUG_SYMBOLS(mysqld)
......
...@@ -20,3 +20,4 @@ ADD_DEFINITIONS(${SSL_DEFINES}) ...@@ -20,3 +20,4 @@ ADD_DEFINITIONS(${SSL_DEFINES})
SET(VIO_SOURCES vio.c viosocket.c viossl.c viosslfactories.c) SET(VIO_SOURCES vio.c viosocket.c viossl.c viosslfactories.c)
ADD_CONVENIENCE_LIBRARY(vio ${VIO_SOURCES}) ADD_CONVENIENCE_LIBRARY(vio ${VIO_SOURCES})
TARGET_LINK_LIBRARIES(vio ${LIBSOCKET})
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment