@@ -160,14 +160,8 @@ set(SQLITECPP_SCRIPT
160160)
161161source_group (scripts FILES ${SQLITECPP_SCRIPT} )
162162
163- # All includes are relative to the "include" directory
164- include_directories ("${PROJECT_SOURCE_DIR} /include" )
165-
166163# add sources of the wrapper as a "SQLiteCpp" static library
167164add_library (SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC} ${SQLITECPP_SCRIPT} )
168- # make the sqlite3 library part of the interface of the SQLiteCpp wrapper itself (the client app does not need to link to sqlite3)
169- # PR https://github.com/SRombauts/SQLiteCpp/pull/111 "linked SQLiteCpp to sqlite3" commented out since it breaks install step from PR #118
170- #target_link_libraries(SQLiteCpp PUBLIC sqlite3)
171165
172166# Options relative to SQLite and SQLiteC++ functions
173167
@@ -218,16 +212,46 @@ if (SQLITECPP_USE_GCOV)
218212 set_target_properties (SQLiteCpp PROPERTIES COMPILE_FLAGS "-fkeep-inline-functions -fkeep-static-functions" )
219213endif ()
220214
215+ ## Build provided copy of SQLite3 C library ##
216+
217+ option (SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON )
218+ if (SQLITECPP_INTERNAL_SQLITE)
219+ message (STATUS "Compile sqlite3 from source in subdirectory" )
220+ # build the SQLite3 C library (for ease of use/compatibility) versus Linux sqlite3-dev package
221+ add_subdirectory (sqlite3)
222+ target_link_libraries (SQLiteCpp PUBLIC sqlite3)
223+ else (SQLITECPP_INTERNAL_SQLITE)
224+ find_package (SQLite3 REQUIRED)
225+ message (STATUS "Link to sqlite3 system library" )
226+ target_link_libraries (SQLiteCpp PUBLIC SQLite::SQLite3)
227+ if (SQLite3_VERSION VERSION_LESS "3.19" )
228+ set_target_properties (SQLiteCpp PROPERTIES COMPILE_FLAGS "-DSQLITECPP_HAS_MEM_STRUCT" )
229+ endif ()
230+ endif (SQLITECPP_INTERNAL_SQLITE)
231+
232+ # Link target with pthread and dl for Unix
233+ if (UNIX )
234+ set (THREADS_PREFER_PTHREAD_FLAG ON )
235+ find_package (Threads REQUIRED)
236+ target_link_libraries (SQLiteCpp PUBLIC Threads::Threads ${CMAKE_DL_LIBS} )
237+ endif (UNIX )
238+
239+ # Set includes for target and transitive downstream targets
240+
241+ target_include_directories (SQLiteCpp
242+ PRIVATE
243+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include >
244+ $<$<BOOL :${SQLITECPP_INTERNAL_SQLITE} >:${CMAKE_CURRENT_SOURCE_DIR} /sqlite3>
245+ PUBLIC $<INSTALL_INTERFACE:include />)
246+
221247# Allow the library to be installed via "make install" and found with "find_package"
248+
222249include (GNUInstallDirs)
223250install (TARGETS SQLiteCpp
224251 EXPORT ${PROJECT_NAME} Targets
225252 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
226253 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
227254 COMPONENT libraries)
228- target_include_directories (SQLiteCpp PUBLIC
229- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include >
230- $<INSTALL_INTERFACE:include />)
231255install (DIRECTORY include / DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT headers FILES_MATCHING REGEX ".*\\ .(hpp|h)$" )
232256install (EXPORT ${PROJECT_NAME} Targets DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME} )
233257
@@ -245,24 +269,6 @@ install(FILES
245269 ${CMAKE_CURRENT_BINARY_DIR} /cmake/${PROJECT_NAME} ConfigVersion.cmake
246270 DESTINATION lib/cmake/${PROJECT_NAME} )
247271
248- ## Build provided copy of SQLite3 C library ##
249-
250- option (SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON )
251- if (SQLITECPP_INTERNAL_SQLITE)
252- message (STATUS "Compile sqlite3 from source in subdirectory" )
253- # build the SQLite3 C library (for ease of use/compatibility) versus Linux sqlite3-dev package
254- add_subdirectory (sqlite3)
255- target_include_directories (sqlite3 PUBLIC "${PROJECT_SOURCE_DIR} /sqlite3" )
256- target_include_directories (SQLiteCpp PRIVATE "${PROJECT_SOURCE_DIR} /sqlite3" )
257- else (SQLITECPP_INTERNAL_SQLITE)
258- find_package (SQLite3 REQUIRED)
259- if (SQLITE3_FOUND)
260- message (STATUS "Link to sqlite3 system library" )
261- include_directories (${SQLITE3_INCLUDE_DIRS} )
262- target_link_libraries (SQLiteCpp ${SQLITE3_LIBRARIES} )
263- endif (SQLITE3_FOUND)
264- endif (SQLITECPP_INTERNAL_SQLITE)
265-
266272# Optional additional targets:
267273
268274option (SQLITECPP_RUN_CPPLINT "Run cpplint.py tool for Google C++ StyleGuide." ON )
@@ -316,14 +322,11 @@ option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF)
316322if (SQLITECPP_BUILD_EXAMPLES)
317323 # add the basic example executable
318324 add_executable (SQLiteCpp_example1 ${SQLITECPP_EXAMPLES} )
319- target_link_libraries (SQLiteCpp_example1 SQLiteCpp sqlite3)
320- # Link target with pthread and dl for Linux
321- if (UNIX )
322- target_link_libraries (SQLiteCpp_example1 pthread)
323- if (NOT APPLE )
324- target_link_libraries (SQLiteCpp_example1 dl)
325- endif ()
326- elseif (MSYS OR MINGW)
325+ target_link_libraries (SQLiteCpp_example1 SQLiteCpp)
326+ target_include_directories (SQLiteCpp_example1 PRIVATE
327+ ${CMAKE_CURRENT_SOURCE_DIR} /include
328+ $<$<BOOL :${SQLITECPP_INTERNAL_SQLITE} >:${CMAKE_CURRENT_SOURCE_DIR} /sqlite3>)
329+ if (MSYS OR MINGW)
327330 target_link_libraries (SQLiteCpp_example1 ssp)
328331 endif ()
329332else (SQLITECPP_BUILD_EXAMPLES)
@@ -334,11 +337,15 @@ option(SQLITECPP_BUILD_TESTS "Build and run tests." OFF)
334337if (SQLITECPP_BUILD_TESTS)
335338 # add the unit test executable
336339 add_executable (SQLiteCpp_tests ${SQLITECPP_TESTS} )
340+ target_link_libraries (SQLiteCpp_tests SQLiteCpp)
341+ target_include_directories (SQLiteCpp_tests PRIVATE
342+ ${CMAKE_CURRENT_SOURCE_DIR} /include
343+ $<$<BOOL :${SQLITECPP_INTERNAL_SQLITE} >:${CMAKE_CURRENT_SOURCE_DIR} /sqlite3>)
337344
338345 find_package (GTest)
339346 if (GTEST_FOUND)
340347 message (STATUS "Link to GTest system library" )
341- target_link_libraries (SQLiteCpp_tests GTest::GTest GTest::Main SQLiteCpp sqlite3 )
348+ target_link_libraries (SQLiteCpp_tests GTest::GTest GTest::Main)
342349 else (GTEST_FOUND)
343350 message (STATUS "Compile googletest from source in submodule" )
344351 # deactivate some warnings for compiling the googletest library
@@ -363,14 +370,9 @@ if (SQLITECPP_BUILD_TESTS)
363370 endif (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919)
364371 endif (MSVC )
365372
366- target_link_libraries (SQLiteCpp_tests gtest_main SQLiteCpp sqlite3 )
373+ target_link_libraries (SQLiteCpp_tests gtest_main)
367374 endif (GTEST_FOUND)
368375
369- # Link target with dl for linux
370- if (UNIX AND NOT APPLE )
371- target_link_libraries (SQLiteCpp_tests dl)
372- endif ()
373-
374376 # add a "test" target:
375377 enable_testing ()
376378
0 commit comments