diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a80cd9..0262a45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,15 @@ cmake_minimum_required(VERSION 3.10) project(beman_iter_interface VERSION 0.0.0 LANGUAGES CXX) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") include(FetchContent) +include(CompilerFeatureTest) + +beman_iterator26_check_deducing_this(COMPILER_SUPPORTS_DEDUCING_THIS) + +if(NOT COMPILER_SUPPORTS_DEDUCING_THIS) + message(FATAL_ERROR "The selected compiler and flags lack C++23's deducing this support, which is required to build this project. Try adding -DCMAKE_CXX_STANDARD=23 to your command line parameters and, failing that, upgrade your compiler.") +endif() enable_testing() diff --git a/cmake/CompilerFeatureTest.cmake b/cmake/CompilerFeatureTest.cmake new file mode 100644 index 0000000..2480cf4 --- /dev/null +++ b/cmake/CompilerFeatureTest.cmake @@ -0,0 +1,17 @@ +# Functions that determine compiler capabilities + +include(CheckCXXSourceCompiles) + +# Determines if the selected C++ compiler has deducing this support. Sets +# 'result_var' to whether support is detected. +function(beman_iterator26_check_deducing_this result_var) + check_cxx_source_compiles( " +// clang-specific check due to http://github.com/llvm/llvm-project/issues/113174 +#if defined(__cpp_explicit_this_parameter) || (defined(__clang__) && __has_extension(cxx_explicit_this_parameter)) +#else +#error No deducing this support +#endif +int main(){} +" HAVE_DEDUCING_THIS ) + set(${result_var} ${HAVE_DEDUCING_THIS} PARENT_SCOPE) +endfunction()