In CMake, is it possible to programmatically retrieve the complete list of linker flags that will be used for a given target? The only way I can see to do this is to inspect the link.txt
file in the target's CMakeFiles
directory. Not ideal.
The use case that I'm interested in is to collect the data to include in something like a pkg-config file. I'm writing a library, and it includes a couple executable utilities that use the library. Building the executables (especially when the library is build statically) requires a non-trivial link line to link to my library and its dependencies. So I'd like to write out the link line necessary for building these executables to a data file included with the package such that other clients can know how to link.
As @Tsyvarev has commented there is no build-in command or property "to programmatically retrieve the complete list of linker flags" in CMake.
But inspired by your hint "so I'd like to write out the link line necessary for building these executables to a data file" I think I found a feasible solution (at least for makefile generators).
And if I understand your request correctly, we are not talking about simple verbose outputs like you get with e.g.
CMAKE_VERBOSE_MAKEFILE
, which would still need you to copy things manually.So taking the following into account:
I came up with adding an
LinkLine
executable using myECHO
"linker" with the single purpose to create a link line file of my choosing:The nice thing about this approach is, that the output of my
LinkLine
target can be used as any other "officially generated" executable output (e.g. ininstall()
commands or post-build steps with generator expressions):References