Skip to content

Commit 3ef5b1d

Browse files
authored
Merge pull request SRombauts#406 Dllexport import from pierre-aimi/dllexport_import
2 parents f6eaa11 + 82afee6 commit 3ef5b1d

File tree

14 files changed

+152
-80
lines changed

14 files changed

+152
-80
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ if (SQLITE_USE_LEGACY_STRUCT)
213213
target_compile_definitions(SQLiteCpp PUBLIC SQLITE_USE_LEGACY_STRUCT)
214214
endif (SQLITE_USE_LEGACY_STRUCT)
215215

216+
if(BUILD_SHARED_LIBS)
217+
if(WIN32)
218+
add_definitions("-DSQLITECPP_COMPILE_DLL")
219+
target_compile_definitions(SQLiteCpp PRIVATE "SQLITECPP_DLL_EXPORT")
220+
endif()
221+
endif()
222+
216223
option(SQLITE_OMIT_LOAD_EXTENSION "Enable omit load extension" OFF)
217224
if (SQLITE_OMIT_LOAD_EXTENSION)
218225
# Enable the user definition of load_extension().
@@ -402,8 +409,10 @@ endif (SQLITECPP_RUN_DOXYGEN)
402409

403410
option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF)
404411
if (SQLITECPP_BUILD_EXAMPLES)
412+
405413
# add the basic example executable
406414
add_executable(SQLiteCpp_example1 ${SQLITECPP_EXAMPLES})
415+
407416
target_link_libraries(SQLiteCpp_example1 SQLiteCpp)
408417
if (MSYS OR MINGW)
409418
target_link_libraries(SQLiteCpp_example1 ssp)

include/SQLiteCpp/Backup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
#pragma once
1313

14+
#include <SQLiteCpp/SQLiteCppExport.h>
1415
#include <SQLiteCpp/Database.h>
1516

1617
#include <string>
@@ -31,7 +32,7 @@ namespace SQLite
3132
* See also the a reference implementation of live backup taken from the official site:
3233
* https://www.sqlite.org/backup.html
3334
*/
34-
class Backup
35+
class SQLITECPP_API Backup
3536
{
3637
public:
3738
/**

include/SQLiteCpp/Column.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
#pragma once
1212

13+
#include <SQLiteCpp/SQLiteCppExport.h>
1314
#include <SQLiteCpp/Statement.h>
1415
#include <SQLiteCpp/Exception.h>
1516

@@ -22,11 +23,11 @@ struct sqlite3_stmt;
2223
namespace SQLite
2324
{
2425

25-
extern const int INTEGER; ///< SQLITE_INTEGER
26-
extern const int FLOAT; ///< SQLITE_FLOAT
27-
extern const int TEXT; ///< SQLITE_TEXT
28-
extern const int BLOB; ///< SQLITE_BLOB
29-
extern const int Null; ///< SQLITE_NULL
26+
SQLITECPP_API extern const int INTEGER; ///< SQLITE_INTEGER
27+
SQLITECPP_API extern const int FLOAT; ///< SQLITE_FLOAT
28+
SQLITECPP_API extern const int TEXT; ///< SQLITE_TEXT
29+
SQLITECPP_API extern const int BLOB; ///< SQLITE_BLOB
30+
SQLITECPP_API extern const int Null; ///< SQLITE_NULL
3031

3132
/**
3233
* @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
4445
* because of the way it shares the underling SQLite precompiled statement
4546
* in a custom shared pointer (See the inner class "Statement::Ptr").
4647
*/
47-
class Column
48+
class SQLITECPP_API Column
4849
{
4950
public:
5051
/**
@@ -241,7 +242,7 @@ class Column
241242
*
242243
* @return Reference to the stream used
243244
*/
244-
std::ostream& operator<<(std::ostream& aStream, const Column& aColumn);
245+
SQLITECPP_API std::ostream& operator<<(std::ostream& aStream, const Column& aColumn);
245246

246247
#if __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900) // c++14: Visual Studio 2015
247248

include/SQLiteCpp/Database.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
#pragma once
1212

13+
#include <SQLiteCpp/SQLiteCppExport.h>
1314
#include <SQLiteCpp/Column.h>
1415

1516
// c++17: MinGW GCC version > 8
@@ -84,37 +85,37 @@ namespace SQLite
8485
// Those public constants enable most usages of SQLiteCpp without including <sqlite3.h> in the client application.
8586

8687
/// The database is opened in read-only mode. If the database does not already exist, an error is returned.
87-
extern const int OPEN_READONLY; // SQLITE_OPEN_READONLY
88+
SQLITECPP_API extern const int OPEN_READONLY; // SQLITE_OPEN_READONLY
8889
/// The database is opened for reading and writing if possible, or reading only if the file is write protected
8990
/// by the operating system. In either case the database must already exist, otherwise an error is returned.
90-
extern const int OPEN_READWRITE; // SQLITE_OPEN_READWRITE
91+
SQLITECPP_API extern const int OPEN_READWRITE; // SQLITE_OPEN_READWRITE
9192
/// With OPEN_READWRITE: The database is opened for reading and writing, and is created if it does not already exist.
92-
extern const int OPEN_CREATE; // SQLITE_OPEN_CREATE
93+
SQLITECPP_API extern const int OPEN_CREATE; // SQLITE_OPEN_CREATE
9394
/// Enable URI filename interpretation, parsed according to RFC 3986 (ex. "file:data.db?mode=ro&cache=private")
94-
extern const int OPEN_URI; // SQLITE_OPEN_URI
95+
SQLITECPP_API extern const int OPEN_URI; // SQLITE_OPEN_URI
9596
/// Open in memory database
96-
extern const int OPEN_MEMORY; // SQLITE_OPEN_MEMORY
97+
SQLITECPP_API extern const int OPEN_MEMORY; // SQLITE_OPEN_MEMORY
9798
/// Open database in multi-thread threading mode
98-
extern const int OPEN_NOMUTEX; // SQLITE_OPEN_NOMUTEX
99+
SQLITECPP_API extern const int OPEN_NOMUTEX; // SQLITE_OPEN_NOMUTEX
99100
/// Open database with thread-safety in serialized threading mode
100-
extern const int OPEN_FULLMUTEX; // SQLITE_OPEN_FULLMUTEX
101+
SQLITECPP_API extern const int OPEN_FULLMUTEX; // SQLITE_OPEN_FULLMUTEX
101102
/// Open database with shared cache enabled
102-
extern const int OPEN_SHAREDCACHE; // SQLITE_OPEN_SHAREDCACHE
103+
SQLITECPP_API extern const int OPEN_SHAREDCACHE; // SQLITE_OPEN_SHAREDCACHE
103104
/// Open database with shared cache disabled
104-
extern const int OPEN_PRIVATECACHE; // SQLITE_OPEN_PRIVATECACHE
105+
SQLITECPP_API extern const int OPEN_PRIVATECACHE; // SQLITE_OPEN_PRIVATECACHE
105106
/// Database filename is not allowed to be a symbolic link (Note: only since SQlite 3.31.0 from 2020-01-22)
106-
extern const int OPEN_NOFOLLOW; // SQLITE_OPEN_NOFOLLOW
107+
SQLITECPP_API extern const int OPEN_NOFOLLOW; // SQLITE_OPEN_NOFOLLOW
107108

108109

109-
extern const int OK; ///< SQLITE_OK (used by check() bellow)
110+
SQLITECPP_API extern const int OK; ///< SQLITE_OK (used by check() bellow)
110111

111-
extern const char* const VERSION; ///< SQLITE_VERSION string from the sqlite3.h used at compile time
112-
extern const int VERSION_NUMBER; ///< SQLITE_VERSION_NUMBER from the sqlite3.h used at compile time
112+
SQLITECPP_API extern const char* const VERSION; ///< SQLITE_VERSION string from the sqlite3.h used at compile time
113+
SQLITECPP_API extern const int VERSION_NUMBER; ///< SQLITE_VERSION_NUMBER from the sqlite3.h used at compile time
113114

114115
/// Return SQLite version string using runtime call to the compiled library
115-
const char* getLibVersion() noexcept;
116+
SQLITECPP_API const char* getLibVersion() noexcept;
116117
/// Return SQLite version number using runtime call to the compiled library
117-
int getLibVersionNumber() noexcept;
118+
SQLITECPP_API int getLibVersionNumber() noexcept;
118119

119120
// Public structure for representing all fields contained within the SQLite header.
120121
// Official documentation for fields: https://www.sqlite.org/fileformat.html#the_database_header
@@ -160,7 +161,7 @@ struct Header {
160161
* because of the way it shares the underling SQLite precompiled statement
161162
* in a custom shared pointer (See the inner class "Statement::Ptr").
162163
*/
163-
class Database
164+
class SQLITECPP_API Database
164165
{
165166
friend class Statement; // Give Statement constructor access to the mSQLitePtr Connection Handle
166167

@@ -265,7 +266,7 @@ class Database
265266
// Deleter functor to use with smart pointers to close the SQLite database connection in an RAII fashion.
266267
struct Deleter
267268
{
268-
void operator()(sqlite3* apSQLite);
269+
SQLITECPP_API void operator()(sqlite3* apSQLite);
269270
};
270271

271272
/**

include/SQLiteCpp/Exception.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
#pragma once
1212

13+
#include <SQLiteCpp/SQLiteCppExport.h>
1314
#include <stdexcept>
1415
#include <string>
1516

@@ -23,7 +24,7 @@ namespace SQLite
2324
/**
2425
* @brief Encapsulation of the error message from SQLite3, based on std::runtime_error.
2526
*/
26-
class Exception : public std::runtime_error
27+
class SQLITECPP_API Exception : public std::runtime_error
2728
{
2829
public:
2930
/**

include/SQLiteCpp/SQLiteCpp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
// Include useful headers of SQLiteC++
21+
#include <SQLiteCpp/SQLiteCppExport.h>
2122
#include <SQLiteCpp/Assertion.h>
2223
#include <SQLiteCpp/Exception.h>
2324
#include <SQLiteCpp/Database.h>
@@ -42,3 +43,5 @@
4243
*/
4344
#define SQLITECPP_VERSION "3.02.01" // 3.2.1
4445
#define SQLITECPP_VERSION_NUMBER 3002001 // 3.2.1
46+
47+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @file SQLiteCppExport.h
3+
* @ingroup SQLiteCpp
4+
* @brief File with macros needed in the generation of Windows DLLs
5+
*
6+
*
7+
* Copyright (c) 2012-2022 Sebastien Rombauts ([email protected])
8+
*
9+
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
10+
* or copy at http://opensource.org/licenses/MIT)
11+
*/
12+
13+
#pragma once
14+
15+
/*
16+
* #define SQLITECPP_COMPILE_DLL to compile a DLL under Windows
17+
* #define SQLITECPP_EXPORT to export symbols when creating the DLL, otherwise it defaults to importing symbols
18+
*/
19+
20+
/* Windows DLL export/import */
21+
#if defined(_WIN32)&& !defined(__GNUC__) && defined(SQLITECPP_COMPILE_DLL)
22+
#if SQLITECPP_DLL_EXPORT
23+
#define SQLITECPP_API __declspec(dllexport)
24+
#pragma message("Exporting symbols")
25+
#else
26+
#define SQLITECPP_API __declspec(dllimport)
27+
#pragma message("Importing symbols")
28+
#endif
29+
#else
30+
#if __GNUC__ >= 4
31+
#define SQLITECPP_API __attribute__ ((visibility ("default")))
32+
#else
33+
#define SQLITECPP_API
34+
#endif
35+
#endif
36+
37+
#if defined(WIN32) && defined(SQLITECPP_COMPILE_DLL)
38+
#pragma warning( disable : 4251 )
39+
#pragma warning( disable : 4275 )
40+
#endif

include/SQLiteCpp/Savepoint.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
#pragma once
1414

15+
#include <SQLiteCpp/SQLiteCppExport.h>
1516
#include <SQLiteCpp/Exception.h>
1617

1718
namespace SQLite
@@ -53,7 +54,7 @@ class Database;
5354
* because of the way it shares the underling SQLite precompiled statement
5455
* in a custom shared pointer (See the inner class "Statement::Ptr").
5556
*/
56-
class Savepoint
57+
class SQLITECPP_API Savepoint
5758
{
5859
public:
5960
/**

include/SQLiteCpp/Statement.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
#pragma once
1212

13+
#include <SQLiteCpp/SQLiteCppExport.h>
1314
#include <SQLiteCpp/Exception.h>
1415
#include <SQLiteCpp/Utils.h> // SQLITECPP_PURE_FUNC
1516

@@ -30,7 +31,7 @@ namespace SQLite
3031
class Database;
3132
class Column;
3233

33-
extern const int OK; ///< SQLITE_OK
34+
SQLITECPP_API extern const int OK; ///< SQLITE_OK
3435

3536
/**
3637
* @brief RAII encapsulation of a prepared SQLite Statement.
@@ -49,7 +50,7 @@ extern const int OK; ///< SQLITE_OK
4950
* because of the way it shares the underling SQLite precompiled statement
5051
* in a custom shared pointer (See the inner class "Statement::Ptr").
5152
*/
52-
class Statement
53+
class SQLITECPP_API Statement
5354
{
5455
public:
5556
/**

include/SQLiteCpp/Transaction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
#pragma once
1212

13+
#include <SQLiteCpp/SQLiteCppExport.h>
1314
#include <SQLiteCpp/Exception.h>
1415

1516

@@ -50,7 +51,7 @@ enum class TransactionBehavior {
5051
* because of the way it shares the underling SQLite precompiled statement
5152
* in a custom shared pointer (See the inner class "Statement::Ptr").
5253
*/
53-
class Transaction
54+
class SQLITECPP_API Transaction
5455
{
5556
public:
5657
/**

0 commit comments

Comments
 (0)