I have the following content in my CMakeLists.txt:
project( Matfile )
SET ( CMAKE_CXX_FLAGS "-std=c++0x" )
set ( SOURCES
"foo.cpp"
"bar.cpp"
)
add_library(
Matfile
${SOURCES}
)
As you may imagine, what I want to do is to compile my C++ sources using the flag -std=c++0x (I'm using gcc and I need the C++11 features). Unfortunately, this does not work, in the sense that, when I use cmake to generate the makefiles, the variable CMAKE_CXX_FLAGS is completely void.
How can I set this variable in the project file?
It seems to be a very stupid question, but I just spent not less than two houres trying to figure this out.
This is the solution I currently use:
Or, if you have an older version of cmake and you want to see it show up in cmake-gui:
In the specific case of requiring a particular standard to the compiler, cmake 3.1 solves the issue by providing a way to request a standard version or a set of compiler features. Refer to this answer and to the official documentation.
I've come up with a better method that works on older versions of cmake, e.g. Ubuntu 14 has 2.8.12, and target expressions are 3.3 feature.
Here is how you would set some C++ specific flags: