Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cmake won't set the compiler standard to c++11?

Tags:

cmake

I'm new to cmake, and I was building some c++11 code with it (notably a set of template aliases.) I want to use the CXX_STANDARD property to hopefully cover all platforms and problems introduced by simply adding -std=c++11 to cxxflags, which worked for me before:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

But when I change this to

set_property(GLOBAL PROPERTY CXX_STANDARD 11)
set_property(GLOBAL PROPERTY CXX_STANDARD_REQUIRED true)

cmake doesn't tell the compiler to use c++11. What am I doing wrong with the latter code?

like image 783
ralian Avatar asked Jun 11 '15 22:06

ralian


2 Answers

I didn't have CMake updated to the latest version... I should have done that before posting a question. The code above only works for version > 3.1.

like image 137
ralian Avatar answered Oct 25 '22 14:10

ralian


CMAKE_CXX_STANDARD is not a global property, but a variable. http://www.cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_STANDARD.html#variable:CMAKE_CXX_STANDARD

So all you need is

set( CMAKE_CXX_STANDARD 11 )

before you define any targets.

like image 34
Finn Avatar answered Oct 25 '22 15:10

Finn