[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cmake
Subject:    Re: [CMake] C++ standard version fallbacks.
From:       Stephen Kelly <steveire () gmail ! com>
Date:       2017-06-05 22:50:45
Message-ID: oh4n80$mad$1 () blaine ! gmane ! org
[Download RAW message or body]

Craig Scott wrote:

> On Tue, Jun 6, 2017 at 7:50 AM, Stephen Kelly
> <steveire@gmail.com> wrote:
> 
> > Roger Leigh wrote:
> > 
> > > Hi folks,
> > > 
> > > I'm currently using this logic to use C++14 with a fallback to C++11
> > > when C++14 is unavailable:
> > > 
> > > if(NOT CMAKE_CXX_STANDARD)
> > > set(CMAKE_CXX_STANDARD 14)
> > > endif()
> > > if(NOT CMAKE_CXX_STANDARD_REQUIRED)
> > > set(CMAKE_CXX_STANDARD_REQUIRED 11)
> > > endif()
> > > 
> > > which seems to work OK.
> > > 
> > > However, for some new stuff, I'd like to use C++17 when available, but
> > > fall back to C++14, C++11 or C++98.  Is it possible to do this?
> > 
> > Probably set CMAKE_CXX_STANDARD
> > 
> > without CMAKE_CXX_STANDARD_REQUIRED (That variable doesn't really make
> > sense
> > to me and I think it is overused when not needed).
> > 
> 
> If you don't set CMAKE_CXX_STANDARD_REQUIRED, then there's no guarantee
> you get any particular minimum standard.

He wants to fall back all the way to C++98. Am I missing something?

> Roger's example (sorry Roger!)
> highlights part of the confusion about this latter variable (and the
> target property it ultimately controls). He appears to be setting it
> expecting it to specify a minimum version, but that's not how it works. It
> is expected to be a boolean which says whether CMAKE_CXX_STANDARD must be
> honoured or not, which most developers (myself included) tend to find
> unintuitive. 

Ok.

I remember I was opposed to introducing CMAKE_CXX_STANDARD_REQUIRED in the 
first place as I think it is redundant. I recommend populating compile 
features for whatever you absolutely need and let cmake populate the std 
flag. If your code can benefit from a more-recent std flag than the 
requirement, then set CMAKE_CXX_STANDARD to that.

> Roger's use would actually make it a bit better, if that was
> how it worked, but unfortunately there's currently no way to set a
> *minimum* standard version,

If you have a minimum, then you must be relying on some language features 
existing and you can list those.

Thanks,

Steve.


-- 

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic