Skip to content

Commit

Permalink
[CMake] Simplify cmake file regarding filesystem library
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Devel committed Nov 5, 2018
1 parent 8b1c12e commit 2ce5c52
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,19 @@
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt

cmake_minimum_required( VERSION 3.1 )
if(${CMAKE_VERSION} VERSION_GREATER "3.8.0")
# Honor CXX_STANDARD_REQUIRED in check_cxx_source_compiles
# (see https://cmake.org/cmake/help/v3.8/policy/CMP0067.html)
cmake_policy( SET CMP0067 NEW )
endif()

project( boostdep LANGUAGES CXX )

# Compile with c++17 if available (so we can use std::filesystem),
# but boostdep is c++98 compatible, so no CMAKE_CXX_STANDARD_REQUIRED is necessary
set( CMAKE_CXX_STANDARD 17 )
option( BOOSTDEP_USE_STD_FS "Use std::filesystem instead of boost::filesystem" OFF )

add_executable( boostdep src/boostdep.cpp )

####### options #######

# Decide if boostdep should use Boost.Filesystem or std::filesystem

# We default to using the standard library when available
# and Boost.Filesystem otherwise
# NOTE: Prior to 3.8.0 check_cxx_source_compiles will not honor the c++17 setting,
# so with older cmake versions this will never detect std::filesystem correctly
include( CheckCXXSourceCompiles )
check_cxx_source_compiles(
"
#include <filesystem>
int main() {
std::filesystem::is_directory( std::filesystem::current_path() );
}
"
has_std_filesystem )

option( BOOSTDEP_USE_STD_FS "Use std::filesystem instead of boost::filesystem" ${has_std_filesystem} )

#~~~~~~ options ~~~~~~

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).
Expand All @@ -58,5 +31,4 @@ else()

endif()


install( TARGETS boostdep RUNTIME DESTINATION bin )

0 comments on commit 2ce5c52

Please sign in to comment.