From e7d704394c1e04535a1ed08e4d28c4b1d4e4c653 Mon Sep 17 00:00:00 2001 From: David Sankel Date: Fri, 18 Oct 2024 13:08:02 -0400 Subject: [PATCH 1/4] Generate a CMake-time error if compiler+flags lacks deducing this support This improves the user experience when incompatible flags are used. It also is a first step toward resolving #10. --- CMakeLists.txt | 8 ++++++++ cmake/CompilerFeatureTest.cmake | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 cmake/CompilerFeatureTest.cmake 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() From 4b5cf8d2343d1bcfcd33b75aa292753667a773b9 Mon Sep 17 00:00:00 2001 From: David Sankel Date: Fri, 18 Oct 2024 13:21:52 -0400 Subject: [PATCH 2/4] fix typo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c54d64d..6529048 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ 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.") + message(FATAL_ERROR "The selected compiler and flags lacks 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() From 5b6c36e076c6a48223fb3013044b981661339c80 Mon Sep 17 00:00:00 2001 From: David Sankel Date: Fri, 18 Oct 2024 13:22:43 -0400 Subject: [PATCH 3/4] fix typo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6529048..0262a45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ 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 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.") + 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() From bff12ac7bef392109d2c69a08d7459314e6a33d8 Mon Sep 17 00:00:00 2001 From: David Sankel Date: Mon, 21 Oct 2024 15:13:15 +0000 Subject: [PATCH 4/4] Add clang-specific explicit this detection --- cmake/CompilerFeatureTest.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/CompilerFeatureTest.cmake b/cmake/CompilerFeatureTest.cmake index 314ea1c..2480cf4 100644 --- a/cmake/CompilerFeatureTest.cmake +++ b/cmake/CompilerFeatureTest.cmake @@ -6,7 +6,9 @@ include(CheckCXXSourceCompiles) # 'result_var' to whether support is detected. function(beman_iterator26_check_deducing_this result_var) check_cxx_source_compiles( " -#ifndef __cpp_explicit_this_parameter +// 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(){}