From bfe0221b8c3870752102f447245a12555009ca8b Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Thu, 19 Aug 2021 22:01:23 -0300 Subject: [PATCH] Disable std::filesystem on macOS targetting <10.15 macOS flat out refuses to compile if you touch std::filesystem when targetting macOS < 10.15 (to be able to deploy a binary to older macOS versions). This disables the std::filesystem support when in C++17 mode with such a target. --- include/SQLiteCpp/Database.h | 25 +++++++++++++++++++------ tests/Database_test.cpp | 9 +++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index cc15811..7ee45d8 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -14,9 +14,24 @@ // c++17: MinGW GCC version > 8 // c++17: Visual Studio 2017 version 15.7 -#if ((__cplusplus >= 201703L) && ((!defined(__MINGW32__) && !defined(__MINGW64__)) || (__GNUC__ > 8))) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)) // NOLINT +// c++17: macOS unless targetting compatibility with macOS < 10.15 +#if __cplusplus >= 201703L + #if defined(__MINGW32__) || defined(__MINGW64__) + #if __GNUC__ > 8 // MinGW requires GCC version > 8 for std::filesystem + #define SQLITECPP_HAVE_STD_FILESYSTEM + #endif + #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 + // macOS clang won't less us touch std::filesystem if we're targetting earlier than 10.15 + #else + #define SQLITECPP_HAVE_STD_FILESYSTEM + #endif +#elif defined(_MSVC_LANG) && _MSVC_LANG >= 201703L + #define SQLITECPP_HAVE_STD_FILESYSTEM +#endif + +#ifdef SQLITECPP_HAVE_STD_FILESYSTEM #include -#endif // c++17 +#endif // c++17 and a suitable compiler #include #include @@ -167,9 +182,7 @@ public: { } - // c++17: MinGW GCC version > 8 - // c++17: Visual Studio 2017 version 15.7 - #if ((__cplusplus >= 201703L) && ((!defined(__MINGW32__) && !defined(__MINGW64__)) || (__GNUC__ > 8))) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)) // NOLINT + #ifdef SQLITECPP_HAVE_STD_FILESYSTEM /** * @brief Open the provided database std::filesystem::path. @@ -199,7 +212,7 @@ public: { } - #endif // c++17 + #endif // have std::filesystem // Database is non-copyable Database(const Database&) = delete; diff --git a/tests/Database_test.cpp b/tests/Database_test.cpp index 22012f4..a02231b 100644 --- a/tests/Database_test.cpp +++ b/tests/Database_test.cpp @@ -15,7 +15,7 @@ #include -#if (__cplusplus >= 201703L) || ( defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)) // c++17: Visual Studio 2017 version 15.7 +#ifdef SQLITECPP_HAVE_STD_FILESYSTEM #include #endif // c++17 @@ -50,12 +50,13 @@ TEST(Database, ctorExecCreateDropExist) std::string filename = "test.db3"; EXPECT_THROW(SQLite::Database not_found(filename), SQLite::Exception); - // Create a new database using a string or a std::filesystem::path if using c++17 - #if (__cplusplus >= 201703L) || ( defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)) // c++17: Visual Studio 2017 version 15.7 + // Create a new database using a string or a std::filesystem::path if using c++17 and a + // compatible compiler + #ifdef SQLITECPP_HAVE_STD_FILESYSTEM SQLite::Database db(std::filesystem::path("test.db3"), SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); #else SQLite::Database db("test.db3", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); - #endif // c++17 + #endif // have std::filesystem EXPECT_STREQ("test.db3", db.getFilename().c_str()); EXPECT_FALSE(db.tableExists("test"));