From a0860ba700100c0f192ccb5e3be2d4f670e9a958 Mon Sep 17 00:00:00 2001 From: Alexandre Tuleu Date: Thu, 21 Nov 2024 15:36:17 +0100 Subject: [PATCH] Allows compilation on older gcc Gcc version 7 only has access to experimental/filesystem. These simple modifications allows to discover such situation and link to --- CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ include/argparse/argparse.hpp | 7 +++++++ 2 files changed, 38 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index da38e41..53c5407 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,11 +4,42 @@ project(argparse VERSION 1.4.0 LANGUAGES CXX) include(GNUInstallDirs) + +include(CheckCXXSourceCompiles) +set(CMAKE_REQUIRED_FLAGS "--std=c++17") +check_cxx_source_compiles( + "#include +int main() { +std::filesystem::path(\"foo\"); +return 0; +}" + ARGPARSE_HAS_FILESYSTEM) +if(NOT ARGPARSE_HAS_FILESYSTEM) + set(CMAKE_REQUIRED_LIBRARIES "-lstdc++fs") + check_cxx_source_compiles( + "#include +int main() { +std::experimental::filesystem::path(\"foo\"); +return 0; +}" + ARGPARSE_HAS_EXPERIMENTAL_FILESYSTEM) + if(NOT ARGPARSE_HAS_EXPERIMENTAL_FILESYSTEM) + message( + FATAL_ERROR + "Compiler does not have either or support" + ) + endif() +endif() + # installing the header-only-library add_library(${PROJECT_NAME} INTERFACE) add_library(morrisfranken::argparse ALIAS argparse) target_compile_features(argparse INTERFACE cxx_std_17) +if(ARGPARSE_HAS_EXPERIMENTAL_FILESYSTEM) + target_compile_definitions(argparse INTERFACE "-DARGPARSE_USE_EXPERIMENTAL_FS=1") + target_link_libraries(argparse INTERFACE "-lstdc++fs") +endif() target_include_directories(argparse INTERFACE $ $) diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index 31b54db..461d9af 100755 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -35,7 +35,14 @@ #include // for allocator, shared_ptr, __shared_ptr_ac... #include // for optional, nullopt #include // for runtime_error, invalid_argument +#ifdef ARGPARSE_USE_EXPERIMENTAL_FS +#include +namespace std { + namespace filesystem = experimental::filesystem; +} +#else #include // for getting program_name from path +#endif #include // for string, operator+, basic_string, char_... #include // for declval, false_type, true_type, is_enum #include // for move, pair