From 14cba69a33a9f4a16513cab8b1bfa3c29feeb2a0 Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Mon, 6 Feb 2023 19:43:35 +1100 Subject: [PATCH] Now working with example --- CMakeLists.txt | 23 +++++++++++++---------- include/SQLiteCpp/Database.h | 12 ++++++------ include/SQLiteCpp/SQLiteCppExport.h | 7 ++++++- include/SQLiteCpp/Statement.h | 2 +- sqlite3/CMakeLists.txt | 6 ------ src/Column.cpp | 10 +++++----- src/Database.cpp | 29 ++++++++++++++--------------- 7 files changed, 45 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0282847..3d94b4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,16 +17,6 @@ endif () message(STATUS "Using c++ standard c++${CMAKE_CXX_STANDARD}") set(CMAKE_CXX_STANDARD_REQUIRED ON) -if(BUILD_SHARED_LIBS) - if(WIN32) - message("defining SQLITECPP_COMPILE_DLL") - add_definitions("-DSQLITECPP_COMPILE_DLL") - if(SQLITECPP_DLL_EXPORT) - add_definitions("-DSQLITECPP_DLL_EXPORT") - endif() - endif() -endif() - message (STATUS "CMake version: ${CMAKE_VERSION}") message (STATUS "Project version: ${PROJECT_VERSION}") @@ -223,6 +213,13 @@ if (SQLITE_USE_LEGACY_STRUCT) target_compile_definitions(SQLiteCpp PUBLIC SQLITE_USE_LEGACY_STRUCT) endif (SQLITE_USE_LEGACY_STRUCT) +if(BUILD_SHARED_LIBS) + if(WIN32) + add_definitions("-DSQLITECPP_COMPILE_DLL") + target_compile_definitions(SQLiteCpp PRIVATE "SQLITECPP_DLL_EXPORT=1") + endif() +endif() + option(SQLITE_OMIT_LOAD_EXTENSION "Enable omit load extension" OFF) if (SQLITE_OMIT_LOAD_EXTENSION) # Enable the user definition of load_extension(). @@ -412,8 +409,14 @@ endif (SQLITECPP_RUN_DOXYGEN) option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF) if (SQLITECPP_BUILD_EXAMPLES) + # add the basic example executable add_executable(SQLiteCpp_example1 ${SQLITECPP_EXAMPLES}) + if(BUILD_SHARED_LIBS) + if(WIN32) + target_compile_definitions(SQLiteCpp_example1 PRIVATE "SQLITECPP_DLL_EXPORT=0") + endif() + endif() target_link_libraries(SQLiteCpp_example1 SQLiteCpp) if (MSYS OR MINGW) target_link_libraries(SQLiteCpp_example1 ssp) diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index 8408048..7d34988 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -107,15 +107,15 @@ DLL_API extern const int OPEN_PRIVATECACHE; // SQLITE_OPEN_PRIVATECACHE DLL_API extern const int OPEN_NOFOLLOW; // SQLITE_OPEN_NOFOLLOW -extern const int OK; ///< SQLITE_OK (used by check() bellow) +DLL_API extern const int OK; ///< SQLITE_OK (used by check() bellow) -extern const char* const VERSION; ///< SQLITE_VERSION string from the sqlite3.h used at compile time -extern const int VERSION_NUMBER; ///< SQLITE_VERSION_NUMBER from the sqlite3.h used at compile time +DLL_API extern const char* const VERSION; ///< SQLITE_VERSION string from the sqlite3.h used at compile time +DLL_API extern const int VERSION_NUMBER; ///< SQLITE_VERSION_NUMBER from the sqlite3.h used at compile time /// Return SQLite version string using runtime call to the compiled library -const char* getLibVersion() noexcept; +DLL_API const char* getLibVersion() noexcept; /// Return SQLite version number using runtime call to the compiled library -int getLibVersionNumber() noexcept; +DLL_API int getLibVersionNumber() noexcept; // Public structure for representing all fields contained within the SQLite header. // Official documentation for fields: https://www.sqlite.org/fileformat.html#the_database_header @@ -266,7 +266,7 @@ public: // Deleter functor to use with smart pointers to close the SQLite database connection in an RAII fashion. struct Deleter { - void operator()(sqlite3* apSQLite); + DLL_API void operator()(sqlite3* apSQLite); }; /** diff --git a/include/SQLiteCpp/SQLiteCppExport.h b/include/SQLiteCpp/SQLiteCppExport.h index 63d1e0f..c6322bb 100644 --- a/include/SQLiteCpp/SQLiteCppExport.h +++ b/include/SQLiteCpp/SQLiteCppExport.h @@ -19,7 +19,7 @@ /* Windows DLL export/import */ #if defined(WIN32) && defined(SQLITECPP_COMPILE_DLL) - #if defined(SQLITECPP_DLL_EXPORT) + #if SQLITECPP_DLL_EXPORT #define DLL_API __declspec(dllexport) #pragma message("Exporting symbols") #else @@ -29,3 +29,8 @@ #else #define DLL_API #endif + +#if defined(WIN32) && defined(SQLITECPP_COMPILE_DLL) + #pragma warning( disable : 4251 ) + #pragma warning( disable : 4275 ) +#endif diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index dfdcd97..bddc369 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -31,7 +31,7 @@ namespace SQLite class Database; class Column; -extern const int OK; ///< SQLITE_OK +DLL_API extern const int OK; ///< SQLITE_OK /** * @brief RAII encapsulation of a prepared SQLite Statement. diff --git a/sqlite3/CMakeLists.txt b/sqlite3/CMakeLists.txt index ef222e9..b3dc73a 100644 --- a/sqlite3/CMakeLists.txt +++ b/sqlite3/CMakeLists.txt @@ -13,13 +13,7 @@ add_library(sqlite3 if(WIN32) if(BUILD_SHARED_LIBS) - if(SQLITECPP_DLL_EXPORT) - message("Adding __declspec(dllexport)") add_definitions("-DSQLITE_API=__declspec(dllexport)") - else() - message("Adding __declspec(dllimport)") - add_definitions("-DSQLITE_API=__declspec(dllimport)") - endif() endif() endif() diff --git a/src/Column.cpp b/src/Column.cpp index 60b3c3b..ec7c64d 100644 --- a/src/Column.cpp +++ b/src/Column.cpp @@ -18,11 +18,11 @@ namespace SQLite { -const int INTEGER = SQLITE_INTEGER; -const int FLOAT = SQLITE_FLOAT; -const int TEXT = SQLITE_TEXT; -const int BLOB = SQLITE_BLOB; -const int Null = SQLITE_NULL; +DLL_API const int INTEGER = SQLITE_INTEGER; +DLL_API const int FLOAT = SQLITE_FLOAT; +DLL_API const int TEXT = SQLITE_TEXT; +DLL_API const int BLOB = SQLITE_BLOB; +DLL_API const int Null = SQLITE_NULL; // Encapsulation of a Column in a row of the result pointed by the prepared Statement. diff --git a/src/Database.cpp b/src/Database.cpp index c1403ae..a473dd9 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -23,29 +23,28 @@ #define SQLITE_DETERMINISTIC 0x800 #endif // SQLITE_DETERMINISTIC - namespace SQLite { -const int OK = SQLITE_OK; -const int OPEN_READONLY = SQLITE_OPEN_READONLY; -const int OPEN_READWRITE = SQLITE_OPEN_READWRITE; -const int OPEN_CREATE = SQLITE_OPEN_CREATE; -const int OPEN_URI = SQLITE_OPEN_URI; -const int OPEN_MEMORY = SQLITE_OPEN_MEMORY; -const int OPEN_NOMUTEX = SQLITE_OPEN_NOMUTEX; -const int OPEN_FULLMUTEX = SQLITE_OPEN_FULLMUTEX; -const int OPEN_SHAREDCACHE = SQLITE_OPEN_SHAREDCACHE; -const int OPEN_PRIVATECACHE = SQLITE_OPEN_PRIVATECACHE; +DLL_API const int OK = SQLITE_OK; +DLL_API const int OPEN_READONLY = SQLITE_OPEN_READONLY; +DLL_API const int OPEN_READWRITE = SQLITE_OPEN_READWRITE; +DLL_API const int OPEN_CREATE = SQLITE_OPEN_CREATE; +DLL_API const int OPEN_URI = SQLITE_OPEN_URI; +DLL_API const int OPEN_MEMORY = SQLITE_OPEN_MEMORY; +DLL_API const int OPEN_NOMUTEX = SQLITE_OPEN_NOMUTEX; +DLL_API const int OPEN_FULLMUTEX = SQLITE_OPEN_FULLMUTEX; +DLL_API const int OPEN_SHAREDCACHE = SQLITE_OPEN_SHAREDCACHE; +DLL_API const int OPEN_PRIVATECACHE = SQLITE_OPEN_PRIVATECACHE; // check if sqlite version is >= 3.31.0 and SQLITE_OPEN_NOFOLLOW is defined #if SQLITE_VERSION_NUMBER >= 3031000 && defined(SQLITE_OPEN_NOFOLLOW) -const int OPEN_NOFOLLOW = SQLITE_OPEN_NOFOLLOW; +DLL_API const int OPEN_NOFOLLOW = SQLITE_OPEN_NOFOLLOW; #else -const int OPEN_NOFOLLOW = 0; +DLL_API const int OPEN_NOFOLLOW = 0; #endif -const char* const VERSION = SQLITE_VERSION; -const int VERSION_NUMBER = SQLITE_VERSION_NUMBER; +DLL_API const char* const VERSION = SQLITE_VERSION; +DLL_API const int VERSION_NUMBER = SQLITE_VERSION_NUMBER; // Return SQLite version string using runtime call to the compiled library const char* getLibVersion() noexcept