diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index cc158115..7ee45d8e 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 @@ class Database { } - // 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 @@ class Database { } - #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 22012f41..a02231b2 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"));