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)
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)
......
......@@ -125,7 +125,11 @@ MACRO(MYSQL_ADD_PLUGIN)
DTRACE_INSTRUMENT(${target})
SET_TARGET_PROPERTIES (${target} PROPERTIES PREFIX ""
COMPILE_DEFINITIONS "MYSQL_DYNAMIC_PLUGIN")
IF(ARG_LINK_LIBRARIES)
TARGET_LINK_LIBRARIES (${target} ${ARG_LINK_LIBRARIES})
ENDIF()
TARGET_LINK_LIBRARIES (${target} mysqlservices)
# Plugin uses symbols defined in mysqld executable.
# Some operating systems like Windows and OSX and are pretty strict about
# unresolved symbols. Others are less strict and allow unresolved symbols
......
......@@ -94,9 +94,6 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
ENDIF()
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
IF(WIN32)
SET(CAN_CONVERT_STATIC_TO_SHARED_LIB 1)
ENDIF()
# Large files
SET(_LARGEFILE_SOURCE 1)
......@@ -134,13 +131,9 @@ IF(CMAKE_GENERATOR MATCHES "Visual Studio 7")
# VS2003 needs the /Op compiler option to disable floating point
# optimizations
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Op")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Op")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Op")
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")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Op")
SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /Op")
ENDIF()
IF(CMAKE_SYSTEM_NAME STREQUAL "HP-UX" )
......@@ -148,7 +141,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "HP-UX" )
# HPUX linker crashes building plugins
SET(WITHOUT_DYNAMIC_PLUGINS TRUE)
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
# use .sl, however MySQL prefers .so
IF(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "9000")
......@@ -157,6 +150,24 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "HP-UX" )
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
IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
ADD_DEFINITIONS(-DNET_RETRY_COUNT=1000000)
......@@ -244,47 +255,40 @@ IF(WIN32)
LINK_LIBRARIES(ws2_32)
ENDIF()
MACRO(MY_CHECK_LIB func lib found)
SET(${found} 0)
# Searches function in libraries
# if function is found, sets output parameter result to the name of the library
# if function is found in libc, result will be empty
FUNCTION(MY_SEARCH_LIBS func libs result)
CHECK_FUNCTION_EXISTS(${func} HAVE_${func}_IN_LIBC)
CHECK_LIBRARY_EXISTS(${lib} ${func} "" HAVE_${func}_IN_${lib})
IF (HAVE_${func}_IN_${lib})
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${lib})
LINK_LIBRARIES(${lib})
STRING(TOUPPER ${lib} upper_lib)
SET(HAVE_LIB${upper_lib} 1 CACHE INTERNAL "Library check")
SET(${found} 1)
IF(HAVE_${func}_IN_LIBC)
SET(${result} "" PARENT_SCOPE)
RETURN()
ENDIF()
ENDMACRO()
MACRO(MY_SEARCH_LIBS func lib found)
SET(${found} 0)
CHECK_FUNCTION_EXISTS(${func} HAVE_${func}_IN_LIBC)
IF(NOT HAVE_${func}_IN_LIBC)
MY_CHECK_LIB(${func} ${lib} ${found})
ELSE()
SET(${found} 1)
FOREACH(lib ${libs})
CHECK_LIBRARY_EXISTS(${lib} ${func} "" HAVE_${func}_IN_${lib})
IF(HAVE_${func}_IN_${lib})
SET(${result} ${lib} PARENT_SCOPE)
ENDIF()
ENDMACRO()
RETURN()
ENDFOREACH()
ENDFUNCTION()
IF(UNIX)
MY_CHECK_LIB(floor m found)
IF(NOT found)
MY_CHECK_LIB( __infinity m found)
ENDIF()
MY_CHECK_LIB(gethostbyname_r nsl_r found)
IF (NOT found)
MY_CHECK_LIB(gethostbyname_r nsl found)
MY_SEARCH_LIBS(floor m LIBM)
IF(NOT LIBM)
MY_SEARCH_LIBS(__infinity m LIBM)
ENDIF()
MY_SEARCH_LIBS(bind bind found)
MY_SEARCH_LIBS(crypt crypt found)
MY_SEARCH_LIBS(setsockopt socket found)
MY_SEARCH_LIBS(aio_read rt found)
MY_SEARCH_LIBS(sched_yield posix4 found)
MY_CHECK_LIB(pthread_create pthread found)
MY_SEARCH_LIBS(dlopen dl found)
MY_SEARCH_LIBS(gethostbyname_r "nsl_r;nsl" LIBNLS)
MY_SEARCH_LIBS(bind bind LIBBIND)
MY_SEARCH_LIBS(crypt crypt LIBCRYPT)
MY_SEARCH_LIBS(setsockopt socket LIBSOCKET)
MY_SEARCH_LIBS(dlopen dl LIBDL)
FIND_PACKAGE(Threads)
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)
IF(WITH_LIBWRAP)
......@@ -303,7 +307,7 @@ IF(UNIX)
SET(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES})
IF(HAVE_LIBWRAP)
SET(MYSYS_LIBWRAP_SOURCE ${CMAKE_SOURCE_DIR}/mysys/my_libwrap.c)
SET(LIBWRAP_LIBRARY "wrap")
SET(LIBWRAP "wrap")
ENDIF()
ENDIF()
ENDIF()
......
......@@ -167,7 +167,14 @@ IF(NOT DISABLE_SHARED)
OUTPUT_NAME mysqlclient
VERSION "${SHARED_LIB_MAJOR_VERSION}.0.0"
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
#(mysqlclient in this case)
SET_TARGET_PROPERTIES(mysqlclient PROPERTIES CLEAN_DIRECT_OUTPUT 1)
......
......@@ -100,7 +100,8 @@ ENDIF()
SET(LIBS
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}
sql_embedded
)
......
......@@ -63,5 +63,6 @@ IF(UNIX)
SET(MYSYS_SOURCES ${MYSYS_SOURCES} my_port.c)
ENDIF()
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)
......@@ -130,7 +130,8 @@ SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE)
SET_TARGET_PROPERTIES(mysqld PROPERTIES OUTPUT_NAME mysqld${MYSQLD_EXE_SUFFIX})
TARGET_LINK_LIBRARIES(mysqld ${MYSQLD_STATIC_PLUGIN_LIBS}
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_DEBUG_SYMBOLS(mysqld)
......
......@@ -20,3 +20,4 @@ ADD_DEFINITIONS(${SSL_DEFINES})
SET(VIO_SOURCES vio.c viosocket.c viossl.c viosslfactories.c)
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