Module to prune unnecessary libraries from link

On Linux all libraries that are specified on the command-line will be
referred to in the resulting binary. There may be find modules which
just adds everything to satisfy every possible dependency; we want to
discard those unnecessary libraries.
This commit is contained in:
Roland Kaufmann 2013-01-24 23:05:25 +01:00
parent 05a4ff30bf
commit a0e0535512

View File

@ -0,0 +1,18 @@
# - Use only needed imports from libraries
#
# Add the -Wl,--as-needed flag to the default linker flags on Linux
# in order to get only the minimal set of dependencies.
function (prepend var_name value)
if (${var_name})
set (${var_name} "${value} ${${var_name}}" PARENT_SCOPE)
else (${var_name})
set (${var_name} "${value}")
endif (${var_name})
endfunction (prepend var_name value)
if (CMAKE_CXX_PLATFORM_ID STREQUAL "Linux")
prepend (CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
prepend (CMAKE_MODULE_LINKER_FLAGS "-Wl,--as-needed")
prepend (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
endif (CMAKE_CXX_PLATFORM_ID STREQUAL "Linux")