Skip to content

Commit 372449e

Browse files
Fix the c++ version configuration in cmake
1 parent 8ce3d90 commit 372449e

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22

33
cmake_minimum_required(VERSION 3.25)
44

5-
project(beman.scope DESCRIPTION "Generic Scope Guard" LANGUAGES CXX
5+
project(beman.scope DESCRIPTION "Generic Scope Guard" LANGUAGES CXX)
6+
7+
# Define an option for the C++ standard with a default of 20
8+
option(CXX_STANDARD "C++ standard to use (minimum C++20)" 20)
9+
10+
# Ensure the specified standard is at least C++20
11+
if (CXX_STANDARD LESS 20)
12+
message(FATAL_ERROR "The minimum required C++ standard is C++20")
13+
endif()
14+
15+
# Set the C++ standard based on the user input
16+
set(CMAKE_CXX_STANDARD ${CXX_STANDARD})
17+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
18+
set(CMAKE_CXX_EXTENSIONS OFF)
619

720
enable_testing()
821

CMakePresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"generator": "Ninja",
88
"binaryDir": "${sourceDir}/build/${presetName}",
99
"cacheVariables": {
10-
"CMAKE_CXX_STANDARD": "20"
10+
"CXX_STANDARD": "20"
1111
}
1212
},
1313
{

examples/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
set(CMAKE_CXX_STANDARD 20) # Set the C++ standard to C++20
4-
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Ensure the standard is required
5-
set(CMAKE_CXX_EXTENSIONS OFF) # Disable compiler-specific extensions
6-
73
set(ALL_EXAMPLES scope_example)
84

95
message("Examples to be built: ${ALL_EXAMPLES}")
@@ -13,3 +9,4 @@ foreach(example ${ALL_EXAMPLES})
139
target_sources(beman.scope.examples.${example} PRIVATE ${example}.cpp)
1410
target_link_libraries(beman.scope.examples.${example} beman::scope)
1511
endforeach()
12+

tests/beman/scope/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
set(CMAKE_CXX_STANDARD 20) # Set the C++ standard to C++20
4-
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Ensure the standard is required
5-
set(CMAKE_CXX_EXTENSIONS OFF) # Disable compiler-specific extensions
63

74
add_executable(beman.scope.tests.scope)
85
target_sources(beman.scope.tests.scope PRIVATE scope.test.cpp)
96

107
target_link_libraries(beman.scope.tests.scope PRIVATE beman::scope)
118

129
add_test(NAME beman.scope.tests.scope COMMAND beman.scope.tests.scope)
10+

0 commit comments

Comments
 (0)