Skip to content

Commit fb58411

Browse files
committed
Added an option to automatically copy the driver into the Qt plugin folder.
1 parent ebf3ed5 commit fb58411

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ else()
99
SET(CMAKE_PREFIX_PATH "C:/Qtx86/5.9.2/msvc2015/lib/cmake/")
1010
endif()
1111

12+
find_package(Qt5Core REQUIRED)
1213
find_package(Qt5Sql REQUIRED)
1314

1415
if (NOT WIN32)
@@ -33,6 +34,7 @@ endif()
3334

3435
option(QSQLCIPHER_STATIC "Build plugin as a static library" OFF)
3536
option(QSQLCIPHER_BUILD_TESTS "Build the test binary" ON)
37+
option(QSQLCIPHER_INSTALL_INTO_QT_PLUGIN_DIRECTORY "Find the Qt plugin directory and install the driver there" OFF)
3638
set(QSQLCIPHER_COPYTO_DIR "" CACHE PATH "If set, the build artifact of the library will be copied there")
3739

3840
set(CMAKE_CXX_STANDARD 14)
@@ -42,6 +44,19 @@ if(CMAKE_COMPILER_IS_GNUCC)
4244
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
4345
endif()
4446

47+
if(QSQLCIPHER_INSTALL_INTO_QT_PLUGIN_DIRECTORY)
48+
string(REPLACE "\\" "/" Qt5Core_DIR "${Qt5Core_DIR}")
49+
if ("${Qt5Core_DIR}" STREQUAL "")
50+
message(SEND_ERROR "Qt5Core_DIR is not set and can not be used to derive the location of the Qt installation.")
51+
elseif(NOT "${Qt5Core_DIR}" MATCHES "^(.*)/lib/cmake/Qt5Core")
52+
message(SEND_ERROR "Qt5Core_DIR does not end in lib/cmake/Qt5Core, which is unexpected and therefore can not be used to derive the location of the Qt installation.")
53+
else()
54+
string(REGEX REPLACE "^(.*)/lib/cmake/Qt5Core" "\\1" QT5_BASE_DIR "${Qt5Core_DIR}")
55+
set(QSQLCIPHER_PLUGIN_DIR "${QT5_BASE_DIR}/plugins")
56+
message(STATUS "QSQLCIPHER_INSTALL_INTO_QT_PLUGIN_DIRECTORY is set, will install plugin to folder ${QSQLCIPHER_PLUGIN_DIR}/sqldrivers")
57+
endif()
58+
endif()
59+
4560
if(QSQLCIPHER_STATIC)
4661
set(LIBTYPE STATIC)
4762
add_definitions(-DQT_STATICPLUGIN)
@@ -112,6 +127,10 @@ if (NOT ("${QSQLCIPHER_COPYTO_DIR}" STREQUAL ""))
112127
add_custom_command(TARGET qsqlcipher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:qsqlcipher> ${QSQLCIPHER_COPYTO_DIR}/$<TARGET_FILE_NAME:qsqlcipher>)
113128
endif()
114129

130+
if (NOT ("${QSQLCIPHER_PLUGIN_DIR}" STREQUAL ""))
131+
add_custom_command(TARGET qsqlcipher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:qsqlcipher> ${QSQLCIPHER_PLUGIN_DIR}/sqldrivers/$<TARGET_FILE_NAME:qsqlcipher>)
132+
endif()
133+
115134
find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
116135
if (NOT WIN32)
117136
if (DPKG_PROGRAM)

0 commit comments

Comments
 (0)