@@ -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 ()
242281endif (SQLITECPP_INTERNAL_SQLITE)
243282
244283# Link target with pthread and dl for Unix
0 commit comments