Skip to content

Commit 454484f

Browse files
committed
Replaced the bundled sqlite sources with the ones retrieving the lib from the official website.
1 parent 13759e1 commit 454484f

File tree

6 files changed

+116
-237020
lines changed

6 files changed

+116
-237020
lines changed

CMakeLists.txt

+66-42
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
#
55
# Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
66
# 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"
88
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") # custom CMake modules like FindSQLiteCpp
9+
include(GNUInstallDirs)
10+
include(FetchContent)
11+
include(DownloadSQLite)
912
project(SQLiteCpp VERSION "2.99")
1013

1114
# SQLiteC++ 3.x now requires C++11 compiler
@@ -160,8 +163,58 @@ set(SQLITECPP_SCRIPT
160163
)
161164
source_group(scripts FILES ${SQLITECPP_SCRIPT})
162165

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+
163208
# add sources of the wrapper as a "SQLiteCpp" static library
164209
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)
165218

166219
# Options relative to SQLite and SQLiteC++ functions
167220

@@ -212,42 +265,10 @@ if (SQLITECPP_USE_GCOV)
212265
set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fkeep-inline-functions -fkeep-static-functions")
213266
endif ()
214267

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-
247268
# Allow the library to be installed via "make install" and found with "find_package"
248269

249270
include(GNUInstallDirs)
250-
install(TARGETS SQLiteCpp
271+
install(TARGETS SQLiteCpp sqlite3
251272
EXPORT ${PROJECT_NAME}Targets
252273
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
253274
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -322,11 +343,14 @@ option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF)
322343
if (SQLITECPP_BUILD_EXAMPLES)
323344
# add the basic example executable
324345
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)
330354
target_link_libraries(SQLiteCpp_example1 ssp)
331355
endif ()
332356
else (SQLITECPP_BUILD_EXAMPLES)
@@ -340,12 +364,12 @@ if (SQLITECPP_BUILD_TESTS)
340364
target_link_libraries(SQLiteCpp_tests SQLiteCpp)
341365
target_include_directories(SQLiteCpp_tests PRIVATE
342366
${CMAKE_CURRENT_SOURCE_DIR}/include
343-
$<$<BOOL:${SQLITECPP_INTERNAL_SQLITE}>:${CMAKE_CURRENT_SOURCE_DIR}/sqlite3>)
367+
$<$<BOOL:${SQLITECPP_INTERNAL_SQLITE}>:${sqlite3_AMALGAMATION_SOURCE_DIR}>)
344368

345369
find_package(GTest)
346370
if (GTEST_FOUND)
347371
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)
349373
else (GTEST_FOUND)
350374
message(STATUS "Compile googletest from source in submodule")
351375
# deactivate some warnings for compiling the googletest library
@@ -370,7 +394,7 @@ if (SQLITECPP_BUILD_TESTS)
370394
endif (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919)
371395
endif (MSVC)
372396

373-
target_link_libraries(SQLiteCpp_tests gtest_main)
397+
target_link_libraries(SQLiteCpp_tests gtest_main SQLiteCpp sqlite3)
374398
endif (GTEST_FOUND)
375399

376400
# add a "test" target:

cmake/DownloadSQLite.cmake

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#This is free and unencumbered software released into the public domain.
2+
#Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
3+
#In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
4+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5+
#For more information, please refer to <https://unlicense.org/>
6+
7+
set(SQLITE_BASE_URI "https://sqlite.org")
8+
set(SQLITE_DOWNLOAD_PAGE_URI "${SQLITE_BASE_URI}/download.html")
9+
set(SQLITE_USE_PRERELEASE ON)
10+
11+
12+
function(downloadSQLiteIfNeeded projectName)
13+
set("DOWNLOADED_DOWNLOAD_HTML_FILE_NAME" "${CMAKE_BINARY_DIR}/sqlite_download.html")
14+
if(EXISTS "${${projectName}_DOWNLOADED_DOWNLOAD_HTML_FILE_NAME}")
15+
else()
16+
file(DOWNLOAD "${SQLITE_DOWNLOAD_PAGE_URI}" "${DOWNLOADED_DOWNLOAD_HTML_FILE_NAME}" TLS_VERIFY SHOW_PROGRESS)
17+
endif()
18+
19+
file(READ "${DOWNLOADED_DOWNLOAD_HTML_FILE_NAME}" DOWNLOADED_DOWNLOAD_HTML)
20+
if(SQLITE_USE_PRERELEASE)
21+
set(ARCHIVE_FILE_NAME_REGEXP "snapshot/sqlite-snapshot-[0-9]+.tar.gz")
22+
else()
23+
set(ARCHIVE_FILE_NAME_REGEXP "20[0-9][0-9]/sqlite-amalgamation-[0-9]+.zip")
24+
endif()
25+
set(ARCHIVE_REGEXP ",'(${ARCHIVE_FILE_NAME_REGEXP})'\\)")
26+
string(REGEX MATCH "${ARCHIVE_REGEXP}" "" "${DOWNLOADED_DOWNLOAD_HTML}")
27+
28+
set(SQLITE_URI_PART "${CMAKE_MATCH_1}")
29+
set(SQLITE_AMALGAMATION_URI "${SQLITE_BASE_URI}/${SQLITE_URI_PART}")
30+
31+
message(STATUS "${projectName} amalgamation file URI: ${SQLITE_BASE_URI}/${SQLITE_URI_PART}")
32+
33+
set(VAR_NAME "${projectName}_download")
34+
FetchContent_Declare(
35+
"${VAR_NAME}"
36+
URL "${SQLITE_AMALGAMATION_URI}"
37+
#SOURCE_DIR "${SQLITE_AMALGAMATION_SOURCE_DIR}"
38+
#CONFIGURE_COMMAND ""
39+
#BUILD_COMMAND ""
40+
#INSTALL_COMMAND ""
41+
TLS_VERIFY 1
42+
)
43+
44+
FetchContent_MakeAvailable("${VAR_NAME}")
45+
FetchContent_GetProperties("${VAR_NAME}"
46+
SOURCE_DIR "${projectName}_AMALGAMATION_SOURCE_DIR"
47+
)
48+
set("${projectName}_AMALGAMATION_SOURCE_DIR" "${${projectName}_AMALGAMATION_SOURCE_DIR}" PARENT_SCOPE)
49+
message(STATUS "${projectName} amalgamation dir: ${${projectName}_AMALGAMATION_SOURCE_DIR}")
50+
endfunction()

sqlite3/CMakeLists.txt

-45
This file was deleted.

sqlite3/README.md

-14
This file was deleted.

0 commit comments

Comments
 (0)