Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake target_link_options LINKER syntax

Tags:

c++

cmake

Since CMake 3.13, target_link_options exists that adds "options to the link step".

Near the bottom of that page it says:

To pass options to the linker tool, each compiler driver has its own syntax. The LINKER: prefix and , separator can be used to specify, in a portable way, options to pass to the linker tool

Could someone give an example of how you would use target_link_options() with the LINKER: helper?

Thank you for any help!

like image 892
Arghnews Avatar asked Oct 27 '25 05:10

Arghnews


1 Answers

The idea is to put all linker options as a string of comma-separated items prepended by 'LINKER:'. Say I have these set of flags which I use with the compiler invocation (gcc):

-Wl,--gc-sections,-Tbootloader.ld,-Map=bootloader.map

Then cmake portion should look like.

...
add_executable(bootloader ${SRC})
target_link_options(bootloader PUBLIC "LINKER:--gc-sections,-Tbootloader.ld,-Map=bootloader.map") 
...
like image 72
dnsglk Avatar answered Oct 28 '25 19:10

dnsglk