Skip to content

Commit

Permalink
Let user choose which filesystem lib (std/boost) to use
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Devel committed Nov 5, 2018
1 parent 0fd7f80 commit 9041abc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
23 changes: 21 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,28 @@ cmake_minimum_required( VERSION 3.1 )

project( boostdep LANGUAGES CXX )

option( BOOSTDEP_USE_STD_FS "Use std::filesystem instead of boost::filesystem" OFF )

add_executable( boostdep src/boostdep.cpp )

find_package( Boost COMPONENTS filesystem REQUIRED )
target_link_libraries( boostdep Boost::filesystem )
if( BOOSTDEP_USE_STD_FS )

message(STATUS "Using std::filesystem as filesystem library")

target_compile_definitions( boostdep PUBLIC BOOSTDEP_USE_STD_FS )
target_compile_features( boostdep PUBLIC cxx_std_17 )

# NOTE: Some compilers (e.g. g++-8) will require additional linker flags
# in order to use std::filesystem (e.g. -lstdc++fs).
# We are NOT handling those special cases

else()

message(STATUS "Using Boost::filesystem as filesystem library")

find_package( Boost COMPONENTS filesystem REQUIRED )
target_link_libraries( boostdep PUBLIC Boost::filesystem )

endif()

install( TARGETS boostdep RUNTIME DESTINATION bin )
25 changes: 18 additions & 7 deletions src/boostdep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#define _CRT_SECURE_NO_WARNINGS

#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <string>
#include <iostream>
#include <fstream>
Expand All @@ -23,7 +21,16 @@
#include <streambuf>
#include <sstream>

namespace fs = boost::filesystem;
#ifdef BOOSTDEP_USE_STD_FS
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
namespace fs = boost::filesystem;
#endif



// header -> module
static std::map< std::string, std::string > s_header_map;
Expand All @@ -50,7 +57,7 @@ static void scan_module_headers( fs::path const & path )

for( ; it != last; ++it )
{
if( it->status().type() == fs::directory_file )
if( fs::is_directory( it->status() ) )
{
continue;
}
Expand All @@ -76,7 +83,7 @@ static void scan_submodules( fs::path const & path )
{
fs::directory_entry const & e = *it;

if( e.status().type() != fs::directory_file )
if( !fs::is_directory( it->status() ) )
{
continue;
}
Expand Down Expand Up @@ -211,7 +218,7 @@ static void scan_module_path( fs::path const & dir, bool remove_prefix, std::map

for( ; it != last; ++it )
{
if( it->status().type() == fs::directory_file )
if( fs::is_directory( it->status() ) )
{
continue;
}
Expand All @@ -223,7 +230,11 @@ static void scan_module_path( fs::path const & dir, bool remove_prefix, std::map
header = header.substr( n+1 );
}

#ifdef BOOSTDEP_USE_STD_FS
std::ifstream is( it->path() );
#else
fs::ifstream is( it->path() );
#endif

scan_header_dependencies( header, is, deps, from );
}
Expand Down Expand Up @@ -1669,7 +1680,7 @@ static void add_module_headers( fs::path const & dir, std::set<std::string> & he

for( ; it != last; ++it )
{
if( it->status().type() == fs::directory_file )
if( fs::is_directory( it->status() ) )
{
continue;
}
Expand Down

0 comments on commit 9041abc

Please sign in to comment.