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 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..3b10d12 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,18 @@ #include #include -namespace fs = boost::filesystem; +#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 + + // header -> module static std::map< std::string, std::string > s_header_map; @@ -50,7 +59,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 +85,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 +220,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 +232,7 @@ static void scan_module_path( fs::path const & dir, bool remove_prefix, std::map header = header.substr( n+1 ); } - fs::ifstream is( it->path() ); + ifstream_t is( it->path() ); scan_header_dependencies( header, is, deps, from ); } @@ -1669,7 +1678,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; }