[CMake] Stray backslash appearing when CMAKE_CXX_FLAGS_RELEASE used in custom command

Stephen Morris s-morris at n-eos.com
Mon Nov 4 18:07:08 EST 2019


On 4 November at 08:43, Eric Doenges wrote:
> Welcome to the wonderful world of lists and their interaction with quoting in CMake ! Since space is used 
> as a list item separator outside of double quoted strings, CMake is escaping the space within CXX_FLAGS
> to keep it as a single element within the list of arguments passed to add_custom_command. To avoid this,
> you need to turn CXX_FLAGS into a list prior to using it in add_custom_command:
>
>string(REGEX REPLACE " " ";" CXX_FLAGS "${CXX_FLAGS}")
>
>Of course, this will not work if you want to pass a double quoted string as an actual command line argument ... 

Thank you! I'd never have worked this out for myself, though it makes perfect sense now you've explained it.

Thank you for answering my other question about -fPIC -std=gnu++17 as well.



More information about the CMake mailing list