Significantly improved support for external sqlite3, and generalized … · SRombauts/SQLiteCpp@a166062 (original) (raw)
`@@ -160,14 +160,8 @@ set(SQLITECPP_SCRIPT
`
160
160
`)
`
161
161
`source_group(scripts FILES ${SQLITECPP_SCRIPT})
`
162
162
``
163
``
`-
All includes are relative to the "include" directory
`
164
``
`-
include_directories("${PROJECT_SOURCE_DIR}/include")
`
165
``
-
166
163
`# add sources of the wrapper as a "SQLiteCpp" static library
`
167
164
`add_library(SQLiteCpp SQLITECPPSRC{SQLITECPP_SRC} SQLITECPPSRC{SQLITECPP_INC} SQLITECPPDOC{SQLITECPP_DOC} SQLITECPPDOC{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)
`
171
165
``
172
166
`# Options relative to SQLite and SQLiteC++ functions
`
173
167
``
`@@ -218,16 +212,46 @@ if (SQLITECPP_USE_GCOV)
`
218
212
` set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fkeep-inline-functions -fkeep-static-functions")
`
219
213
`endif ()
`
220
214
``
``
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
`+
<BUILDINTERFACE:<BUILD_INTERFACE:<BUILDINTERFACE:{CMAKE_CURRENT_SOURCE_DIR}/include>
`
``
244
`+
<<<BOOL:${SQLITECPP_INTERNAL_SQLITE}:${CMAKE_CURRENT_SOURCE_DIR}/sqlite3>
`
``
245
`+
PUBLIC $<INSTALL_INTERFACE:include/>)
`
``
246
+
221
247
`# Allow the library to be installed via "make install" and found with "find_package"
`
``
248
+
222
249
`include(GNUInstallDirs)
`
223
250
`install(TARGETS SQLiteCpp
`
224
251
` EXPORT ${PROJECT_NAME}Targets
`
225
252
` LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
`
226
253
` ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
`
227
254
`COMPONENT libraries)
`
228
``
`-
target_include_directories(SQLiteCpp PUBLIC
`
229
``
`-
<BUILDINTERFACE:<BUILD_INTERFACE:<BUILDINTERFACE:{CMAKE_CURRENT_SOURCE_DIR}/include>
`
230
``
`-
$<INSTALL_INTERFACE:include/>)
`
231
255
`install(DIRECTORY include/ DESTINATION CMAKEINSTALLINCLUDEDIRCOMPONENTheadersFILESMATCHINGREGEX".∗.(hpp∣h){CMAKE_INSTALL_INCLUDEDIR} COMPONENT headers FILES_MATCHING REGEX ".*\.(hpp|h)CMAKEINSTALLINCLUDEDIRCOMPONENTheadersFILESMATCHINGREGEX".∗.(hpp∣h)")
`
232
256
`install(EXPORT PROJECTNAMETargetsDESTINATION{PROJECT_NAME}Targets DESTINATION PROJECTNAMETargetsDESTINATION{CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
`
233
257
``
`@@ -245,24 +269,6 @@ install(FILES
`
245
269
`${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake
`
246
270
`DESTINATION lib/cmake/${PROJECT_NAME})
`
247
271
``
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
``
-
266
272
`# Optional additional targets:
`
267
273
``
268
274
`option(SQLITECPP_RUN_CPPLINT "Run cpplint.py tool for Google C++ StyleGuide." ON)
`
`@@ -316,14 +322,11 @@ option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF)
`
316
322
`if (SQLITECPP_BUILD_EXAMPLES)
`
317
323
`# add the basic example executable
`
318
324
` 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)
`
327
330
` target_link_libraries(SQLiteCpp_example1 ssp)
`
328
331
` endif ()
`
329
332
`else (SQLITECPP_BUILD_EXAMPLES)
`
`@@ -334,11 +337,15 @@ option(SQLITECPP_BUILD_TESTS "Build and run tests." OFF)
`
334
337
`if (SQLITECPP_BUILD_TESTS)
`
335
338
`# add the unit test executable
`
336
339
` 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>)
`
337
344
``
338
345
` find_package(GTest)
`
339
346
` if (GTEST_FOUND)
`
340
347
` 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)
`
342
349
` else (GTEST_FOUND)
`
343
350
` message(STATUS "Compile googletest from source in submodule")
`
344
351
`# deactivate some warnings for compiling the googletest library
`
`@@ -363,14 +370,9 @@ if (SQLITECPP_BUILD_TESTS)
`
363
370
` endif (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919)
`
364
371
` endif (MSVC)
`
365
372
``
366
``
`-
target_link_libraries(SQLiteCpp_tests gtest_main SQLiteCpp sqlite3)
`
``
373
`+
target_link_libraries(SQLiteCpp_tests gtest_main)
`
367
374
` endif (GTEST_FOUND)
`
368
375
``
369
``
`-
Link target with dl for linux
`
370
``
`-
if (UNIX AND NOT APPLE)
`
371
``
`-
target_link_libraries(SQLiteCpp_tests dl)
`
372
``
`-
endif ()
`
373
``
-
374
376
`# add a "test" target:
`
375
377
` enable_testing()
`
376
378
``