Skip to content

Commit 3c598cd

Browse files
Fix building with sqlcipher (#508)
* Move cmake/Find*.cmake -> cmake/modules/Find*.cmake * Add cmake/modules/FindSQLCipher.cmake from sqlpp17
1 parent a085d73 commit 3c598cd

File tree

4 files changed

+126
-6
lines changed

4 files changed

+126
-6
lines changed

CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ cmake_minimum_required(VERSION 3.14)
2828
project(sqlpp11 VERSION 0.1 LANGUAGES CXX)
2929

3030
### Project Wide Setup
31-
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/)
31+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
32+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
3233

3334
include(GNUInstallDirs)
3435
include(CTest)
@@ -93,7 +94,7 @@ if(BUILD_SQLITE3_CONNECTOR)
9394
endif()
9495

9596
if(BUILD_SQLCIPHER_CONNECTOR)
96-
add_component(NAME sqlcipher DEPENDENCIES SQLite::SQLCipher)
97+
add_component(NAME sqlcipher DEPENDENCIES SQLCipher::SQLCipher)
9798
target_compile_definitions(sqlpp11_sqlcipher INTERFACE SQLPP_USE_SQLCIPHER)
9899
endif()
99100

@@ -115,7 +116,7 @@ install(PROGRAMS ${PROJECT_SOURCE_DIR}/scripts/ddl2cpp
115116
DESTINATION ${CMAKE_INSTALL_BINDIR}
116117
)
117118

118-
write_basic_package_version_file(Sqlpp11ConfigVersion.cmake
119+
write_basic_package_version_file(Sqlpp11ConfigVersion.cmake
119120
COMPATIBILITY SameMajorVersion
120121
ARCH_INDEPENDENT
121122
)
@@ -132,20 +133,24 @@ endif()
132133

133134
if(BUILD_SQLCIPHER_CONNECTOR)
134135
install_component(NAME Sqlpp11SQLCipher TARGETS sqlpp11_sqlcipher DIRECTORY sqlite3)
136+
137+
install(FILES ${PROJECT_SOURCE_DIR}/cmake/modules/FindSQLCipher.cmake
138+
DESTINATION ${SQLPP11_INSTALL_CMAKEDIR}
139+
)
135140
endif()
136141

137142
if(BUILD_MYSQL_CONNECTOR)
138143
install_component(NAME Sqlpp11MySQL TARGETS sqlpp11_mysql DIRECTORY mysql)
139144

140-
install(FILES ${PROJECT_SOURCE_DIR}/cmake/FindMySQL.cmake
145+
install(FILES ${PROJECT_SOURCE_DIR}/cmake/modules/FindMySQL.cmake
141146
DESTINATION ${SQLPP11_INSTALL_CMAKEDIR}
142147
)
143148
endif()
144149

145150
if(BUILD_MARIADB_CONNECTOR)
146151
install_component(NAME Sqlpp11MariaDB TARGETS sqlpp11_mariadb DIRECTORY mysql)
147152

148-
install(FILES ${PROJECT_SOURCE_DIR}/cmake/FindMariaDB.cmake
153+
install(FILES ${PROJECT_SOURCE_DIR}/cmake/modules/FindMariaDB.cmake
149154
DESTINATION ${SQLPP11_INSTALL_CMAKEDIR}
150155
)
151156
endif()
@@ -158,4 +163,4 @@ endif()
158163
### Tests
159164
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
160165
add_subdirectory(tests)
161-
endif()
166+
endif()
File renamed without changes.
File renamed without changes.

cmake/modules/FindSQLCipher.cmake

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# - Try to find SQLCipher
2+
# Once done this will define
3+
#
4+
# SQLCIPHER_FOUND - system has SQLCipher
5+
# SQLCIPHER_INCLUDE_DIR - the SQLCipher include directory
6+
# SQLCIPHER_LIBRARIES - Link these to use SQLCipher
7+
# SQLCIPHER_DEFINITIONS - Compiler switches required for using SQLCipher
8+
# SQLCIPHER_VERSION - This is set to major.minor.revision (e.g. 3.4.1)
9+
#
10+
# Hints to find SQLCipher
11+
#
12+
# Set SQLCIPHER_ROOT_DIR to the root directory of a SQLCipher installation
13+
#
14+
# The following variables may be set
15+
#
16+
# SQLCIPHER_USE_OPENSSL - Set to ON/OFF to specify whether to search and use OpenSSL.
17+
# Default is OFF.
18+
# SQLCIPHER_OPENSSL_USE_ZLIB - Set to ON/OFF to specify whether to search and use Zlib in OpenSSL
19+
# Default is OFF.
20+
21+
# Redistribution and use is allowed according to the terms of the BSD license.
22+
23+
# Copyright (c) 2008, Gilles Caulier, <[email protected]>
24+
# Copyright (c) 2014, Christian Dávid, <[email protected]>
25+
#
26+
# Redistribution and use in source and binary forms, with or without
27+
# modification, are permitted provided that the following conditions
28+
# are met:
29+
#
30+
# 1. Redistributions of source code must retain the copyright
31+
# notice, this list of conditions and the following disclaimer.
32+
# 2. Redistributions in binary form must reproduce the copyright
33+
# notice, this list of conditions and the following disclaimer in the
34+
# documentation and/or other materials provided with the distribution.
35+
# 3. The name of the author may not be used to endorse or promote products
36+
# derived from this software without specific prior written permission.
37+
#
38+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
39+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40+
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
41+
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
42+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43+
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
47+
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48+
49+
# use pkg-config to get the directories and then use these values
50+
# in the FIND_PATH() and FIND_LIBRARY() calls
51+
if( NOT WIN32 )
52+
find_package(PkgConfig)
53+
54+
pkg_check_modules(PC_SQLCIPHER QUIET sqlcipher)
55+
56+
set(SQLCIPHER_DEFINITIONS ${PC_SQLCIPHER_CFLAGS_OTHER})
57+
endif( NOT WIN32 )
58+
59+
find_path(SQLCIPHER_INCLUDE_DIR NAMES sqlcipher/sqlite3.h
60+
PATHS
61+
${SQLCIPHER_ROOT_DIR}
62+
${PC_SQLCIPHER_INCLUDEDIR}
63+
${PC_SQLCIPHER_INCLUDE_DIRS}
64+
${CMAKE_INCLUDE_PATH}
65+
PATH_SUFFIXES "include"
66+
)
67+
68+
find_library(SQLCIPHER_LIBRARY NAMES sqlcipher
69+
PATHS
70+
${PC_SQLCIPHER_LIBDIR}
71+
${PC_SQLCIPHER_LIBRARY_DIRS}
72+
${SQLCIPHER_ROOT_DIR}
73+
PATH_SUFFIXES "lib"
74+
)
75+
76+
set(SQLCIPHER_LIBRARIES ${SQLCIPHER_LIBRARY})
77+
set(SQLCIPHER_INCLUDE_DIRS ${SQLCIPHER_INCLUDE_DIR})
78+
79+
if (SQLCIPHER_USE_OPENSSL)
80+
find_package(OpenSSL REQUIRED COMPONENTS Crypto)
81+
if (SQLCIPHER_OPENSSL_USE_ZLIB)
82+
find_package(ZLIB REQUIRED)
83+
# Official FindOpenSSL.cmake does not support Zlib
84+
set_target_properties(OpenSSL::Crypto PROPERTIES INTERFACE_LINK_LIBRARIES ZLIB::ZLIB)
85+
endif()
86+
87+
list(APPEND SQLCIPHER_LIBRARIES ${OPENSSL_LIBRARIES})
88+
list(APPEND SQLCIPHER_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIRS})
89+
endif()
90+
91+
92+
include(FindPackageHandleStandardArgs)
93+
94+
find_package_handle_standard_args(SQLCipher
95+
DEFAULT_MSG SQLCIPHER_INCLUDE_DIR SQLCIPHER_LIBRARY)
96+
97+
# show the SQLCIPHER_INCLUDE_DIR and SQLCIPHER_LIBRARIES variables only in the advanced view
98+
mark_as_advanced(SQLCIPHER_INCLUDE_DIR SQLCIPHER_LIBRARY)
99+
100+
if (NOT TARGET SQLCipher::SQLCipher)
101+
add_library(SQLCipher::SQLCipher UNKNOWN IMPORTED)
102+
103+
set_property(TARGET SQLCipher::SQLCipher PROPERTY INTERFACE_COMPILE_DEFINITIONS SQLITE_HAS_CODEC)
104+
set_property(TARGET SQLCipher::SQLCipher APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "SQLITE_TEMPSTORE=2")
105+
set_target_properties(SQLCipher::SQLCipher PROPERTIES
106+
INTERFACE_INCLUDE_DIRECTORIES "${SQLCIPHER_INCLUDE_DIRS}"
107+
IMPORTED_INTERFACE_LINK_LANGUAGES "C"
108+
IMPORTED_LOCATION "${SQLCIPHER_LIBRARY}")
109+
110+
if (SQLCIPHER_USE_OPENSSL)
111+
set_target_properties(SQLCipher::SQLCipher PROPERTIES
112+
INTERFACE_LINK_LIBRARIES OpenSSL::Crypto)
113+
set_property(TARGET SQLCipher::SQLCipher APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "SQLCIPHER_CRYPTO_OPENSSL")
114+
endif()
115+
endif()

0 commit comments

Comments
 (0)