[CMake] Stray backslash appearing when CMAKE_CXX_FLAGS_RELEASE used in custom command
Stephen Morris
s-morris at n-eos.com
Fri Nov 1 12:24:03 EDT 2019
On 1 November at 10:02, Stephen Morris wrote:
> My approach is basically to set up a custom command thus:
> set(CXX_FLAGS ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}) .. or whatever, depending on the current configuration..
> get_target_property(compile_options, mytarget, COMPILE_OPTIONS) add_custom_command(OUTPUT myheader.h.gch
> COMMAND ${CMAKE_CXX_COMPILER} ${CXX_FLAGS} ${compile_options} -fPIC -std=gnu++17 -c myheader.h -o myheader.h.gch
> DEPENDS myheader.h) add_custom_target(BuildMyPCH
> DEPENDS myheader.h.gch) add_dependencies(mytarget, BuildMyPCH)
My earlier question still stands, but at the time I wrote it I had only tested it for Debug builds where ${CMAKE_CXX_FLAGS_DEBUG} consisted of a single item, '-g'.
I've since tried doing the same thing for a Release build, and this failed because ${CMAKE_CXX_FLAGS_RELEASE} has two items, '-O3 -DNDEBUG'. When the custom command is executed, this somehow becomes "-O3\ -DNDEBUG" on the command line, and the presence of the stray backslash causes the compilation to fail with the message,
"cc1plus: error: argument to '-O' should be a non-negative integer. 'g', 's' or 'fast'"
So why isn't the cmake variable placed properly onto the command line, and what can I do to prevent this behaviour?
More information about the CMake
mailing list