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

Adams, Brian M briadam at sandia.gov
Tue Oct 31 14:17:06 EDT 2017


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171031/05048220/attachment.html>


More information about the CMake mailing list