From 44a527958b982aca8f6b80c41cf60e316c298623 Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Mon, 15 Oct 2018 18:28:28 +0200 Subject: [PATCH 1/3] [FS] Let user choose which filesystem lib (std/boost) to use --- CMakeLists.txt | 23 +++++++++++++++++++++-- src/boostdep.cpp | 25 ++++++++++++++++++------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bc5834..c134974 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ) diff --git a/src/boostdep.cpp b/src/boostdep.cpp index f517d2d..27488c0 100644 --- a/src/boostdep.cpp +++ b/src/boostdep.cpp @@ -9,8 +9,6 @@ #define _CRT_SECURE_NO_WARNINGS -#include -#include #include #include #include @@ -23,7 +21,16 @@ #include #include -namespace fs = boost::filesystem; +#ifdef BOOSTDEP_USE_STD_FS + #include + namespace fs = std::filesystem; +#else + #include + #include + namespace fs = boost::filesystem; +#endif + + // header -> module static std::map< std::string, std::string > s_header_map; @@ -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; } @@ -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; } @@ -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; } @@ -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 ); } @@ -1669,7 +1680,7 @@ static void add_module_headers( fs::path const & dir, std::set & he for( ; it != last; ++it ) { - if( it->status().type() == fs::directory_file ) + if( fs::is_directory( it->status() ) ) { continue; } From ed35ff147d5403b5c7bdaa89a78e385602939a72 Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Fri, 2 Nov 2018 12:32:30 +0100 Subject: [PATCH 2/3] [CI/FS] Check that cmake build works with gcc-8 --- .travis.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.travis.yml b/.travis.yml index d39de22..31a13f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -102,6 +102,23 @@ matrix: compiler: clang++ env: TOOLSET=clang CXXSTD=03,11,14,1z + - os: linux + compiler: g++ + env: CMAKE=1 + addons: + apt: + packages: + - libboost-filesystem-dev + - g++-8 + sources: + - ubuntu-toolchain-r-test + install: true + script: + - export CC=gcc-8 && export CXX=g++-8 + - mkdir __build__ && cd __build__ + - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~ .. + - cmake --build . --target install + - os: linux compiler: g++ env: CMAKE=1 From 0157181d05a6819c237fb32ac689cb4e05417900 Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Mon, 5 Nov 2018 13:04:27 +0100 Subject: [PATCH 3/3] [FS] Use typdef for ifstream type instead of separate #ifdef --- src/boostdep.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/boostdep.cpp b/src/boostdep.cpp index 27488c0..3b10d12 100644 --- a/src/boostdep.cpp +++ b/src/boostdep.cpp @@ -24,10 +24,12 @@ #ifdef BOOSTDEP_USE_STD_FS #include namespace fs = std::filesystem; + typedef std::ifstream ifstream_t; #else #include #include namespace fs = boost::filesystem; + typedef fs::ifstream ifstream_t; #endif @@ -230,11 +232,7 @@ 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 + ifstream_t is( it->path() ); scan_header_dependencies( header, is, deps, from ); }