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:
parent
05a4ff30bf
commit
a0e0535512
18
cmake/Modules/UseOnlyNeeded.cmake
Normal file
18
cmake/Modules/UseOnlyNeeded.cmake
Normal 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")
|
Loading…
Reference in New Issue
Block a user