[CMake] extending CMAKE_<LANG>_LINK_EXECUTABLE

Fred Baksik fdk17 at ftml.net
Tue Oct 8 09:48:39 EDT 2019


On Tue, Oct 8, 2019, at 9:08 AM, Setzer Sebastian (CM-CI2/ECS2) via CMake wrote:
> Dear list,

> I need to run a tool after building an executable, which will modify the executable itself.

> I intend to extend the toolchain for this, because it shall be done for every executable on this particular operating system.

> 

> I think for this purpose, I need to change the rule CMAKE_<LANG>_LINK_EXECUTABLE.

> And I think I can’t put multiple commands into that rule, so I need to write a wrapper which will be called instead of the normal linker, and the calls the normal linker and then that special tool.

> 

> Right, so far?

> 

> Now I’d like to pass a few additional parameters to this tool, which I’d like to get from a special target property.

> 

> The rule currently looks like this:

> set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")

> 

> And I wonder what these placeholders in angle brackets mean, and if there are more placeholders available. The manual doesn’t say anything about this, unfortunately:

> https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_LINK_EXECUTABLE.html

> 

> Is there, for example, a way to access arbitrary target properties?

> Or do I need to hide my special parameters somewhere in the LINK_OPTIONS property?

> 

> Regards,

> Sebastian

> -- 
> 

I don't see how running arbitrary commands is possible in this way.

If you want to avoid the boilerplate of adding a post-build custom command use a macro that performs the add_executable() and add_custom_command(). Then use the macro for each of the executable.

Those markers aren't specified because it is part of implementation details of the Makefile (and Ninja?) generator and these items tend not to be documented for that reason (at least that is what I have come to understand from comments made on gitlab and developers mailing list).

--
Fred
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20191008/5e0329cc/attachment-0001.html>


More information about the CMake mailing list