Skip to content

Commit

Permalink
Added an option to automatically copy the driver into the Qt plugin f…
Browse files Browse the repository at this point in the history
…older.
  • Loading branch information
blizzard4591 committed Dec 13, 2017
1 parent ebf3ed5 commit fb58411
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ else()
SET(CMAKE_PREFIX_PATH "C:/Qtx86/5.9.2/msvc2015/lib/cmake/")
endif()

find_package(Qt5Core REQUIRED)
find_package(Qt5Sql REQUIRED)

if (NOT WIN32)
Expand All @@ -33,6 +34,7 @@ endif()

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

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

if(QSQLCIPHER_INSTALL_INTO_QT_PLUGIN_DIRECTORY)
string(REPLACE "\\" "/" Qt5Core_DIR "${Qt5Core_DIR}")
if ("${Qt5Core_DIR}" STREQUAL "")
message(SEND_ERROR "Qt5Core_DIR is not set and can not be used to derive the location of the Qt installation.")
elseif(NOT "${Qt5Core_DIR}" MATCHES "^(.*)/lib/cmake/Qt5Core")
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.")
else()
string(REGEX REPLACE "^(.*)/lib/cmake/Qt5Core" "\\1" QT5_BASE_DIR "${Qt5Core_DIR}")
set(QSQLCIPHER_PLUGIN_DIR "${QT5_BASE_DIR}/plugins")
message(STATUS "QSQLCIPHER_INSTALL_INTO_QT_PLUGIN_DIRECTORY is set, will install plugin to folder ${QSQLCIPHER_PLUGIN_DIR}/sqldrivers")
endif()
endif()

if(QSQLCIPHER_STATIC)
set(LIBTYPE STATIC)
add_definitions(-DQT_STATICPLUGIN)
Expand Down Expand Up @@ -112,6 +127,10 @@ if (NOT ("${QSQLCIPHER_COPYTO_DIR}" STREQUAL ""))
add_custom_command(TARGET qsqlcipher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:qsqlcipher> ${QSQLCIPHER_COPYTO_DIR}/$<TARGET_FILE_NAME:qsqlcipher>)
endif()

if (NOT ("${QSQLCIPHER_PLUGIN_DIR}" STREQUAL ""))
add_custom_command(TARGET qsqlcipher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:qsqlcipher> ${QSQLCIPHER_PLUGIN_DIR}/sqldrivers/$<TARGET_FILE_NAME:qsqlcipher>)
endif()

find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
if (NOT WIN32)
if (DPKG_PROGRAM)
Expand Down

0 comments on commit fb58411

Please sign in to comment.