4
4
#
5
5
# Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
6
6
# or copy at http://opensource.org/licenses/MIT)
7
- cmake_minimum_required (VERSION 3.1 ) # for "CMAKE_CXX_STANDARD" version
7
+ cmake_minimum_required (VERSION 3.14 ) # for "FetchContent"
8
8
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" ) # custom CMake modules like FindSQLiteCpp
9
+ include (GNUInstallDirs)
10
+ include (FetchContent)
11
+ include (DownloadSQLite)
9
12
project (SQLiteCpp VERSION "2.99" )
10
13
11
14
# SQLiteC++ 3.x now requires C++11 compiler
@@ -160,8 +163,58 @@ set(SQLITECPP_SCRIPT
160
163
)
161
164
source_group (scripts FILES ${SQLITECPP_SCRIPT} )
162
165
166
+ # All includes are relative to the "include" directory
167
+ include_directories ("${PROJECT_SOURCE_DIR} /include" )
168
+
169
+ option (SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON )
170
+ if (SQLITECPP_INTERNAL_SQLITE)
171
+ # build the SQLite3 C library (for ease of use/compatibility) versus Linux sqlite3-dev package
172
+ downloadSQLiteIfNeeded(sqlite3)
173
+ add_library (sqlite3 "${sqlite3_AMALGAMATION_SOURCE_DIR} /sqlite3.c" )
174
+ if (SQLITE_ENABLE_COLUMN_METADATA)
175
+ # Enable the use of SQLite column metadata method
176
+ # Require that the sqlite3 library is also compiled with this flag:
177
+ target_compile_definitions (sqlite3 PUBLIC SQLITE_ENABLE_COLUMN_METADATA)
178
+ endif (SQLITE_ENABLE_COLUMN_METADATA)
179
+
180
+ if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" ))
181
+ set_target_properties (sqlite3 PROPERTIES COMPILE_FLAGS "-fPIC" )
182
+ endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" ))
183
+
184
+ if (UNIX AND CMAKE_COMPILER_IS_GNUCXX)
185
+ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
186
+ target_compile_options (sqlite3 PRIVATE "-Wimplicit-fallthrough=0" )
187
+ endif ()
188
+ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0)
189
+ target_compile_options (sqlite3 PRIVATE "-Wno-cast-function-type" )
190
+ endif ()
191
+ endif ()
192
+ target_link_libraries (sqlite3 dl)
193
+ target_include_directories (sqlite3 PRIVATE "${sqlite3_AMALGAMATION_SOURCE_DIR} " )
194
+ target_include_directories (sqlite3
195
+ PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} >
196
+ PUBLIC $<INSTALL_INTERFACE:include />
197
+ )
198
+
199
+ install (TARGETS sqlite3
200
+ #EXPORT ${PROJECT_NAME}Targets
201
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
202
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
203
+ COMPONENT libsqlite3
204
+ )
205
+ install (FILES "${sqlite3_AMALGAMATION_SOURCE_DIR} /sqlite3.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT libsqlite3_dev)
206
+ endif (SQLITECPP_INTERNAL_SQLITE)
207
+
163
208
# add sources of the wrapper as a "SQLiteCpp" static library
164
209
add_library (SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC} ${SQLITECPP_SCRIPT} )
210
+ # make the sqlite3 library part of the interface of the SQLiteCpp wrapper itself (the client app does not need to link to sqlite3)
211
+ # PR https://github.com/SRombauts/SQLiteCpp/pull/111 "linked SQLiteCpp to sqlite3" commented out since it breaks install step from PR #118
212
+ target_include_directories (SQLiteCpp
213
+ PRIVATE
214
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include >
215
+ $<$<BOOL :${SQLITECPP_INTERNAL_SQLITE} >:${sqlite3_AMALGAMATION_SOURCE_DIR} >
216
+ PUBLIC $<INSTALL_INTERFACE:include />)
217
+ target_link_libraries (SQLiteCpp PUBLIC sqlite3)
165
218
166
219
# Options relative to SQLite and SQLiteC++ functions
167
220
@@ -212,42 +265,10 @@ if (SQLITECPP_USE_GCOV)
212
265
set_target_properties (SQLiteCpp PROPERTIES COMPILE_FLAGS "-fkeep-inline-functions -fkeep-static-functions" )
213
266
endif ()
214
267
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
-
247
268
# Allow the library to be installed via "make install" and found with "find_package"
248
269
249
270
include (GNUInstallDirs)
250
- install (TARGETS SQLiteCpp
271
+ install (TARGETS SQLiteCpp sqlite3
251
272
EXPORT ${PROJECT_NAME} Targets
252
273
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
253
274
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -322,11 +343,14 @@ option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF)
322
343
if (SQLITECPP_BUILD_EXAMPLES)
323
344
# add the basic example executable
324
345
add_executable (SQLiteCpp_example1 ${SQLITECPP_EXAMPLES} )
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)
346
+ target_link_libraries (SQLiteCpp_example1 SQLiteCpp sqlite3)
347
+ # Link target with pthread and dl for Linux
348
+ if (UNIX )
349
+ target_link_libraries (SQLiteCpp_example1 pthread)
350
+ if (NOT APPLE )
351
+ target_link_libraries (SQLiteCpp_example1 dl)
352
+ endif ()
353
+ elseif (MSYS OR MINGW)
330
354
target_link_libraries (SQLiteCpp_example1 ssp)
331
355
endif ()
332
356
else (SQLITECPP_BUILD_EXAMPLES)
@@ -340,12 +364,12 @@ if (SQLITECPP_BUILD_TESTS)
340
364
target_link_libraries (SQLiteCpp_tests SQLiteCpp)
341
365
target_include_directories (SQLiteCpp_tests PRIVATE
342
366
${CMAKE_CURRENT_SOURCE_DIR} /include
343
- $<$<BOOL :${SQLITECPP_INTERNAL_SQLITE} >:${CMAKE_CURRENT_SOURCE_DIR} /sqlite3 >)
367
+ $<$<BOOL :${SQLITECPP_INTERNAL_SQLITE} >:${sqlite3_AMALGAMATION_SOURCE_DIR} >)
344
368
345
369
find_package (GTest)
346
370
if (GTEST_FOUND)
347
371
message (STATUS "Link to GTest system library" )
348
- target_link_libraries (SQLiteCpp_tests GTest::GTest GTest::Main)
372
+ target_link_libraries (SQLiteCpp_tests GTest::GTest GTest::Main SQLiteCpp sqlite3 )
349
373
else (GTEST_FOUND)
350
374
message (STATUS "Compile googletest from source in submodule" )
351
375
# deactivate some warnings for compiling the googletest library
@@ -370,7 +394,7 @@ if (SQLITECPP_BUILD_TESTS)
370
394
endif (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919)
371
395
endif (MSVC )
372
396
373
- target_link_libraries (SQLiteCpp_tests gtest_main)
397
+ target_link_libraries (SQLiteCpp_tests gtest_main SQLiteCpp sqlite3 )
374
398
endif (GTEST_FOUND)
375
399
376
400
# add a "test" target:
0 commit comments