Skip to content

Simple cmake module to specify required C++ and standard library features

License

Notifications You must be signed in to change notification settings

mikekasprzak/RequireCXXFeature

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RequireCXXFeature

A set of cmake modules for specifing required C++ and C++ standard library features. It works by checking for C++20 feature test macros. It builds on the built-in CheckCXXSymbolExists cmake module by providing a simpler syntax.

Usage

Add the .cmake files to your project, then include and use them.

CMakeFiles.txt

...

include (RequireCXXFeature.cmake)
# Reference: https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations#table-of-feature-test-macros

# Required C++ features
require_cxx_feature(__cpp_constexpr)
require_cxx_feature(__cpp_decltype_auto)
require_cxx_feature(__cpp_lib_coroutine)
require_cxx_feature(__cpp_lib_format)

Polyfilling a C++ feature with CheckCXXFeature

Instead of raising an error, CheckCXXFeature sets a variable if the requested C++ feature flag is found.

...

include (CheckCXXFeature.cmake)
include (RequireCXXFeature.cmake)
# Reference: https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations#table-of-feature-test-macros

# Required C++ features
require_cxx_feature(__cpp_constexpr)
require_cxx_feature(__cpp_decltype_auto)
require_cxx_feature(__cpp_lib_coroutine) 
check_cxx_feature(__cpp_lib_format HAS_LIB_FORMAT)
if (NOT DEFINED "${HAS_LIB_FORMAT}")
  # polyfill config goes here
endif()

About

Simple cmake module to specify required C++ and standard library features

Topics

Resources

License

Stars

Watchers

Forks

Languages