[CMake] Specify compiler flags as list?

Matthew S Wallace mwallace at ccmtrading.com
Mon Oct 12 23:22:46 EDT 2015


Consider the following CMakeLists.txt (hello.cpp is some standard hello world program)

cmake_minimum_required (VERSION 2.6)
project(HelloWorld)
add_executable(hello hello.cpp)
set(WARNING_FLAGS -Wno-char-subscripts -Wno-unused-local-typedefs)
#set(WARNING_FLAGS "-Wno-char-subscripts -Wno-unused-local-typedefs")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${WARNING_FLAGS}”)

When I try to run “cmake . -DCMAKE_BUILD_TYPE=RELEASE && make” - make fails because there
are semi-colons in the command line.  According to the FAQ (https://cmake.org/Wiki/CMake_FAQ#Why_do_I_have_unwanted_semicolons_.3B_in_my_compiler_flags.3F <https://cmake.org/Wiki/CMake_FAQ#Why_do_I_have_unwanted_semicolons_.3B_in_my_compiler_flags.3F>)
putting the list variable in quotes should cause it to be expanded with spaces, but this doesn’t seem to occur.

If I replace the set(WARNING_FLAGS ..) with the commented out line, everything works fine, but I’d rather not do this because it seems cleaner to use lists for compiler options (can put them on multiple lines, append to them, etc).  What’s the right way to do this?

-Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151012/cd1f0932/attachment.html>


More information about the CMake mailing list