I\'m new to C++ and have been struggling with compiling/making/linking/building/whatever, lets see if somebody can help me out. I did some searches and found other people with
In CMake versions earlier than 3.1, we use
add_compile_options(-std=c++11) # CMake 2.8.12 or newer
to add compile options to the compiler call as described in the CMake Docs.
That's propably not as portable as the one in Alvaro's answer, but it's more readable and since you are on you RasPi, I guess, GCC and Clang as target compilers will do.
Edit: For the sake of completeness: In CMake version 3.1 and newer, if you want to force C++11, you need the following lines:
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
This enables the options for all targets following this declaration during compilation. If you want to control this more fine-grained, see Alvaro's answer or the CMake Docs of set_taget_properties()
, which then looks something like this:
set_target_properties(myTarget PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)
Edit: But beware that C++11 support in GCC 4 is not complete and there might be things that behave differently from the defined standard.