Skip to content

Commit 91fe2d7

Browse files
authored
Merge pull request #234 support for external sqlite3 from BioDataAnalysis/emmenlau_support_external_sqlite
Added support for external sqlite3
2 parents 8485bb7 + a166062 commit 91fe2d7

File tree

3 files changed

+59
-43
lines changed

3 files changed

+59
-43
lines changed

CMakeLists.txt

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,8 @@ set(SQLITECPP_SCRIPT
160160
)
161161
source_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
167164
add_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")
219213
endif ()
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+
222249
include(GNUInstallDirs)
223250
install(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/>)
231255
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT headers FILES_MATCHING REGEX ".*\\.(hpp|h)$")
232256
install(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

268274
option(SQLITECPP_RUN_CPPLINT "Run cpplint.py tool for Google C++ StyleGuide." ON)
@@ -316,14 +322,11 @@ option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF)
316322
if (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 ()
329332
else (SQLITECPP_BUILD_EXAMPLES)
@@ -334,11 +337,15 @@ option(SQLITECPP_BUILD_TESTS "Build and run tests." OFF)
334337
if (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

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ init:
3636
before_build:
3737
- mkdir build
3838
- cd build
39-
- cmake -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON -DSQLITECPP_RUN_CPPCHECK=OFF .. -G %generator%
39+
- cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON -DSQLITECPP_RUN_CPPCHECK=OFF .. -G %generator%
4040

4141
# build examples, and run tests (ie make & make test)
4242
build_script:

sqlite3/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ add_library(sqlite3
1111
sqlite3.h
1212
)
1313

14+
target_include_directories(sqlite3
15+
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
16+
PUBLIC $<INSTALL_INTERFACE:include/>)
17+
1418
if (SQLITE_ENABLE_COLUMN_METADATA)
1519
# Enable the use of SQLite column metadata method
1620
# Require that the sqlite3 library is also compiled with this flag:
@@ -29,3 +33,13 @@ if (UNIX AND CMAKE_COMPILER_IS_GNUCXX)
2933
target_compile_options(sqlite3 PRIVATE "-Wno-cast-function-type")
3034
endif()
3135
endif()
36+
37+
# Allow the library to be installed via "make install" and found with "find_package"
38+
39+
include(GNUInstallDirs)
40+
install(TARGETS sqlite3
41+
EXPORT ${PROJECT_NAME}Targets
42+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
43+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
44+
COMPONENT libraries)
45+
install(FILES sqlite3.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT headers)

0 commit comments

Comments
 (0)