Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add C++0x support in CMake

Tags:

c++

c++11

cmake

I have a rather large application configured in CMake. I have recently added a couple of classes that use C++0x functionality, and it breaks the build, since CMake is not configured to compile with C++0x support. How do I add that as an option to CMake?

like image 722
ewok Avatar asked Oct 03 '12 18:10

ewok


2 Answers

You need to add the flag to CMAKE_CXX_FLAGS:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
like image 89
juanchopanza Avatar answered Sep 27 '22 21:09

juanchopanza


I use this snippet for GCC, but it is a more complicated way:

if(CMAKE_COMPILER_IS_GNUCXX)
   SET(ENABLE_CXX11 "-std=c++11")

   EXECUTE_PROCESS(COMMAND "${CMAKE_CXX_COMPILER} -dumpversion" OUTPUT_VARIABLE GCC_VERSION)
   if (GCC_VERSION VERSION_LESS 4.7)
      SET(ENABLE_CXX11 "-std=c++0x")
   endif()

   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_CXX11}")
endif()
like image 33
fasked Avatar answered Sep 27 '22 21:09

fasked