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})
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()
function(join VALUES GLUE OUTPUT)

View File

@ -283,6 +283,7 @@ if(BUILD_FAIRMQ)
if(BUILD_OFI_TRANSPORT)
target_compile_definitions(${_target} PRIVATE BUILD_OFI_TRANSPORT)
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>
Boost::boost
Boost::date_time
$<$<NOT:${FAIRMQ_HAS_STD_FILESYSTEM}>:Boost::filesystem>
Boost::program_options
FairLogger::FairLogger
PicoSHA2
@ -391,6 +393,7 @@ if(BUILD_FAIRMQ)
target_include_directories(fairmq-shmmonitor PUBLIC
$<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)
target_link_libraries(fairmq-uuid-gen PUBLIC

View File

@ -20,7 +20,6 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include <csignal>
#include <filesystem>
#include <iostream>
#include <iomanip>
#include <chrono>
@ -32,6 +31,14 @@
#include <termios.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 bie = ::boost::interprocess::interprocess_exception;
namespace bipc = ::boost::interprocess;
@ -275,12 +282,12 @@ bool Monitor::PrintShm(const ShmId& shmId)
void Monitor::ListAll(const std::string& path)
{
try {
if (std::filesystem::is_empty(path)) {
LOG(info) << "directory " << filesystem::path(path) << " is empty.";
if (fs::is_empty(path)) {
LOG(info) << "directory " << fs::path(path) << " is empty.";
return;
}
for (const auto& entry : filesystem::directory_iterator(path)) {
for (const auto& entry : fs::directory_iterator(path)) {
string filename = entry.path().filename().string();
// LOG(info) << filename << ", size: " << entry.file_size() << " bytes";
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...";
}
}
} catch (filesystem::filesystem_error& fse) {
} catch (fs::filesystem_error& fse) {
LOG(error) << "error: " << fse.what();
}
}