Skip to content

Generate a CMake-time error if compiler+flags lacks deducing this support #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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()

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