Skip to content

Commit b93de0a

Browse files
authored
Merge pull request #292 Fix compilation if using SQLITE_HAS_CODEC from sum01/fix_sqlcipher_compile
2 parents 80b5817 + 15b307a commit b93de0a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

CMakeLists.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,45 @@ else (SQLITECPP_INTERNAL_SQLITE)
239239
if(SQLite3_VERSION VERSION_LESS "3.19")
240240
set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-DSQLITECPP_HAS_MEM_STRUCT")
241241
endif()
242+
243+
# When using the SQLite codec, we need to link against the sqlcipher lib & include <sqlcipher/sqlite3.h>
244+
# So this gets the lib & header, and links/includes everything
245+
if(SQLITE_HAS_CODEC)
246+
# Make PkgConfig optional since Windows doesn't usually have it installed.
247+
find_package(PkgConfig QUIET)
248+
if(PKG_CONFIG_FOUND)
249+
# IMPORTED_TARGET was added in 3.6.3
250+
if(CMAKE_VERSION VERSION_LESS 3.6.3)
251+
pkg_check_modules(sqlcipher REQUIRED sqlcipher)
252+
# Only used in Database.cpp so PRIVATE to hide from end-user
253+
# Since we can't use IMPORTED_TARGET on this older Cmake version, manually link libs & includes
254+
target_link_libraries(SQLiteCpp PRIVATE ${sqlcipher_LIBRARIES})
255+
target_include_directories(SQLiteCpp PRIVATE ${sqlcipher_INCLUDE_DIRS})
256+
else()
257+
pkg_check_modules(sqlcipher REQUIRED IMPORTED_TARGET sqlcipher)
258+
# Only used in Database.cpp so PRIVATE to hide from end-user
259+
target_link_libraries(SQLiteCpp PRIVATE PkgConfig::sqlcipher)
260+
endif()
261+
else()
262+
# Since we aren't using pkgconf here, find it manually
263+
find_library(sqlcipher_LIBRARY "sqlcipher")
264+
find_path(sqlcipher_INCLUDE_DIR "sqlcipher/sqlite3.h"
265+
PATH_SUFFIXES
266+
"include"
267+
"includes"
268+
)
269+
# Hides it from the GUI
270+
mark_as_advanced(sqlcipher_LIBRARY sqlcipher_INCLUDE_DIR)
271+
if(NOT sqlcipher_INCLUDE_DIR)
272+
message(FATAL_ERROR "${PROJECT_NAME} requires the \"<sqlcipher/sqlite3.h>\" header to use the codec functionality but it wasn't found.")
273+
elseif(NOT sqlcipher_LIBRARY)
274+
message(FATAL_ERROR "${PROJECT_NAME} requires the sqlcipher library to use the codec functionality but it wasn't found.")
275+
endif()
276+
# Only used in Database.cpp so PRIVATE to hide from end-user
277+
target_include_directories(SQLiteCpp PRIVATE "${sqlcipher_INCLUDE_DIR}/sqlcipher")
278+
target_link_libraries(SQLiteCpp PRIVATE ${sqlcipher_LIBRARY})
279+
endif()
280+
endif()
242281
endif (SQLITECPP_INTERNAL_SQLITE)
243282

244283
# Link target with pthread and dl for Unix

0 commit comments

Comments
 (0)