Skip to content

Commit 67dd1c5

Browse files
author
Simon Knopp
committed
Add support for building as a static plugin.
1 parent 07c83e8 commit 67dd1c5

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
lines changed

CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ set(CMAKE_AUTOMOC ON)
1313
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
1414
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/sqldrivers)
1515

16-
add_library(qsqlcipher MODULE
16+
option(STATIC "Build plugin as a static library" OFF)
17+
if(STATIC)
18+
set(LIBTYPE STATIC)
19+
add_definitions(-DQT_STATICPLUGIN)
20+
add_subdirectory(test-static)
21+
else()
22+
set(LIBTYPE MODULE)
23+
add_subdirectory(test-shared)
24+
endif()
25+
26+
add_library(qsqlcipher ${LIBTYPE}
1727
smain.cpp
1828
qt-private/qsql_sqlite.cpp
1929
)
@@ -28,4 +38,3 @@ target_link_libraries(qsqlcipher
2838
${SQLCIPHER_LIBRARIES}
2939
)
3040

31-
add_subdirectory(test)

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ Follow [Qt's plugin deployment guide](http://doc.qt.io/qt-5/deployment-plugins.h
3434
In short, put the plugin at ``sqldrivers/libqsqlcipher.so`` relative to your
3535
executable.
3636

37+
38+
## Static linking
39+
40+
You can also build the plugin statically by passing ``-DSTATIC=ON`` to CMake.
41+
When you build your application which uses the static plugin, you'll need to
42+
include the line ``Q_IMPORT_PLUGIN(QSQLCipherDriverPlugin);`` in one of your
43+
source files and define ``QT_STATICPLUGIN`` at compile time. And link to the
44+
static plugin, of course.
45+
46+
Note that setting ``-DSTATIC=ON`` only builds *this plugin* as a static library.
47+
If you also want to link to static versions of Qt and/or SQLCipher, it's up to
48+
you to make sure CMake finds static versions of those libraries.
49+
3750
-----
3851

3952
## Old version
File renamed without changes.

test-static/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Same as for test-shared, but statically link the plugin
2+
include(../test-shared/CMakeLists.txt)
3+
target_link_libraries(qsqlcipher-test qsqlcipher)

test-static/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Same as for test-shared, but manually import the static plugin
2+
#include <QtPlugin>
3+
Q_IMPORT_PLUGIN(QSQLCipherDriverPlugin);
4+
#include "../test-shared/main.cpp"

0 commit comments

Comments
 (0)