From f0b692f694a35b6880919cb2df2936bff40dea3d Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Tue, 22 Oct 2024 00:23:40 +0300 Subject: [PATCH 1/6] Re-enable all examples --- CMakeLists.txt | 3 +++ cmake/CompilerFeatureTest.cmake | 23 +++++++++++++++++++++++ examples/CMakeLists.txt | 9 ++++++--- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 cmake/CompilerFeatureTest.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a1a4550..70e94f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/cmake/CompilerFeatureTest.cmake b/cmake/CompilerFeatureTest.cmake new file mode 100644 index 0000000..cbf6631 --- /dev/null +++ b/cmake/CompilerFeatureTest.cmake @@ -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 // 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() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 60032ff..1339a95 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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}) From 454c1de38df303f88c2257b5b70df675007f513a Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Tue, 22 Oct 2024 01:26:35 +0300 Subject: [PATCH 2/6] Feedback from linter --- cmake/CompilerFeatureTest.cmake | 12 +++++++----- examples/CMakeLists.txt | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cmake/CompilerFeatureTest.cmake b/cmake/CompilerFeatureTest.cmake index d491d72..240853e 100644 --- a/cmake/CompilerFeatureTest.cmake +++ b/cmake/CompilerFeatureTest.cmake @@ -13,11 +13,13 @@ function(beman_check_range_support result_var) return() endif() - check_cxx_source_compiles(" -// example specific check due to https://github.com/beman-project/exemplar/issues/41 -#include // C++20 ranges; note that __cpp_lib_ranges is not defined for all compilers -int main(){ return 0; } -" _HAVE_RANGE_SUPPORT ) + check_cxx_source_compiles( + " + #include // 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() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b43865f..8f27096 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -4,7 +4,10 @@ set(ALL_EXAMPLES identity_direct_usage) if(COMPILER_SUPPORTS_RANGES) list(APPEND ALL_EXAMPLES identity_as_default_projection) else() - message(WARNING "Missing range support! Skip: identity_as_default_projection") + message( + WARNING + "Missing range support! Skip: identity_as_default_projection" + ) endif() foreach(example ${ALL_EXAMPLES}) From 4681c10897482754eb80eb55b781f597c856458d Mon Sep 17 00:00:00 2001 From: River <26424577+wusatosi@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:03:36 -0500 Subject: [PATCH 3/6] Use check_cxx_symbol_exists --- examples/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 8f27096..67a8cbd 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,7 +1,12 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception set(ALL_EXAMPLES identity_direct_usage) -if(COMPILER_SUPPORTS_RANGES) + +# Example: identity_as_default_projection need ranges support: +include(CheckCXXSymbolExists) +check_cxx_symbol_exists(__cpp_lib_ranges "ranges" HAS_RANGES) + +if(HAS_RANGES) list(APPEND ALL_EXAMPLES identity_as_default_projection) else() message( From a7a6372908aa0ec1e0413b20bfd9c7686c655fe8 Mon Sep 17 00:00:00 2001 From: River <26424577+wusatosi@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:10:50 -0500 Subject: [PATCH 4/6] remove unneeded file --- CMakeLists.txt | 2 -- cmake/CompilerFeatureTest.cmake | 25 ------------------------- 2 files changed, 27 deletions(-) delete mode 100644 cmake/CompilerFeatureTest.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4decf61..9e73ca3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,6 @@ include(CTest) include(FetchContent) include(GNUInstallDirs) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") - if(BEMAN_EXEMPLAR_BUILD_TESTING) enable_testing() diff --git a/cmake/CompilerFeatureTest.cmake b/cmake/CompilerFeatureTest.cmake deleted file mode 100644 index 240853e..0000000 --- a/cmake/CompilerFeatureTest.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# # 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( - " - #include // 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() From d3bbe3016474d422eaad23d8734126a7db88c4b6 Mon Sep 17 00:00:00 2001 From: River <26424577+wusatosi@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:15:22 -0500 Subject: [PATCH 5/6] print examples to be build --- examples/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 67a8cbd..ba8168b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -2,7 +2,7 @@ set(ALL_EXAMPLES identity_direct_usage) -# Example: identity_as_default_projection need ranges support: +# Example `identity_as_default_projection` need ranges support: include(CheckCXXSymbolExists) check_cxx_symbol_exists(__cpp_lib_ranges "ranges" HAS_RANGES) @@ -15,6 +15,8 @@ else() ) endif() +message("Examples to be built: ${ALL_EXAMPLES}") + foreach(example ${ALL_EXAMPLES}) add_executable(beman.exemplar.examples.${example}) target_sources(beman.exemplar.examples.${example} PRIVATE ${example}.cpp) From 43f0bcab1f8ea8b726b57638857de5ba1678802d Mon Sep 17 00:00:00 2001 From: River <26424577+wusatosi@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:17:52 -0500 Subject: [PATCH 6/6] update preset to build all examples by default --- CMakePresets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakePresets.json b/CMakePresets.json index ede9472..0b645f2 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -7,7 +7,7 @@ "generator": "Ninja", "binaryDir": "${sourceDir}/build/${presetName}", "cacheVariables": { - "CMAKE_CXX_STANDARD": "17" + "CMAKE_CXX_STANDARD": "20" } }, {