Arghnews
Arghnews

Reputation: 124

CMake target_link_options LINKER syntax

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!

Upvotes: 4

Views: 7224

Answers (1)

dnsglk
dnsglk

Reputation: 167

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") 
...

Upvotes: 6

Related Questions