diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a80cd9..c54d64d 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 lacks support C++23's deducing this, 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..314ea1c --- /dev/null +++ b/cmake/CompilerFeatureTest.cmake @@ -0,0 +1,15 @@ +# 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( " +#ifndef __cpp_explicit_this_parameter +#error No deducing this support +#endif +int main(){} +" HAVE_DEDUCING_THIS ) + set(${result_var} ${HAVE_DEDUCING_THIS} PARENT_SCOPE) +endfunction()