Skip to content

Commit 88ec881

Browse files
authored
Merge pull request #12 from camio/cmake-time-deducing-this-error
Generate a CMake-time error if compiler+flags lacks deducing this support
2 parents 4a03894 + bff12ac commit 88ec881

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ cmake_minimum_required(VERSION 3.10)
22

33
project(beman_iter_interface VERSION 0.0.0 LANGUAGES CXX)
44

5+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
56
include(FetchContent)
7+
include(CompilerFeatureTest)
8+
9+
beman_iterator26_check_deducing_this(COMPILER_SUPPORTS_DEDUCING_THIS)
10+
11+
if(NOT COMPILER_SUPPORTS_DEDUCING_THIS)
12+
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.")
13+
endif()
614

715
enable_testing()
816

cmake/CompilerFeatureTest.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Functions that determine compiler capabilities
2+
3+
include(CheckCXXSourceCompiles)
4+
5+
# Determines if the selected C++ compiler has deducing this support. Sets
6+
# 'result_var' to whether support is detected.
7+
function(beman_iterator26_check_deducing_this result_var)
8+
check_cxx_source_compiles( "
9+
// clang-specific check due to http://github.com/llvm/llvm-project/issues/113174
10+
#if defined(__cpp_explicit_this_parameter) || (defined(__clang__) && __has_extension(cxx_explicit_this_parameter))
11+
#else
12+
#error No deducing this support
13+
#endif
14+
int main(){}
15+
" HAVE_DEDUCING_THIS )
16+
set(${result_var} ${HAVE_DEDUCING_THIS} PARENT_SCOPE)
17+
endfunction()

0 commit comments

Comments
 (0)