openage icon indicating copy to clipboard operation
openage copied to clipboard

Target Property: LINK_WHAT_YOU_USE

Open simonsan opened this issue 5 years ago • 0 comments

This is a boolean option that when set to TRUE will automatically run ldd -r -u on the target after it is linked. In addition, the linker flag -Wl,--no-as-needed will be passed to the target with the link command so that all libraries specified on the command line will be linked into the target. This will result in the link producing a list of libraries that provide no symbols used by this target but are being linked to it. This is only applicable to executable and shared library targets and will only work when ld and ldd accept the flags used. (src)

I've built libopenage with that property [1]:

Warning: Unused direct dependencies:
	/lib/x86_64-linux-gnu/libz.so.1
	/lib/x86_64-linux-gnu/librt.so.1
	/usr/lib/x86_64-linux-gnu/libQt5Network.so.5
[ 89%] Linking CXX shared module cython_check.cpython-36m-x86_64-linux-gnu.so
Warning: Unused direct dependencies:
	/home/runner/work/openage/openage/.bin/g++-release-Oauto-sanitize-none/libopenage/libopenage.so.0
	/lib/x86_64-linux-gnu/libm.so.6
	/lib/x86_64-linux-gnu/libgcc_s.so.1

Adding the last line to libopenage/CMakeLists.txt/:

set_target_properties(libopenage PROPERTIES
 	VERSION 0
 	AUTOMOC ON
 	AUTOGEN_TARGET_DEPENDS "codegen"
	LINK_WHAT_YOU_USE "TRUE"
 )

There is also a default value for every target that is created: CMAKE_LINK_WHAT_YOU_USE=<BOOL>, maybe this would be easier then for future use?

And to nyan as well, would give us some info which libraries are linked although we don't use them.

simonsan avatar May 03 '20 00:05 simonsan