With the diversification of standard libraries implementations for C and C++ it has become desirable to be able to detect and change the used standard library from CMake in an easy and portable manner.
CMake will add additional compiler flags pertaining to the standard library if
<LANG>_STANDARD_LIBRARY differs from the detected default.
- If the default standard library is false/
<LANG>_STANDARD_LIBRARYto non-false values is an error due to possible problems stemming from duplicate or conflicting options with the compiler's default standard library.
- If the
<LANG>_STANDARD_LIBRARY_<LIBRARY>is false or not set, setting
<LIBRARY>is an error. False values would be reported as "unsupported", unset as "unknown".
The handling of default standard libraries allows introducing this functionality without requiring a policy.
"NOTFOUND" value will allow adding support for new platforms and standard libraries without backwards compatibility concerns.
Compiler modules would set the following variables:
Contains the value of the detected default standard library for the current language's compiler. May be modified by user.
"NOTFOUND"if the standard library is unknown.
nonefor no standard library.
Set to the detected default standard library. Stored in
Used internally for detecting if the user changed
CMAKE_<LANG>_STANDARD_LIBRARY from the default.
Set to true if supported by the current compiler. False if not supported (e.g. compiler version too old). Unset if compiler module is unaware of such a standard library.
libstdc++– GNU C++ standard library
libc++– LLVM C++ standard library
msvc– Microsoft C++ standard library
Custom standard libraries
Custom or exotic default standard libraries not known by CMake would be detected as false/
"NOTFOUND" and thus CMake won't mess with standard library options. The new mechanism won't introduce backwards incompatibility in such cases.
It would be possible for users to add support for custom standard libraries not known by CMake by setting
However, it seems advisable to avoid documenting and explicitly supporting custom standard libraries for a while to allow revising these variables in future versions to better support various combinations of compilers and standard libraries.
Default C++ standard library detection of
Ability to choose between
- GCC support.
Extend support to MSVC with
Extend support to C with at least
glibcon GCC, MSVC and Clang.
- Custom standard library support once there's enough real-world experience with adding support for standard libraries on various compilers.