Skip to content

Commit

Permalink
Generate a CMake-time error if compiler+flags lacks deducing this sup…
Browse files Browse the repository at this point in the history
…port

This improves the user experience when incompatible flags are used. It
also is a first step toward resolving #10.
  • Loading branch information
camio committed Oct 18, 2024
1 parent 7433749 commit e7d7043
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
15 changes: 15 additions & 0 deletions cmake/CompilerFeatureTest.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit e7d7043

Please sign in to comment.