Skip to content

Commit 8d5ddc8

Browse files
committed
Restore observation of the value of CMAKE_CXX_STANDARD when
determining which C++ standard to use.
1 parent 490eb2e commit 8d5ddc8

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@ ensure_git_subrepo("${CMAKE_CURRENT_SOURCE_DIR}/include/quickcpplib/byte/include
1616
# Sets the usual PROJECT_NAME etc
1717
project(quickcpplib VERSION 0.1.0.0 LANGUAGES C CXX)
1818
include(CMakeDependentOption)
19-
option(QUICKCPPLIB_REQUIRE_CXX20 "Add cxx20 compile feature to the target which in turn makes byte-lite, span-lite and akrzemi1/Optional optional." OFF)
20-
cmake_dependent_option(QUICKCPPLIB_REQUIRE_CXX17 "Add cxx17 compile feature to the target which in turn makes akrzemi1/Optional optional." OFF "NOT QUICKCPPLIB_REQUIRE_CXX20" ON)
19+
set(CMAKE_CXX_STANDARD_IS_GREATER_EQUAL_17 FALSE)
20+
set(CMAKE_CXX_STANDARD_IS_GREATER_EQUAL_20 FALSE)
21+
if(CMAKE_CXX_STANDARD GREATER_EQUAL 20)
22+
set(CMAKE_CXX_STANDARD_IS_GREATER_EQUAL_20 TRUE)
23+
set(CMAKE_CXX_STANDARD_IS_GREATER_EQUAL_17 TRUE)
24+
elseif(CMAKE_CXX_STANDARD GREATER_EQUAL 17)
25+
set(CMAKE_CXX_STANDARD_IS_GREATER_EQUAL_17 TRUE)
26+
endif()
27+
cmake_dependent_option(QUICKCPPLIB_REQUIRE_CXX20 "Add cxx20 compile feature to the target which in turn makes byte-lite, span-lite and akrzemi1/Optional optional." OFF "NOT CMAKE_CXX_STANDARD_IS_GREATER_EQUAL_20" ON)
28+
cmake_dependent_option(QUICKCPPLIB_REQUIRE_CXX17 "Add cxx17 compile feature to the target which in turn makes akrzemi1/Optional optional." OFF "NOT CMAKE_CXX_STANDARD_IS_GREATER_EQUAL_17" ON)
2129
cmake_dependent_option(QUICKCPPLIB_USE_SYSTEM_BYTE_LITE "Whether to use embedded nonstd::byte-lite. Used by various package managers such as vcpkg." OFF "NOT QUICKCPPLIB_REQUIRE_CXX17" OFF)
2230
cmake_dependent_option(QUICKCPPLIB_USE_SYSTEM_SPAN_LITE "Whether to use embedded nonstd::span-lite. Used by various package managers such as vcpkg." OFF "NOT QUICKCPPLIB_REQUIRE_CXX20" OFF)
2331
# quickcpplib does not provide a master header file

include/quickcpplib/optional.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ Distributed under the Boost Software License, Version 1.0.
2727

2828
#include "config.hpp"
2929

30+
#include "cpp_feature.h"
31+
3032
#if !defined(QUICKCPPLIB_USE_STD_OPTIONAL)
31-
#if _HAS_CXX17 || (__cplusplus >= 201700 && (!defined(__APPLE__) || _LIBCPP_VERSION > 7000 /* approx end of 2017 */))
33+
#if _HAS_CXX17 || \
34+
(__cplusplus >= 201700 && (!defined(__APPLE__) || _LIBCPP_VERSION > 7000 /* approx end of 2017 */)) || \
35+
!defined(__cpp_exceptions)
3236
#define QUICKCPPLIB_USE_STD_OPTIONAL 1
3337
#else
3438
#define QUICKCPPLIB_USE_STD_OPTIONAL 0
@@ -48,7 +52,12 @@ namespace optional
4852

4953
QUICKCPPLIB_NAMESPACE_END
5054

51-
#else // ^^^ QUICKCPPLIB_USE_STD_OPTIONAL / not QUICKCPPLIB_USE_STD_OPTIONAL vvv
55+
#else // ^^^ QUICKCPPLIB_USE_STD_OPTIONAL / not QUICKCPPLIB_USE_STD_OPTIONAL vvv
56+
57+
#if !defined(__cpp_exceptions)
58+
#error \
59+
"Our <optional> polyfill requires C++ exceptions globally enabled. Try increasing C++ standard to 2017 or higher to enable std <optional>"
60+
#endif
5261

5362
#ifdef _MSC_VER
5463
#pragma warning(push)
@@ -68,6 +77,6 @@ namespace optional
6877

6978
QUICKCPPLIB_NAMESPACE_END
7079

71-
#endif // ^^^ not QUICKCPPLIB_USE_STD_OPTIONAL ^^^
80+
#endif // ^^^ not QUICKCPPLIB_USE_STD_OPTIONAL ^^^
7281

7382
#endif

include/quickcpplib/revision.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
2-
#define QUICKCPPLIB_PREVIOUS_COMMIT_REF 7d002f5eba98df28c81678d1341055f5792f4d7d
3-
#define QUICKCPPLIB_PREVIOUS_COMMIT_DATE "2025-02-02 18:35:50 +00:00"
4-
#define QUICKCPPLIB_PREVIOUS_COMMIT_UNIQUE 7d002f5e
2+
#define QUICKCPPLIB_PREVIOUS_COMMIT_REF 490eb2ed3b6d0176bf6b2b3c6667c182559c8bb9
3+
#define QUICKCPPLIB_PREVIOUS_COMMIT_DATE "2025-02-03 11:27:23 +00:00"
4+
#define QUICKCPPLIB_PREVIOUS_COMMIT_UNIQUE 490eb2ed

0 commit comments

Comments
 (0)