Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable std::filesystem on macOS when compiling C++17 but targetting <10.15 #335

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions include/SQLiteCpp/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <filesystem>
#endif // c++17
#endif // c++17 and a suitable compiler

#include <memory>
#include <string.h>
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -199,7 +212,7 @@ class Database
{
}

#endif // c++17
#endif // have std::filesystem

// Database is non-copyable
Database(const Database&) = delete;
Expand Down
9 changes: 5 additions & 4 deletions tests/Database_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include <gtest/gtest.h>

#if (__cplusplus >= 201703L) || ( defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)) // c++17: Visual Studio 2017 version 15.7
#ifdef SQLITECPP_HAVE_STD_FILESYSTEM
#include <filesystem>
#endif // c++17

Expand Down Expand Up @@ -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"));
Expand Down