[CMake] How to set platform-specific compiler-options from within CMakeFiles

Martin Apel martin.apel at simpack.de
Thu Jun 5 10:35:23 EDT 2008


Hi all,

I am trying to set the CMAKE_CXX_FLAGS or CMAKE_CXX_FLAGS_INIT variable, 
such that it contains flags to turn off specific warnings for the Visual 
Studio compiler. I definitely want to set these additional flags from 
within a CMakeFile, specifying them on the command line or interactively 
is not an option.
I have included a Windows-specific file by using
INCLUDE (${CMAKE_SYSTEM_NAME}.cmake)

The file Windows.cmake contains the line
SET (ENV{CXXFLAGS} "/wd4251")

However this only works after the PROJECT line within the CMakeFile, 
because before it CMAKE_SYSTEM_NAME seems to be unset. On the other 
hand, when writing the include statement after the project command, the 
CMAKE_CXX_FLAGS seem already to be set. If possible I would like to 
specify those flags as initial values, avoiding to use the force option 
of the set command.

What is the recommended way to add platform-specific compiler flags from 
within CMakeFiles?

Any help would be appreciated.

Martin



More information about the CMake mailing list