Skip to content

Commit 251d97e

Browse files
committed
Target wide C++ standard applying
also export this information via cmake configuration as a part of the public interface.
1 parent 51baacb commit 251d97e

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ set(AV_ENABLE_STATIC On CACHE BOOL "Enable static library build (On)")
1616
set(AV_ENABLE_SHARED On CACHE BOOL "Enable shared library build (On)")
1717
set(AV_BUILD_EXAMPLES On CACHE BOOL "Build example applications (On)")
1818

19-
# Compiler-specific C++11 activation.
20-
set(CMAKE_CXX_STANDARD 17)
19+
# Compiler-specific C++ standard activation
20+
#set(CMAKE_CXX_STANDARD 17)
2121
set(CMAKE_CXX_STANDARD_REQUIRED yes)
2222

2323
# Warnings

src/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ foreach(TARGET ${AV_TARGETS})
3838
${CMAKE_CURRENT_SOURCE_DIR})
3939
set_target_properties(${TARGET} PROPERTIES PUBLIC_HEADER "${AV_HEADERS}")
4040

41+
# If not CMAKE_CXX_STANARD provided globally (subproject), use latest supported one
42+
if (NOT CMAKE_CXX_STANDARD)
43+
if ("cxx_std_26" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
44+
target_compile_features(${TARGET} PUBLIC cxx_std_26)
45+
elseif ("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
46+
target_compile_features(${TARGET} PUBLIC cxx_std_23)
47+
elseif("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
48+
target_compile_features(${TARGET} PUBLIC cxx_std_20)
49+
else()
50+
target_compile_features(${TARGET} PUBLIC cxx_std_17)
51+
endif()
52+
endif()
53+
4154
if(WIN32)
4255
target_link_libraries(${TARGET} PRIVATE ws2_32)
4356
endif()

src/avutils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ extern "C" {
4545
# define FF_ENABLE_DEPRECATION_WARNINGS
4646
#endif
4747

48+
#if __has_include(<compare>)
49+
# include <compare>
50+
# if defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907
51+
# define AVCPP_USE_SPACESHIP_OPERATOR 1
52+
# endif
53+
#endif
54+
55+
4856
//
4957
// Functions
5058
//

src/rational.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
#include <memory>
66
#include <type_traits>
77

8-
#if __cplusplus > 201703L
9-
#include <compare>
10-
#endif
11-
128
#include "ffmpeg.h"
9+
#include "avutils.h"
10+
11+
#ifdef AVCPP_USE_SPACESHIP_OPERATOR
12+
# include <compare>
13+
#endif
1314

1415
namespace av
1516
{
@@ -50,7 +51,7 @@ class Rational
5051
Rational& operator= (double value) noexcept;
5152

5253
bool operator== (const Rational &other) const noexcept;
53-
#if __cplusplus > 201703L
54+
#ifdef AVCPP_USE_SPACESHIP_OPERATOR
5455
std::strong_ordering operator<=>(const Rational &other) const noexcept
5556
{
5657
switch (threewaycmp(other)) {

0 commit comments

Comments
 (0)