Skip to content

Commit

Permalink
Re-enable all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
neatudarius committed Oct 21, 2024
1 parent 325a07f commit f0b692f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ project(
DESCRIPTION "A Beman library exemplar"
LANGUAGES CXX)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(CTest)
include(FetchContent)
include(CompilerFeatureTest)
beman_check_range_support(COMPILER_SUPPORTS_RANGES)

if(BUILD_TESTING)
enable_testing()
Expand Down
23 changes: 23 additions & 0 deletions cmake/CompilerFeatureTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Functions that determine compiler capabilities

include(CheckCXXSourceCompiles)

# Determines if the selected C++ compiler has ranges support.
# Sets 'result_var' to whether support is detected.
function(beman_check_range_support result_var)
# Check if the C++ standard is at least C++20 or later.
if(CMAKE_CXX_STANDARD LESS 20)
set(${result_var} FALSE PARENT_SCOPE)
return()
endif()

check_cxx_source_compiles("
// example specific check due to https://github.com/beman-project/exemplar/issues/41
#include <ranges> // C++20 ranges; note that __cpp_lib_ranges is not defined for all compilers
int main(){ return 0; }
" _HAVE_RANGE_SUPPORT )

set(${result_var} ${_HAVE_RANGE_SUPPORT} PARENT_SCOPE)
endfunction()
9 changes: 6 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

set(ALL_EXAMPLES
#identity_as_default_projection
identity_direct_usage)
set(ALL_EXAMPLES identity_direct_usage)
if (COMPILER_SUPPORTS_RANGES)
list(APPEND ALL_EXAMPLES identity_as_default_projection)
else()
message(WARNING "Compiler does not support ranges. Skip: identity_as_default_projection")
endif()

foreach(example ${ALL_EXAMPLES})
add_executable(beman.exemplar.examples.${example})
Expand Down

0 comments on commit f0b692f

Please sign in to comment.