Skip to content

Commit

Permalink
Refactored to std filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchmitz committed Jun 22, 2021
1 parent 299aa51 commit 4f0da36
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 62 deletions.
6 changes: 0 additions & 6 deletions environment/cmake/PCRaster.cmake
Expand Up @@ -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)
Expand Down
51 changes: 28 additions & 23 deletions environment/cmake/PCRasterConfiguration.cmake
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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)
# <<<

3 changes: 0 additions & 3 deletions source/CMakeLists.txt
Expand Up @@ -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})

Expand Down
4 changes: 2 additions & 2 deletions source/modflow/src/mf_utils.cc
@@ -1,11 +1,11 @@
#include "mf_utils.h"

#include <boost/filesystem.hpp>
#include <filesystem>
#include <iostream>



namespace fs = boost::filesystem;
namespace fs = std::filesystem;


namespace mf {
Expand Down
14 changes: 6 additions & 8 deletions source/modflow/src/pcrmodflow.cc
Expand Up @@ -20,10 +20,6 @@
#define INCLUDED_FSTREAM
#endif

#ifndef INCLUDED_BOOST_FILESYSTEM
#include <boost/filesystem.hpp>
#define INCLUDED_BOOST_FILESYSTEM
#endif

//#ifndef INCLUDED_BOOST_BIND
//#include <boost/bind.hpp>
Expand Down Expand Up @@ -140,6 +136,8 @@
#include <QProcess>
#include <QString>

#include <filesystem>


/// \todo change the confined level vector to layer vector

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion source/pcraster_dal/CMakeLists.txt
Expand Up @@ -145,7 +145,6 @@ target_link_libraries(pcraster_dal
pcraster::utils
Qt5::Sql
GDAL::GDAL
Boost::filesystem
Boost::date_time
)

Expand Down
4 changes: 2 additions & 2 deletions source/pcraster_model_engine/calc_clientinterfacetest.cc
Expand Up @@ -2,8 +2,6 @@
#include <boost/test/unit_test.hpp>
#include "stddefx.h"
#include <algorithm>
#include <boost/filesystem.hpp>
namespace fs=boost::filesystem;

#include "appargs.h"
#include "calc_comparefilewithvalidated.h"
Expand All @@ -18,6 +16,8 @@ namespace fs=boost::filesystem;
#include "calc_xmlreflection.h"
#include "calc_spatial.h"

#include <filesystem>
namespace fs = std::filesystem;

namespace calc {
namespace detail {
Expand Down
9 changes: 4 additions & 5 deletions source/pcraster_model_engine/calc_comparefilewithvalidated.cc
Expand Up @@ -16,11 +16,10 @@
// PCRaster library headers.

// Module headers.
#ifndef INCLUDED_BOOST_FILESYSTEM
#include <boost/filesystem.hpp>
#define INCLUDED_BOOST_FILESYSTEM
#endif
namespace fs=boost::filesystem;

#include <filesystem>

namespace fs = std::filesystem;



Expand Down
8 changes: 3 additions & 5 deletions source/pcraster_model_engine/calc_linkinlibrary.cc
Expand Up @@ -13,10 +13,6 @@
#include <sstream>
#define INCLUDED_SSTREAM
#endif
#ifndef INCLUDED_BOOST_FILESYSTEM
#include <boost/filesystem.hpp>
#define INCLUDED_BOOST_FILESYSTEM
#endif
// PCRaster library headers.

#ifndef INCLUDED_PCRLINKIN
Expand Down Expand Up @@ -51,6 +47,8 @@
#define INCLUDED_CALC_XMLDATATYPE
#endif

#include <filesystem>

/*!
\file
This file contains the implementation of the LinkInLibrary class.
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions source/pcraster_old_calc/calc_ioesrifieldstrategy.cc
Expand Up @@ -13,10 +13,6 @@
#include <vector>
#define INCLUDED_VECTOR
#endif
#ifndef INCLUDED_BOOST_FILESYSTEM
#include <boost/filesystem.hpp>
#define INCLUDED_BOOST_FILESYSTEM
#endif

#ifndef INCLUDED_STDEXCEPT
#include <stdexcept>
Expand Down Expand Up @@ -92,6 +88,8 @@
#define INCLUDED_CALC_STACKINFO
#endif

#include <filesystem>

/*!
\file
This file contains the implementation of the IoEsriFieldStrategy class.
Expand Down Expand Up @@ -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());
Expand Down
1 change: 0 additions & 1 deletion source/pcrcom/CMakeLists.txt
Expand Up @@ -90,7 +90,6 @@ target_include_directories(pcrcom
target_link_libraries(pcrcom
PUBLIC
pcraster::misc
Boost::filesystem

# For dlopen in com_dynamiclibrary.
$<$<BOOL:${UNIX}>:${CMAKE_DL_LIBS}>
Expand Down
1 change: 0 additions & 1 deletion source/utils/CMakeLists.txt
Expand Up @@ -27,7 +27,6 @@ target_include_directories(utils

target_link_libraries(utils
PRIVATE
Boost::filesystem
Boost::program_options
XercesC::XercesC
GDAL::GDAL
Expand Down

0 comments on commit 4f0da36

Please sign in to comment.