From 4c718643195216c1e56d0db4ab6bf13584a24086 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 16 Mar 2019 20:30:38 +0100 Subject: [PATCH] Fix for gcc < 5.0 --- src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt | 12 ++++++++++++ src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt b/src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt index 936f4c05f..69dd5c022 100644 --- a/src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt @@ -58,6 +58,18 @@ if(Boost_VERSION LESS 105800) target_compile_definitions(pvt_gr_blocks PRIVATE -DOLD_BOOST=1) endif() +# Check if we have std::put_time (Workaround for gcc < 5.0) +include(CheckCXXSourceCompiles) +check_cxx_source_compiles(" + #include + int main() + { std::put_time(nullptr, \"\"); }" + HAS_PUT_TIME +) +if(${HAS_PUT_TIME}) + target_compile_definitions(pvt_gr_blocks PRIVATE -DHAS_PUT_TIME=1) +endif() + set_property(TARGET pvt_gr_blocks APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $ diff --git a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc index 09e49a576..22915cca5 100644 --- a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc +++ b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc @@ -369,7 +369,9 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels, time_t when = std::time(nullptr); auto const tm = *std::localtime(&when); std::ostringstream os; +#ifdef HAS_PUT_TIME os << std::put_time(&tm, "%z"); +#endif std::string utc_diff_str = os.str(); // in ISO 8601 format: "+HHMM" or "-HHMM" if (utc_diff_str.empty()) { @@ -379,7 +381,9 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels, int m = std::stoi(utc_diff_str[0] + utc_diff_str.substr(3), nullptr, 10); d_utc_diff_time = boost::posix_time::hours(h) + boost::posix_time::minutes(m); std::ostringstream os2; +#ifdef HAS_PUT_TIME os2 << std::put_time(&tm, "%Z"); +#endif std::string time_zone_abrv = os2.str(); if (time_zone_abrv.empty()) {