From 4f0da36389f595043de3a44cd2876c5a66f010c2 Mon Sep 17 00:00:00 2001 From: Oliver Schmitz Date: Tue, 22 Jun 2021 09:10:49 +0200 Subject: [PATCH] Refactored to std filesystem --- environment/cmake/PCRaster.cmake | 6 --- environment/cmake/PCRasterConfiguration.cmake | 51 ++++++++++--------- source/CMakeLists.txt | 3 -- source/modflow/src/mf_utils.cc | 4 +- source/modflow/src/pcrmodflow.cc | 14 +++-- source/pcraster_dal/CMakeLists.txt | 1 - .../calc_clientinterfacetest.cc | 4 +- .../calc_comparefilewithvalidated.cc | 9 ++-- .../calc_linkinlibrary.cc | 8 ++- .../calc_ioesrifieldstrategy.cc | 8 ++- source/pcrcom/CMakeLists.txt | 1 - source/utils/CMakeLists.txt | 1 - 12 files changed, 48 insertions(+), 62 deletions(-) diff --git a/environment/cmake/PCRaster.cmake b/environment/cmake/PCRaster.cmake index 400b329a..bfb08881 100644 --- a/environment/cmake/PCRaster.cmake +++ b/environment/cmake/PCRaster.cmake @@ -20,12 +20,6 @@ include(PCRasterCompilerConfiguration) include(DevBaseExternal) include(DevBaseMacro) -if(PCRASTER_BUILD_TEST) - enable_testing() - if(NOT GDAL_TRANSLATE) - message(FATAL_ERROR "gdal_translate executable not found") - endif() -endif() set(PCRASTER_DATA_DIR ${PROJECT_SOURCE_DIR}/data) diff --git a/environment/cmake/PCRasterConfiguration.cmake b/environment/cmake/PCRasterConfiguration.cmake index 27e84181..b127c18d 100644 --- a/environment/cmake/PCRasterConfiguration.cmake +++ b/environment/cmake/PCRasterConfiguration.cmake @@ -128,19 +128,18 @@ if(PCRASTER_BUILD_MULTICORE) endif() endif() + # Ugly workaround to enforce working wrt conda-build -# TODO: Refactor when all platforms support std filesystem +# TODO: Refactor when no more boost dependency required at runtime # Consider to move to Qt command line options as well # to remove (release package) dependency on Boost if(PCRASTER_LINK_STATIC_BOOST) - set(DEVBASE_BOOST_REQUIRED TRUE) - set(Boost_NO_BOOST_CMAKE ON) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_RUNTIME OFF) - find_package(Boost COMPONENTS system unit_test_framework date_time filesystem program_options timer) + find_package(Boost 1.60 COMPONENTS unit_test_framework date_time program_options timer) if(NOT Boost_FOUND) message(FATAL_ERROR "Boost not found") @@ -149,33 +148,21 @@ if(PCRASTER_LINK_STATIC_BOOST) message(STATUS " libraries: ${Boost_LIBRARIES}") endif() - add_definitions(-DBOOST_FILESYSTEM_NO_DEPRECATED) - else() - - set(DEVBASE_BOOST_REQUIRED TRUE) - set(Boost_NO_BOOST_CMAKE ON) + list(APPEND PCR_BOOST_COMPONENTS date_time program_options timer) if(PCRASTER_BUILD_TEST) - set(DEVBASE_BUILD_TEST TRUE) - list(APPEND DEVBASE_REQUIRED_BOOST_COMPONENTS - system unit_test_framework) - - # The ones below are required in case a developer needs to - # regenerate one of the pcraster_model_engine's XML files - # set(DEVBASE_LIB_XSLT_XSLTPROC_REQUIRED TRUE) - # set(DEVBASE_LIB_XML2_REQUIRED TRUE) - # set(DEVBASE_LIB_XSLT_REQUIRED TRUE) - # - # ... or XSD - # set(DEVBASE_XSD_REQUIRED TRUE) + enable_testing() + list(APPEND PCR_BOOST_COMPONENTS unit_test_framework) endif() - list(APPEND DEVBASE_REQUIRED_BOOST_COMPONENTS - date_time filesystem program_options timer) + find_package(Boost 1.60 REQUIRED COMPONENTS ${PCR_BOOST_COMPONENTS}) endif() + + + set(DEVBASE_QT_REQUIRED TRUE) set(DEVBASE_REQUIRED_QT_VERSION 5) set(DEVBASE_REQUIRED_QT_COMPONENTS @@ -209,6 +196,12 @@ else() message(FATAL_ERROR "GDAL data dir not found") endif() +if(PCRASTER_BUILD_TEST) + if(NOT GDAL_TRANSLATE) + message(FATAL_ERROR "gdal_translate executable not found") + endif() +endif() + find_package(Python3 COMPONENTS Interpreter Development NumPy) message(STATUS " Interpreter ID: " ${Python3_INTERPRETER_ID}) @@ -279,3 +272,15 @@ if(NOT PYBIND11_SYSTEM_INCLUDE) else() find_package(pybind11 REQUIRED) endif() + + +# >>> The ones below are required in case a developer needs to +# regenerate one of the pcraster_model_engine's XML files +# set(DEVBASE_LIB_XSLT_XSLTPROC_REQUIRED TRUE) +# set(DEVBASE_LIB_XML2_REQUIRED TRUE) +# set(DEVBASE_LIB_XSLT_REQUIRED TRUE) +# +# ... or XSD +# set(DEVBASE_XSD_REQUIRED TRUE) +# <<< + diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 1df477bc..ea20c136 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -129,9 +129,6 @@ set(LIBS_PATH "") if(PCRASTER_PACKAGE_BOOST) - get_dependent_so(var Boost::filesystem) - list(APPEND LIBS_PATH ${var}) - get_dependent_so(var Boost::date_time) list(APPEND LIBS_PATH ${var}) diff --git a/source/modflow/src/mf_utils.cc b/source/modflow/src/mf_utils.cc index 8cfc66bb..59b4111a 100644 --- a/source/modflow/src/mf_utils.cc +++ b/source/modflow/src/mf_utils.cc @@ -1,11 +1,11 @@ #include "mf_utils.h" -#include +#include #include -namespace fs = boost::filesystem; +namespace fs = std::filesystem; namespace mf { diff --git a/source/modflow/src/pcrmodflow.cc b/source/modflow/src/pcrmodflow.cc index 74cd713f..c63c9b5c 100644 --- a/source/modflow/src/pcrmodflow.cc +++ b/source/modflow/src/pcrmodflow.cc @@ -20,10 +20,6 @@ #define INCLUDED_FSTREAM #endif -#ifndef INCLUDED_BOOST_FILESYSTEM -#include -#define INCLUDED_BOOST_FILESYSTEM -#endif //#ifndef INCLUDED_BOOST_BIND //#include @@ -140,6 +136,8 @@ #include #include +#include + /// \todo change the confined level vector to layer vector @@ -1016,8 +1014,8 @@ void PCRModflow::setRechargeLay(const calc::Field *rch, const calc::Field *layer void PCRModflow::removeTextFiles(std::string const & fileName) const { - if(boost::filesystem::exists(fileName)) { - boost::filesystem::remove(fileName); + if(std::filesystem::exists(fileName)) { + std::filesystem::remove(fileName); } } @@ -1258,7 +1256,7 @@ void PCRModflow::modflow_converged() { std::string filename = mf::execution_path(run_directory(), "pcrmf.lst"); - if(!boost::filesystem::exists(filename)) { + if(!std::filesystem::exists(filename)) { std::cerr << " Error in PCRasterModflow: can not open global list file " << filename << std::endl; exit(1); } @@ -1286,7 +1284,7 @@ void PCRModflow::printList() { std::string filename = mf::execution_path(run_directory(), "pcrmf.lst"); - if(!boost::filesystem::exists(filename)) { + if(!std::filesystem::exists(filename)) { std::cerr << " Error in PCRasterModflow: can not open global list file " << filename << std::endl; exit(1); } diff --git a/source/pcraster_dal/CMakeLists.txt b/source/pcraster_dal/CMakeLists.txt index 59a46e94..772fbabc 100644 --- a/source/pcraster_dal/CMakeLists.txt +++ b/source/pcraster_dal/CMakeLists.txt @@ -145,7 +145,6 @@ target_link_libraries(pcraster_dal pcraster::utils Qt5::Sql GDAL::GDAL - Boost::filesystem Boost::date_time ) diff --git a/source/pcraster_model_engine/calc_clientinterfacetest.cc b/source/pcraster_model_engine/calc_clientinterfacetest.cc index 5f0a1309..c3342e57 100644 --- a/source/pcraster_model_engine/calc_clientinterfacetest.cc +++ b/source/pcraster_model_engine/calc_clientinterfacetest.cc @@ -2,8 +2,6 @@ #include #include "stddefx.h" #include -#include -namespace fs=boost::filesystem; #include "appargs.h" #include "calc_comparefilewithvalidated.h" @@ -18,6 +16,8 @@ namespace fs=boost::filesystem; #include "calc_xmlreflection.h" #include "calc_spatial.h" +#include +namespace fs = std::filesystem; namespace calc { namespace detail { diff --git a/source/pcraster_model_engine/calc_comparefilewithvalidated.cc b/source/pcraster_model_engine/calc_comparefilewithvalidated.cc index 2f7cd7e4..4a792d33 100644 --- a/source/pcraster_model_engine/calc_comparefilewithvalidated.cc +++ b/source/pcraster_model_engine/calc_comparefilewithvalidated.cc @@ -16,11 +16,10 @@ // PCRaster library headers. // Module headers. -#ifndef INCLUDED_BOOST_FILESYSTEM -#include -#define INCLUDED_BOOST_FILESYSTEM -#endif -namespace fs=boost::filesystem; + +#include + +namespace fs = std::filesystem; diff --git a/source/pcraster_model_engine/calc_linkinlibrary.cc b/source/pcraster_model_engine/calc_linkinlibrary.cc index ec1c9bb7..ecf1bd6d 100644 --- a/source/pcraster_model_engine/calc_linkinlibrary.cc +++ b/source/pcraster_model_engine/calc_linkinlibrary.cc @@ -13,10 +13,6 @@ #include #define INCLUDED_SSTREAM #endif -#ifndef INCLUDED_BOOST_FILESYSTEM -#include -#define INCLUDED_BOOST_FILESYSTEM -#endif // PCRaster library headers. #ifndef INCLUDED_PCRLINKIN @@ -51,6 +47,8 @@ #define INCLUDED_CALC_XMLDATATYPE #endif +#include + /*! \file This file contains the implementation of the LinkInLibrary class. @@ -183,7 +181,7 @@ class LinkInLibraryPrivate if (!d_execute) throwException("code library does not contain pcr_LinkInExecute"); - boost::filesystem::path xmlFile(d_dl->directory()); + std::filesystem::path xmlFile(d_dl->directory()); xmlFile /= (d_name+".xml"); pcrxsd::DOMInput d(pcrxsd::DOMInput::CompiledIn); d.setValidate(true); diff --git a/source/pcraster_old_calc/calc_ioesrifieldstrategy.cc b/source/pcraster_old_calc/calc_ioesrifieldstrategy.cc index 483b6edc..413973d2 100644 --- a/source/pcraster_old_calc/calc_ioesrifieldstrategy.cc +++ b/source/pcraster_old_calc/calc_ioesrifieldstrategy.cc @@ -13,10 +13,6 @@ #include #define INCLUDED_VECTOR #endif -#ifndef INCLUDED_BOOST_FILESYSTEM -#include -#define INCLUDED_BOOST_FILESYSTEM -#endif #ifndef INCLUDED_STDEXCEPT #include @@ -92,6 +88,8 @@ #define INCLUDED_CALC_STACKINFO #endif +#include + /*! \file This file contains the implementation of the IoEsriFieldStrategy class. @@ -286,7 +284,7 @@ void calc::IoEsriFieldStrategy::removeOutputObject(const std::string& objName) c // other directory check that - namespace fs = boost::filesystem; + namespace fs = std::filesystem; bool isAStack = true; fs::path infoDir; fs::path stack(path.pathName().path()); diff --git a/source/pcrcom/CMakeLists.txt b/source/pcrcom/CMakeLists.txt index e56d839f..7083df08 100644 --- a/source/pcrcom/CMakeLists.txt +++ b/source/pcrcom/CMakeLists.txt @@ -90,7 +90,6 @@ target_include_directories(pcrcom target_link_libraries(pcrcom PUBLIC pcraster::misc - Boost::filesystem # For dlopen in com_dynamiclibrary. $<$:${CMAKE_DL_LIBS}> diff --git a/source/utils/CMakeLists.txt b/source/utils/CMakeLists.txt index a6088e0d..969242d0 100644 --- a/source/utils/CMakeLists.txt +++ b/source/utils/CMakeLists.txt @@ -27,7 +27,6 @@ target_include_directories(utils target_link_libraries(utils PRIVATE - Boost::filesystem Boost::program_options XercesC::XercesC GDAL::GDAL