Skip to content

Commit

Permalink
C++20 support
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Aug 28, 2024
1 parent a93043f commit 4a4b761
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Makefile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ else ifeq ($(shell expr match ${CXXVER} "[5-6]"),1) # gcc 5 - 6
else ifeq ($(shell expr match ${CXXVER} "[7-9]"),1) # gcc 7 - 9
NEEDED_CXXFLAGS += -std=c++17
LDLIBS = -latomic
else ifeq ($(shell expr match ${CXXVER} "1[0-9]"),2) # gcc 10+
# NEEDED_CXXFLAGS += -std=c++20
else ifeq ($(shell expr match ${CXXVER} "10"),2) # gcc 10
NEEDED_CXXFLAGS += -std=c++17
LDLIBS = -latomic
else ifeq ($(shell expr match ${CXXVER} "1[1-9]"),2) # gcc 11+
NEEDED_CXXFLAGS += -std=c++20
LDLIBS = -latomic
else # not supported
$(error Compiler too old)
endif
Expand Down
9 changes: 6 additions & 3 deletions build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,21 @@ else()
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -ffunction-sections -fdata-sections")
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "-Wl,--gc-sections") # -flto is added from above

# check for c++17 & c++11 support
# check for с++20 & c++17 & c++11 support
include(CheckCXXCompilerFlag)

CHECK_CXX_COMPILER_FLAG("-std=c++20" CXX20_SUPPORTED)
CHECK_CXX_COMPILER_FLAG("-std=c++17" CXX17_SUPPORTED)
CHECK_CXX_COMPILER_FLAG("-std=c++11" CXX11_SUPPORTED)

if(CXX17_SUPPORTED)
if(CXX20_SUPPORTED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
elseif(CXX17_SUPPORTED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
elseif(CXX11_SUPPORTED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(SEND_ERROR "C++17 nor C++11 standard not seems to be supported by compiler. Too old version?")
message(SEND_ERROR "C++20 nor C++17 nor C++11 standard not seems to be supported by compiler. Too old version?")
endif()
endif()

Expand Down
6 changes: 5 additions & 1 deletion libi2pd/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,12 @@ namespace fs {
std::error_code ec;
auto t = std::filesystem::last_write_time (path, ec);
if (ec) return 0;
auto sctp = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
#if __cplusplus >= 202002L // C++ 20 or higher
const auto sctp = std::chrono::clock_cast<std::chrono::system_clock>(t);
#else
const auto sctp = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
t - decltype(t)::clock::now() + std::chrono::system_clock::now());
#endif
return std::chrono::system_clock::to_time_t(sctp);
#else
boost::system::error_code ec;
Expand Down

0 comments on commit 4a4b761

Please sign in to comment.