Fallback to <boost/filesystem> on GCC 7

This commit is contained in:
Dennis Klein 2021-04-08 12:49:52 +02:00 committed by Dennis Klein
parent 77bf12c8e8
commit ea9aede652
3 changed files with 22 additions and 5 deletions

View File

@ -203,6 +203,13 @@ macro(set_fairmq_defaults)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE}) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
endif() endif()
endif() endif()
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8)
set(FAIRMQ_HAS_STD_FILESYSTEM 0)
else()
set(FAIRMQ_HAS_STD_FILESYSTEM 1)
endif()
endmacro() endmacro()
function(join VALUES GLUE OUTPUT) function(join VALUES GLUE OUTPUT)

View File

@ -283,6 +283,7 @@ if(BUILD_FAIRMQ)
if(BUILD_OFI_TRANSPORT) if(BUILD_OFI_TRANSPORT)
target_compile_definitions(${_target} PRIVATE BUILD_OFI_TRANSPORT) target_compile_definitions(${_target} PRIVATE BUILD_OFI_TRANSPORT)
endif() endif()
target_compile_definitions(${_target} PUBLIC FAIRMQ_HAS_STD_FILESYSTEM=${FAIRMQ_HAS_STD_FILESYSTEM})
####################### #######################
@ -384,6 +385,7 @@ if(BUILD_FAIRMQ)
$<$<PLATFORM_ID:Linux>:rt> $<$<PLATFORM_ID:Linux>:rt>
Boost::boost Boost::boost
Boost::date_time Boost::date_time
$<$<NOT:${FAIRMQ_HAS_STD_FILESYSTEM}>:Boost::filesystem>
Boost::program_options Boost::program_options
FairLogger::FairLogger FairLogger::FairLogger
PicoSHA2 PicoSHA2
@ -391,6 +393,7 @@ if(BUILD_FAIRMQ)
target_include_directories(fairmq-shmmonitor PUBLIC target_include_directories(fairmq-shmmonitor PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}> $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
) )
target_compile_definitions(fairmq-shmmonitor PUBLIC FAIRMQ_HAS_STD_FILESYSTEM=${FAIRMQ_HAS_STD_FILESYSTEM})
add_executable(fairmq-uuid-gen tools/runUuidGenerator.cxx) add_executable(fairmq-uuid-gen tools/runUuidGenerator.cxx)
target_link_libraries(fairmq-uuid-gen PUBLIC target_link_libraries(fairmq-uuid-gen PUBLIC

View File

@ -20,7 +20,6 @@
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include <csignal> #include <csignal>
#include <filesystem>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <chrono> #include <chrono>
@ -32,6 +31,14 @@
#include <termios.h> #include <termios.h>
#include <poll.h> #include <poll.h>
#if FAIRMQ_HAS_STD_FILESYSTEM
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <boost/filesystem.hpp>
namespace fs = ::boost::filesystem;
#endif
using namespace std; using namespace std;
using bie = ::boost::interprocess::interprocess_exception; using bie = ::boost::interprocess::interprocess_exception;
namespace bipc = ::boost::interprocess; namespace bipc = ::boost::interprocess;
@ -275,12 +282,12 @@ bool Monitor::PrintShm(const ShmId& shmId)
void Monitor::ListAll(const std::string& path) void Monitor::ListAll(const std::string& path)
{ {
try { try {
if (std::filesystem::is_empty(path)) { if (fs::is_empty(path)) {
LOG(info) << "directory " << filesystem::path(path) << " is empty."; LOG(info) << "directory " << fs::path(path) << " is empty.";
return; return;
} }
for (const auto& entry : filesystem::directory_iterator(path)) { for (const auto& entry : fs::directory_iterator(path)) {
string filename = entry.path().filename().string(); string filename = entry.path().filename().string();
// LOG(info) << filename << ", size: " << entry.file_size() << " bytes"; // LOG(info) << filename << ", size: " << entry.file_size() << " bytes";
if (tools::StrStartsWith(filename, "fmq_") || tools::StrStartsWith(filename, "sem.fmq_")) { if (tools::StrStartsWith(filename, "fmq_") || tools::StrStartsWith(filename, "sem.fmq_")) {
@ -296,7 +303,7 @@ void Monitor::ListAll(const std::string& path)
LOG(info) << "The file '" << filename << "' does not belong to FairMQ, skipping..."; LOG(info) << "The file '" << filename << "' does not belong to FairMQ, skipping...";
} }
} }
} catch (filesystem::filesystem_error& fse) { } catch (fs::filesystem_error& fse) {
LOG(error) << "error: " << fse.what(); LOG(error) << "error: " << fse.what();
} }
} }