CMake lists are essentially just semicolon-separated strings, but if you pass such a variable to a command, it does get expanded into multiple arguments - for example,
set(FLAGS f1 f2 f3) # now FLAGS == 'f1;f2;f3' add_custom_command( ... COMMAND my_cmd ${FLAGS} ... )
will correctly call my_cmd f1 f2 f3
.
Now if I do this with
set_target_properties( myTarget PROPERTIES LINK_FLAGS "${LD_FLAGS}" )
the expansion does not occur, and I end up with a single LD_FLAG that contains semicolons -- useless, instead of expanding it into a space-separated string.
Is there any way to make it so that when I pass a list to the LINK_FLAGS property (or any property that is), it gets expanded into multiple arguments rather than just one?
Thanks, Dan
A list in cmake is a ; separated group of strings. To create a list the set command can be used. For example, set(var a b c d e) creates a list with a;b;c;d;e , and set(var "a b c d e") creates a string or a list with one item in it.
Editing CMakeLists Files These can be found in the Auxiliary directory of the source distribution, or downloaded from the CMake Download page.
I don't think set_target_properties
can do the expansion automatically, but you can use string (REPLACE ...)
to expand a list into a space separated string:
string (REPLACE ";" " " LD_FLAGS_STR "${LD_FLAGS}") set_target_properties( myTarget PROPERTIES LINK_FLAGS "${LD_FLAGS_STR}" )
For using a cmake List as list, use
${LD_FLAG}
For using a cmake list as string, (i.e. list items are separated with ';'), use
"${LD_FLAG}"
So in your case, just remove "" should be sufficient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With