Skip to content

Commit

Permalink
Merge pull request #335 from jagerman/older-macos-avoid-std-filesystem
Browse files Browse the repository at this point in the history
Disable std::filesystem on macOS when compiling C++17 but targetting <10.15
  • Loading branch information
SRombauts authored Oct 2, 2021
2 parents ee37e4e + bfe0221 commit 4939c32
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
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

0 comments on commit 4939c32

Please sign in to comment.