From 8d36ab83041f52ceafd36017ed4704d3427476ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Guzm=C3=A1n?= Date: Sun, 11 Dec 2022 14:39:49 -0600 Subject: [PATCH] make std::filesystem optional Add a switch to disable std::filesystem so it can be optinally disabled this should let users that older compilers versions to disable it --- CMakeLists.txt | 7 +++++++ include/SQLiteCpp/Database.h | 16 ++++++++++++++++ meson.build | 5 +++++ meson_options.txt | 2 ++ 4 files changed, 30 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cfc6e0..664035d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -294,6 +294,13 @@ else (SQLITECPP_INTERNAL_SQLITE) endif() endif (SQLITECPP_INTERNAL_SQLITE) +## disable the optional support for std::filesystem (C++17) +option(SQLITECPP_DISABLE_STD_FILESYSTEM "Disable the use of std::filesystem in SQLiteCpp." OFF) +if (SQLITECPP_DISABLE_STD_FILESYSTEM) + message (STATUS "Disabling std::filesystem support") + add_definitions(-DSQLITECPP_DISABLE_STD_FILESYSTEM) +endif (SQLITECPP_DISABLE_STD_FILESYSTEM) + # Link target with pthread and dl for Unix if (UNIX) set(THREADS_PREFER_PTHREAD_FLAG ON) diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index e9834dc..e30ff94 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -33,6 +33,22 @@ __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_13_0 #define SQLITECPP_HAVE_STD_FILESYSTEM #endif +// disable the support if the required header is not available +#ifdef __has_include + #ifndef __has_include() + #undef SQLITECPP_HAVE_STD_FILESYSTEM + #endif + #ifndef __has_include() + #undef SQLITECPP_HAVE_EXPERIMENTAL_FILESYSTEM + #endif +#endif + +// C++17 allow to disable std::filesystem support +#ifdef SQLITECPP_DISABLE_STD_FILESYSTEM + #undef SQLITECPP_HAVE_STD_FILESYSTEM + #undef SQLITECPP_HAVE_STD_EXPERIMENTAL_FILESYSTEM +#endif + #ifdef SQLITECPP_HAVE_STD_FILESYSTEM #include #endif // c++17 and a suitable compiler diff --git a/meson.build b/meson.build index 9b3ba42..3dcc642 100644 --- a/meson.build +++ b/meson.build @@ -20,6 +20,11 @@ unix_like_code = ''' ''' unix_like = cxx.compiles(unix_like_code, name : 'unix like environment') +## C++17 disable the support for std::filesystem (by default off) +if get_option('SQLITECPP_DISABLE_STD_FILESYSTEM') + sqlitecpp_cxx_flags += ['-DSQLITECPP_DISABLE_STD_FILESYSTEM'] +endif + thread_dep = dependency('threads') # sqlite3 support sqlite3_dep = dependency( diff --git a/meson_options.txt b/meson_options.txt index c9d80af..1228d85 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -9,6 +9,8 @@ option('SQLITE_ENABLE_ASSERT_HANDLER', type: 'boolean', value: false, descriptio option('SQLITE_HAS_CODEC', type: 'boolean', value: false, description: 'Enable database encryption API. Not available in the public release of SQLite.') ## Force forward declaration of legacy struct sqlite3_value (pre SQLite 3.19) option('SQLITE_USE_LEGACY_STRUCT', type: 'boolean', value: false, description: 'Fallback to forward declaration of legacy struct sqlite3_value (pre SQLite 3.19)') +## Disable the support for std::filesystem (C++17) +option('SQLITECPP_DISABLE_STD_FILESYSTEM', type: 'boolean', value: false, description: 'Disable the support for std::filesystem (C++17)') ## Enable build for the tests of SQLiteC++ option('SQLITECPP_BUILD_TESTS', type: 'boolean', value: false, description: 'Build SQLiteC++ unit tests.') ## Build the examples of SQLiteC++