|
| 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