diff --git a/CMakeLists.txt b/CMakeLists.txt index 5964791..16f7fc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,11 @@ endif () message(STATUS "Using c++ standard c++${CMAKE_CXX_STANDARD}") set(CMAKE_CXX_STANDARD_REQUIRED ON) +option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ON) +if(BUILD_SHARED_LIBS) +add_definitions(-DSQLITECPP_COMPILE_DLL -DSQLITECPP_EXPORT) +endif() + message (STATUS "CMake version: ${CMAKE_VERSION}") message (STATUS "Project version: ${PROJECT_VERSION}") diff --git a/include/SQLiteCpp/Backup.h b/include/SQLiteCpp/Backup.h index 578f21f..ecdd847 100644 --- a/include/SQLiteCpp/Backup.h +++ b/include/SQLiteCpp/Backup.h @@ -11,6 +11,7 @@ */ #pragma once +#include #include #include @@ -31,7 +32,7 @@ namespace SQLite * See also the a reference implementation of live backup taken from the official site: * https://www.sqlite.org/backup.html */ -class Backup +class DLL_API Backup { public: /** diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index 8fee096..21bd9d3 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -10,6 +10,7 @@ */ #pragma once +#include #include #include @@ -22,11 +23,11 @@ struct sqlite3_stmt; namespace SQLite { -extern const int INTEGER; ///< SQLITE_INTEGER -extern const int FLOAT; ///< SQLITE_FLOAT -extern const int TEXT; ///< SQLITE_TEXT -extern const int BLOB; ///< SQLITE_BLOB -extern const int Null; ///< SQLITE_NULL +DLL_API extern const int INTEGER; ///< SQLITE_INTEGER +DLL_API extern const int FLOAT; ///< SQLITE_FLOAT +DLL_API extern const int TEXT; ///< SQLITE_TEXT +DLL_API extern const int BLOB; ///< SQLITE_BLOB +DLL_API extern const int Null; ///< SQLITE_NULL /** * @brief Encapsulation of a Column in a row of the result pointed by the prepared Statement. @@ -44,7 +45,7 @@ extern const int Null; ///< SQLITE_NULL * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class Column +class DLL_API Column { public: /** @@ -241,7 +242,7 @@ private: * * @return Reference to the stream used */ -std::ostream& operator<<(std::ostream& aStream, const Column& aColumn); +DLL_API std::ostream& operator<<(std::ostream& aStream, const Column& aColumn); #if __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900) // c++14: Visual Studio 2015 diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index 3adde86..8408048 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -10,6 +10,7 @@ */ #pragma once +#include #include // c++17: MinGW GCC version > 8 @@ -84,26 +85,26 @@ namespace SQLite // Those public constants enable most usages of SQLiteCpp without including in the client application. /// The database is opened in read-only mode. If the database does not already exist, an error is returned. -extern const int OPEN_READONLY; // SQLITE_OPEN_READONLY +DLL_API extern const int OPEN_READONLY; // SQLITE_OPEN_READONLY /// The database is opened for reading and writing if possible, or reading only if the file is write protected /// by the operating system. In either case the database must already exist, otherwise an error is returned. -extern const int OPEN_READWRITE; // SQLITE_OPEN_READWRITE +DLL_API extern const int OPEN_READWRITE; // SQLITE_OPEN_READWRITE /// With OPEN_READWRITE: The database is opened for reading and writing, and is created if it does not already exist. -extern const int OPEN_CREATE; // SQLITE_OPEN_CREATE +DLL_API extern const int OPEN_CREATE; // SQLITE_OPEN_CREATE /// Enable URI filename interpretation, parsed according to RFC 3986 (ex. "file:data.db?mode=ro&cache=private") -extern const int OPEN_URI; // SQLITE_OPEN_URI +DLL_API extern const int OPEN_URI; // SQLITE_OPEN_URI /// Open in memory database -extern const int OPEN_MEMORY; // SQLITE_OPEN_MEMORY +DLL_API extern const int OPEN_MEMORY; // SQLITE_OPEN_MEMORY /// Open database in multi-thread threading mode -extern const int OPEN_NOMUTEX; // SQLITE_OPEN_NOMUTEX +DLL_API extern const int OPEN_NOMUTEX; // SQLITE_OPEN_NOMUTEX /// Open database with thread-safety in serialized threading mode -extern const int OPEN_FULLMUTEX; // SQLITE_OPEN_FULLMUTEX +DLL_API extern const int OPEN_FULLMUTEX; // SQLITE_OPEN_FULLMUTEX /// Open database with shared cache enabled -extern const int OPEN_SHAREDCACHE; // SQLITE_OPEN_SHAREDCACHE +DLL_API extern const int OPEN_SHAREDCACHE; // SQLITE_OPEN_SHAREDCACHE /// Open database with shared cache disabled -extern const int OPEN_PRIVATECACHE; // SQLITE_OPEN_PRIVATECACHE +DLL_API extern const int OPEN_PRIVATECACHE; // SQLITE_OPEN_PRIVATECACHE /// Database filename is not allowed to be a symbolic link (Note: only since SQlite 3.31.0 from 2020-01-22) -extern const int OPEN_NOFOLLOW; // SQLITE_OPEN_NOFOLLOW +DLL_API extern const int OPEN_NOFOLLOW; // SQLITE_OPEN_NOFOLLOW extern const int OK; ///< SQLITE_OK (used by check() bellow) @@ -160,7 +161,7 @@ struct Header { * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class Database +class DLL_API Database { friend class Statement; // Give Statement constructor access to the mSQLitePtr Connection Handle diff --git a/include/SQLiteCpp/Exception.h b/include/SQLiteCpp/Exception.h index eaf2542..e771dce 100644 --- a/include/SQLiteCpp/Exception.h +++ b/include/SQLiteCpp/Exception.h @@ -10,6 +10,7 @@ */ #pragma once +#include #include #include @@ -23,7 +24,7 @@ namespace SQLite /** * @brief Encapsulation of the error message from SQLite3, based on std::runtime_error. */ -class Exception : public std::runtime_error +class DLL_API Exception : public std::runtime_error { public: /** diff --git a/include/SQLiteCpp/SQLiteCpp.h b/include/SQLiteCpp/SQLiteCpp.h index c8d1801..e3b7448 100644 --- a/include/SQLiteCpp/SQLiteCpp.h +++ b/include/SQLiteCpp/SQLiteCpp.h @@ -18,6 +18,7 @@ // Include useful headers of SQLiteC++ +#include #include #include #include @@ -42,3 +43,5 @@ */ #define SQLITECPP_VERSION "3.02.01" // 3.2.1 #define SQLITECPP_VERSION_NUMBER 3002001 // 3.2.1 + + diff --git a/include/SQLiteCpp/SQLiteCppExport.h b/include/SQLiteCpp/SQLiteCppExport.h new file mode 100644 index 0000000..7242c9d --- /dev/null +++ b/include/SQLiteCpp/SQLiteCppExport.h @@ -0,0 +1,29 @@ +/** + * @file SQLiteCppExport.h + * @ingroup SQLiteCpp + * @brief File with macros needed in the generation of Windows DLLs + * + * + * Copyright (c) 2012-2022 Sebastien Rombauts (sebastien.rombauts@gmail.com) + * + * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt + * or copy at http://opensource.org/licenses/MIT) + */ + +#pragma once + +/* +* #define SQLITECPP_COMPILE_DLL to compile a DLL under Windows +* #define SQLITECPP_EXPORT to export symbols when creating the DLL, otherwise it defaults to importing symbols +*/ + +/* Windows DLL export/import */ +#if defined(WIN32) && defined(SQLITECPP_COMPILE_DLL) + #ifdef SQLITECPP_EXPORT + #define DLL_API __declspec(dllexport) + #pragma message("Exporting symbols") + #else + #define DLL_API __declspec(dllimport) + #pragma message("Importing symbols") + #endif +#endif diff --git a/include/SQLiteCpp/Savepoint.h b/include/SQLiteCpp/Savepoint.h index 0c0fba6..8a5d845 100644 --- a/include/SQLiteCpp/Savepoint.h +++ b/include/SQLiteCpp/Savepoint.h @@ -12,6 +12,7 @@ */ #pragma once +#include #include namespace SQLite @@ -53,7 +54,7 @@ class Database; * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class Savepoint +class DLL_API Savepoint { public: /** diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index e14fed0..dfdcd97 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -10,6 +10,7 @@ */ #pragma once +#include #include #include // SQLITECPP_PURE_FUNC @@ -49,7 +50,7 @@ extern const int OK; ///< SQLITE_OK * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class Statement +class DLL_API Statement { public: /** diff --git a/include/SQLiteCpp/Transaction.h b/include/SQLiteCpp/Transaction.h index af9de7e..77a3235 100644 --- a/include/SQLiteCpp/Transaction.h +++ b/include/SQLiteCpp/Transaction.h @@ -10,6 +10,7 @@ */ #pragma once +#include #include @@ -50,7 +51,7 @@ enum class TransactionBehavior { * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class Transaction +class DLL_API Transaction { public: /**