extending CMAKE_<LANG>_LINK_EXECUTABLE

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

extending CMAKE_<LANG>_LINK_EXECUTABLE

CMake mailing list

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


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: extending CMAKE_<LANG>_LINK_EXECUTABLE

fdk17

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

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake