[CMake] [EXTERNAL] Re: Check if C++11 flag / standard was indeed found

Robert Maynard robert.maynard at kitware.com
Fri Nov 10 09:06:42 EST 2017


Hi,

What version  of CMake are you using and what miniare you exactly using?

The CXX_STANDARD and REQUIRED will make sure that the compiler has the
ability to enable some level of support for that language level. If
CMake isn't aware of the flag to enable that language level it should
error out. I expect what is happening is the compiler has partial
support for C++11 so the flag is being added, but compilation fails,
for these cases I recommend using target_compile_features to
explicitly state what C++11 features you require from the compiler.

On Thu, Nov 9, 2017 at 3:52 PM, Adams, Brian M <briadam at sandia.gov> wrote:
> Thanks Robert, I presumed something like that was happening under the hood, but I'm trying to ask a slightly different couple questions.
>
> Suppose I set CMAKE_CXX_STANDARD=11 and CMAKE_CXX_STANDARD_REQUIRED=TRUE and configure a C++ project with at least one C++ target.  Is there any variable or other means to tell if CMake was able to find and properly use a C++11 compliant compiler?
>
> I ask because if I set these variables and configure the project with a non-C++11-compliant compiler my build just trundles on until the first compile error due to lack of C++11.  Or if I'm using a version of CMake that doesn't support compiler features for the toolchain in use (even if the compiler supports C++11), CMake might fail to add the necessary -std=c++11 flag, but doesn't warn or error about it.
>
> So, in that case, is there any way I can detect whether the version of CMake being run supports compiler features for the compiler in use?  (As presumably that would be a reasonable indicator of language feature support.)
>
> Thanks,
> Brian
>
>
> -----Original Message-----
> From: Robert Maynard [mailto:robert.maynard at kitware.com]
> Sent: Tuesday, October 31, 2017 5:27 PM
> To: Adams, Brian M <briadam at sandia.gov>
> Cc: cmake at cmake.org
> Subject: [EXTERNAL] Re: [CMake] Check if C++11 flag / standard was indeed found
>
> Hi,
>
> CMake itself does this kind of inspection inside the CompileFlags.cmake file  (
> https://gitlab.kitware.com/cmake/cmake/blob/v3.9.3/CompileFlags.cmake#L62
> ). While this exact example is for sunpro, it should be a good example of how to make a similar check for Intel.
>
> On Tue, Oct 31, 2017 at 2:17 PM, Adams, Brian M <briadam at sandia.gov> wrote:
>> Longer term, I plan to follow better practice and include compiler
>> language feature checks for specific C++11 features and let CMake
>> deduce the necessary language standard.
>>
>>
>>
>> In the meantime, I’m trying to implement a stopgap solution to warn
>> the user if CMake doesn’t know how to add a C++11 flag for the
>> CMAKE_CXX_COMPILER in use, so they can add it themselves.  For
>> example, CMake C++11 support for Intel wasn’t added until 3.6, but a
>> user could still use CMake 3.1 to build our software if they explicitly add the “-std=c++11” flag.
>>
>>
>>
>> I’m setting
>>
>>   CMAKE_CXX_STANDARD=11
>>
>>   CMAKE_CXX_STANDARD_REQUIRED=TRUE
>>
>>
>>
>> My hope was that if the CMake version in use doesn’t know how to add
>> the necessary C++11 compile flag, that this would result in an error,
>> but it doesn’t seem to.
>>
>>
>>
>> Is there a way I can detect whether CMake was able to add the
>> necessary
>> C++11 flag, rather than letting the build run forward until a compile
>> failure?
>>
>>
>>
>> My fallback plan might be some conditionals that check specific
>> (CMAKE_CXX_COMPILER_ID, CMAKE_VERSION) pairs and warn the user for
>> cases where that version of CMake doesn’t have
>> <ID>-CXX-FeatureTests.cmake (which I’m assuming is an indicator of
>> being able to add the C++11 compile flags for that compiler ID…)
>>
>>
>>
>> Brian
>>
>>
>> --
>>
>> 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