Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake with SDL 2.0 and C++11

Tags:

c++

c++11

cmake

I'm having some trouble compiling a C++11/SDL 2.0 code with CMake. The CMakeLists is pretty simple:

cmake_minimum_required(VERSION 2.6)
project(Test)

include(FindPkgConfig)
pkg_search_module(SDL2 REQUIRED sdl2)
include_directories(${SDL2_INCLUDE_DIRS})
target_link_libraries(sdl2test ${SDL2_LIBRARIES})

add_definitions(-std=c++0x)
add_executable(Test src/main.cpp)

However, when compiling, i receive this error:

Scanning dependencies of target Test
[100%] Building CXX object CMakeFiles/Test.dir/src/main.cpp.o
/var/dev/cmake/src/main.cpp: In function ‘int main(int, char**)’:
/var/dev/cmake/src/main.cpp:11:16: error: ‘nullptr’ was not declared in this scope
/var/dev/cmake/src/main.cpp:17:16: error: ‘nullptr’ was not declared in this scope
make[2]: *** [CMakeFiles/Test.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Test.dir/all] Error 2
make: *** [all] Error 2

cmake version 2.8.9 and gcc 4.7.2. Any ideas on how to properly make usage of C++11 features with CMake?

ps: I have also tried -std=c++11

like image 308
Klaus S. Avatar asked Oct 02 '13 22:10

Klaus S.


1 Answers

add_definitions is really for setting preprocessor definitions. You need to set the CMAKE_CXX_FLAGS here:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
like image 50
Fraser Avatar answered Sep 23 '22 17:09

Fraser