Skip to content

Commit

Permalink
Target wide C++ standard applying
Browse files Browse the repository at this point in the history
also export this information via cmake configuration as a part of the
public interface.
h4tr3d committed Jan 13, 2025
1 parent 51baacb commit 251d97e
Showing 4 changed files with 29 additions and 7 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@ set(AV_ENABLE_STATIC On CACHE BOOL "Enable static library build (On)")
set(AV_ENABLE_SHARED On CACHE BOOL "Enable shared library build (On)")
set(AV_BUILD_EXAMPLES On CACHE BOOL "Build example applications (On)")

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

# Warnings
13 changes: 13 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -38,6 +38,19 @@ foreach(TARGET ${AV_TARGETS})
${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(${TARGET} PROPERTIES PUBLIC_HEADER "${AV_HEADERS}")

# If not CMAKE_CXX_STANARD provided globally (subproject), use latest supported one
if (NOT CMAKE_CXX_STANDARD)
if ("cxx_std_26" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
target_compile_features(${TARGET} PUBLIC cxx_std_26)
elseif ("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
target_compile_features(${TARGET} PUBLIC cxx_std_23)
elseif("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
target_compile_features(${TARGET} PUBLIC cxx_std_20)
else()
target_compile_features(${TARGET} PUBLIC cxx_std_17)
endif()
endif()

if(WIN32)
target_link_libraries(${TARGET} PRIVATE ws2_32)
endif()
8 changes: 8 additions & 0 deletions src/avutils.h
Original file line number Diff line number Diff line change
@@ -45,6 +45,14 @@ extern "C" {
# define FF_ENABLE_DEPRECATION_WARNINGS
#endif

#if __has_include(<compare>)
# include <compare>
# if defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907
# define AVCPP_USE_SPACESHIP_OPERATOR 1
# endif
#endif


//
// Functions
//
11 changes: 6 additions & 5 deletions src/rational.h
Original file line number Diff line number Diff line change
@@ -5,11 +5,12 @@
#include <memory>
#include <type_traits>

#if __cplusplus > 201703L
#include <compare>
#endif

#include "ffmpeg.h"
#include "avutils.h"

#ifdef AVCPP_USE_SPACESHIP_OPERATOR
# include <compare>
#endif

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

bool operator== (const Rational &other) const noexcept;
#if __cplusplus > 201703L
#ifdef AVCPP_USE_SPACESHIP_OPERATOR
std::strong_ordering operator<=>(const Rational &other) const noexcept
{
switch (threewaycmp(other)) {

0 comments on commit 251d97e

Please sign in to comment.