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

List:       cmake
Subject:    Re: [CMake] C++ standard version fallbacks.
From:       Craig Scott <craig.scott () crascit ! com>
Date:       2017-06-05 22:35:09
Message-ID: CA+dygY=so3FdqiQ569A+-jO2=eo=LWu5m7bETB7ScU8cZJkUCw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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. 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.
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, only either "I'd like to use *up to *this version" or "I must use
exactly this version". That's back to front, in my view, and pretty much
all uses of these that I see want either "I'd like *at least* this version"
or "I must use exactly this version".


-- 
Craig Scott
Melbourne, Australia
https://crascit.com

[Attachment #5 (text/html)]

<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun \
6, 2017 at 7:50 AM, Stephen Kelly <span dir="ltr">&lt;<a \
href="mailto:steveire@gmail.com" target="_blank">steveire@gmail.com</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><span class="">Roger Leigh wrote:<br> <br>
&gt; Hi folks,<br>
&gt;<br>
&gt; I&#39;m currently using this logic to use C++14 with a fallback to C++11<br>
&gt; when C++14 is unavailable:<br>
&gt;<br>
&gt;      if(NOT CMAKE_CXX_STANDARD)<br>
&gt;         set(CMAKE_CXX_STANDARD 14)<br>
&gt;      endif()<br>
&gt;      if(NOT CMAKE_CXX_STANDARD_REQUIRED)<br>
&gt;         set(CMAKE_CXX_STANDARD_<wbr>REQUIRED 11)<br>
&gt;      endif()<br>
&gt;<br>
&gt; which seems to work OK.<br>
&gt;<br>
&gt; However, for some new stuff, I&#39;d like to use C++17 when available, but<br>
&gt; fall back to C++14, C++11 or C++98.   Is it possible to do this?<br>
<br>
</span>Probably set CMAKE_CXX_STANDARD<br>
<br>
without CMAKE_CXX_STANDARD_REQUIRED (That variable doesn&#39;t really make sense<br>
to me and I think it is overused when not \
needed).<br></blockquote><div><br></div><div>If you don&#39;t set \
CMAKE_CXX_STANDARD_REQUIRED, then there&#39;s no guarantee you get any particular \
minimum standard. Roger&#39;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&#39;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. Roger&#39;s use would actually make it a bit better, if \
that was how it worked, but unfortunately there&#39;s currently no way to set a \
<i>minimum</i> standard version, only either &quot;I&#39;d like to use <b>up to \
</b>this version&quot; or &quot;I must use exactly this version&quot;. That&#39;s \
back to front, in my view, and pretty much all uses of these that I see want either \
&quot;I&#39;d like <b>at least</b> this version&quot; or &quot;I must use exactly \
this version&quot;.</div><div><br></div></div><div><br></div>-- <br><div \
class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div \
dir="ltr"><div><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a \
href="https://crascit.com" \
target="_blank">https://crascit.com</a><br></div></div></div></div></div></div></div> \
</div></div>



-- 

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