[CMake] C++11 flag not being added

Matthew S Wallace mwallace at ccmtrading.com
Thu Oct 15 11:41:31 EDT 2015


What version of CMake are you using?  I’m using 3.3.2.  The only other thing I did was:

set_property(GLOBAL PROPERTY CXX_STANDARD_REQUIRED)

I’m guessing this probably does nothing since it is probably a target property.

-Matt

> On Oct 15, 2015, at 10:34 AM, Petr Bena <benapetr at gmail.com> wrote:
> 
> Can you elaborate on it a bit?
> 
> I put set(CMAKE_CXX_STANDARD 11) as first line of my CMakeLists and it
> still doesn't work, without the hack I used I get errors while
> compiling.
> 
> Can you give me example file in which it works? I guess there is more
> needed for it to work.
> 
> On Tue, Oct 13, 2015 at 7:12 PM, Matthew S Wallace
> <mwallace at ccmtrading.com> wrote:
>> Thanks, setting the global variable solved my issue.
>> 
>> -Matt
>> 
>>> On Oct 13, 2015, at 10:46 AM, Johannes Zarl-Zierl <johannes.zarl-zierl at jku.at> wrote:
>>> 
>>> Hi,
>>> 
>>> CXX_STANDARD is a target property, not a global one. You can either set
>>> CXX_STANDARD for every target that needs it, or set it globally by changing
>>> the default value.
>>> 
>>> You can do the latter by setting the variable CMAKE_CXX_STANDARD  before
>>> defining any target that depends on it:
>>> 
>>> set(CMAKE_CXX_STANDARD 11)
>>> 
>>> HTH,
>>> Johannes
>>> 
>>> On Tuesday 13 October 2015 10:22:36 Matthew S Wallace wrote:
>>>> I have the following two lines in my CMakeLists.txt
>>>> 
>>>> set_property(GLOBAL PROPERTY CXX_STANDARD 11)
>>>> set_property(GLOBAL PROPERTY CXX_STANDARD_REQUIRED)
>>>> 
>>>> However when compiling some of my source files, the -std=c++11 flag is not
>>>> added.
>>>> 
>>>> Just for good measure I added:
>>>> target_compile_features(my_target PRIVATE cxx_strong_enums) to the target
>>>> that was having the problem.
>>>> 
>>>> Not sure if it matters, but in this case the compile error I’m getting is
>>>> complaining because I’m referencing a fully scoped enum.  If I explicitly
>>>> include -std=c++11 in my compile flags, everything works.
>>>> 
>>>> I’m thinking I’m probably just misunderstanding how CXX_STANDARD works, but
>>>> any help would be appreciated.
>>>> 
>>>> -Matt
>>> 
>>> --
>>> 
>>> Powered by www.kitware.com
>>> 
>>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>> 
>>> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>>> 
>>> CMake Support: http://cmake.org/cmake/help/support.html
>>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>> 
>>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>> 
>>> Follow this link to subscribe/unsubscribe:
>>> http://public.kitware.com/mailman/listinfo/cmake
>> 
>> --
>> 
>> Powered by www.kitware.com
>> 
>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>> 
>> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>> 
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>> 
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>> 
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/cmake



More information about the CMake mailing list