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

Robert Maynard robert.maynard at kitware.com
Tue Oct 31 19:27:23 EDT 2017


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