Skip to content

Commit

Permalink
Replaced the bundled sqlite sources with the oes retrieving the lib f…
Browse files Browse the repository at this point in the history
…rom the official website.
  • Loading branch information
KOLANICH committed Jan 14, 2020
1 parent 13759e1 commit e657453
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 237,020 deletions.
108 changes: 66 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
#
# Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
# or copy at http://opensource.org/licenses/MIT)
cmake_minimum_required(VERSION 3.1) # for "CMAKE_CXX_STANDARD" version
cmake_minimum_required(VERSION 3.14) # for "FetchContent"
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") # custom CMake modules like FindSQLiteCpp
include(GNUInstallDirs)
include(FetchContent)
include(DownloadSQLite)
project(SQLiteCpp VERSION "2.99")

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

# All includes are relative to the "include" directory
include_directories("${PROJECT_SOURCE_DIR}/include")

option(SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON)
if (SQLITECPP_INTERNAL_SQLITE)
# build the SQLite3 C library (for ease of use/compatibility) versus Linux sqlite3-dev package
downloadSQLiteIfNeeded(sqlite3)
add_library(sqlite3 "${sqlite3_AMALGAMATION_SOURCE_DIR}/sqlite3.c")
if (SQLITE_ENABLE_COLUMN_METADATA)
# Enable the use of SQLite column metadata method
# Require that the sqlite3 library is also compiled with this flag:
target_compile_definitions(sqlite3 PUBLIC SQLITE_ENABLE_COLUMN_METADATA)
endif (SQLITE_ENABLE_COLUMN_METADATA)

if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
set_target_properties(sqlite3 PROPERTIES COMPILE_FLAGS "-fPIC")
endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))

if (UNIX AND CMAKE_COMPILER_IS_GNUCXX)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
target_compile_options(sqlite3 PRIVATE "-Wimplicit-fallthrough=0")
endif()
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0)
target_compile_options(sqlite3 PRIVATE "-Wno-cast-function-type")
endif()
endif()
target_link_libraries(sqlite3 dl)
target_include_directories(sqlite3 PRIVATE "${sqlite3_AMALGAMATION_SOURCE_DIR}")
target_include_directories(sqlite3
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PUBLIC $<INSTALL_INTERFACE:include/>
)

install(TARGETS sqlite3
#EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT libsqlite3
)
install(FILES "${sqlite3_AMALGAMATION_SOURCE_DIR}/sqlite3.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT libsqlite3_dev)
endif (SQLITECPP_INTERNAL_SQLITE)

# add sources of the wrapper as a "SQLiteCpp" static library
add_library(SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC} ${SQLITECPP_SCRIPT})
# make the sqlite3 library part of the interface of the SQLiteCpp wrapper itself (the client app does not need to link to sqlite3)
# PR https://github.com/SRombauts/SQLiteCpp/pull/111 "linked SQLiteCpp to sqlite3" commented out since it breaks install step from PR #118
target_include_directories(SQLiteCpp
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<$<BOOL:${SQLITECPP_INTERNAL_SQLITE}>:${sqlite3_AMALGAMATION_SOURCE_DIR}>
PUBLIC $<INSTALL_INTERFACE:include/>)
target_link_libraries(SQLiteCpp PUBLIC sqlite3)

# Options relative to SQLite and SQLiteC++ functions

Expand Down Expand Up @@ -212,42 +265,10 @@ if (SQLITECPP_USE_GCOV)
set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fkeep-inline-functions -fkeep-static-functions")
endif ()

## Build provided copy of SQLite3 C library ##

option(SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON)
if (SQLITECPP_INTERNAL_SQLITE)
message(STATUS "Compile sqlite3 from source in subdirectory")
# build the SQLite3 C library (for ease of use/compatibility) versus Linux sqlite3-dev package
add_subdirectory(sqlite3)
target_link_libraries(SQLiteCpp PUBLIC sqlite3)
else (SQLITECPP_INTERNAL_SQLITE)
find_package (SQLite3 REQUIRED)
message(STATUS "Link to sqlite3 system library")
target_link_libraries(SQLiteCpp PUBLIC SQLite::SQLite3)
if(SQLite3_VERSION VERSION_LESS "3.19")
set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-DSQLITECPP_HAS_MEM_STRUCT")
endif()
endif (SQLITECPP_INTERNAL_SQLITE)

# Link target with pthread and dl for Unix
if (UNIX)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(SQLiteCpp PUBLIC Threads::Threads ${CMAKE_DL_LIBS})
endif (UNIX)

# Set includes for target and transitive downstream targets

target_include_directories(SQLiteCpp
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<$<BOOL:${SQLITECPP_INTERNAL_SQLITE}>:${CMAKE_CURRENT_SOURCE_DIR}/sqlite3>
PUBLIC $<INSTALL_INTERFACE:include/>)

# Allow the library to be installed via "make install" and found with "find_package"

include(GNUInstallDirs)
install(TARGETS SQLiteCpp
install(TARGETS SQLiteCpp sqlite3
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down Expand Up @@ -322,11 +343,14 @@ option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF)
if (SQLITECPP_BUILD_EXAMPLES)
# add the basic example executable
add_executable(SQLiteCpp_example1 ${SQLITECPP_EXAMPLES})
target_link_libraries(SQLiteCpp_example1 SQLiteCpp)
target_include_directories(SQLiteCpp_example1 PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
$<$<BOOL:${SQLITECPP_INTERNAL_SQLITE}>:${CMAKE_CURRENT_SOURCE_DIR}/sqlite3>)
if (MSYS OR MINGW)
target_link_libraries(SQLiteCpp_example1 SQLiteCpp sqlite3)
# Link target with pthread and dl for Linux
if (UNIX)
target_link_libraries(SQLiteCpp_example1 pthread)
if (NOT APPLE)
target_link_libraries(SQLiteCpp_example1 dl)
endif ()
elseif (MSYS OR MINGW)
target_link_libraries(SQLiteCpp_example1 ssp)
endif ()
else (SQLITECPP_BUILD_EXAMPLES)
Expand All @@ -340,12 +364,12 @@ if (SQLITECPP_BUILD_TESTS)
target_link_libraries(SQLiteCpp_tests SQLiteCpp)
target_include_directories(SQLiteCpp_tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
$<$<BOOL:${SQLITECPP_INTERNAL_SQLITE}>:${CMAKE_CURRENT_SOURCE_DIR}/sqlite3>)
$<$<BOOL:${SQLITECPP_INTERNAL_SQLITE}>:${sqlite3_AMALGAMATION_SOURCE_DIR}>)

find_package(GTest)
if (GTEST_FOUND)
message(STATUS "Link to GTest system library")
target_link_libraries(SQLiteCpp_tests GTest::GTest GTest::Main)
target_link_libraries(SQLiteCpp_tests GTest::GTest GTest::Main SQLiteCpp sqlite3)
else (GTEST_FOUND)
message(STATUS "Compile googletest from source in submodule")
# deactivate some warnings for compiling the googletest library
Expand All @@ -370,7 +394,7 @@ if (SQLITECPP_BUILD_TESTS)
endif (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919)
endif (MSVC)

target_link_libraries(SQLiteCpp_tests gtest_main)
target_link_libraries(SQLiteCpp_tests gtest_main SQLiteCpp sqlite3)
endif (GTEST_FOUND)

# add a "test" target:
Expand Down
50 changes: 50 additions & 0 deletions cmake/DownloadSQLite.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#This is free and unencumbered software released into the public domain.
#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.
#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.
#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.
#For more information, please refer to <https://unlicense.org/>

set(SQLITE_BASE_URI "https://sqlite.org")
set(SQLITE_DOWNLOAD_PAGE_URI "${SQLITE_BASE_URI}/download.html")
set(SQLITE_USE_PRERELEASE ON)


function(downloadSQLiteIfNeeded projectName)
set("DOWNLOADED_DOWNLOAD_HTML_FILE_NAME" "${CMAKE_BINARY_DIR}/sqlite_download.html")
if(EXISTS "${${projectName}_DOWNLOADED_DOWNLOAD_HTML_FILE_NAME}")
else()
file(DOWNLOAD "${SQLITE_DOWNLOAD_PAGE_URI}" "${DOWNLOADED_DOWNLOAD_HTML_FILE_NAME}" TLS_VERIFY SHOW_PROGRESS)
endif()

file(READ "${DOWNLOADED_DOWNLOAD_HTML_FILE_NAME}" DOWNLOADED_DOWNLOAD_HTML)
if(SQLITE_USE_PRERELEASE)
set(ARCHIVE_FILE_NAME_REGEXP "snapshot/sqlite-snapshot-[0-9]+.tar.gz")
else()
set(ARCHIVE_FILE_NAME_REGEXP "20[0-9][0-9]/sqlite-amalgamation-[0-9]+.zip")
endif()
set(ARCHIVE_REGEXP ",'(${ARCHIVE_FILE_NAME_REGEXP})'\\)")
string(REGEX MATCH "${ARCHIVE_REGEXP}" "" "${DOWNLOADED_DOWNLOAD_HTML}")

set(SQLITE_URI_PART "${CMAKE_MATCH_1}")
set(SQLITE_AMALGAMATION_URI "${SQLITE_BASE_URI}/${SQLITE_URI_PART}")

message(STATUS "${projectName} amalgamation file URI: ${SQLITE_BASE_URI}/${SQLITE_URI_PART}")

set(VAR_NAME "${projectName}_download")
FetchContent_Declare(
"${VAR_NAME}"
URL "${SQLITE_AMALGAMATION_URI}"
#SOURCE_DIR "${SQLITE_AMALGAMATION_SOURCE_DIR}"
#CONFIGURE_COMMAND ""
#BUILD_COMMAND ""
#INSTALL_COMMAND ""
TLS_VERIFY 1
)

FetchContent_MakeAvailable("${VAR_NAME}")
FetchContent_GetProperties("${VAR_NAME}"
SOURCE_DIR "${projectName}_AMALGAMATION_SOURCE_DIR"
)
set("${projectName}_AMALGAMATION_SOURCE_DIR" "${${projectName}_AMALGAMATION_SOURCE_DIR}" PARENT_SCOPE)
message(STATUS "${projectName} amalgamation dir: ${${projectName}_AMALGAMATION_SOURCE_DIR}")
endfunction()
45 changes: 0 additions & 45 deletions sqlite3/CMakeLists.txt

This file was deleted.

14 changes: 0 additions & 14 deletions sqlite3/README.md

This file was deleted.

Loading

0 comments on commit e657453

Please sign in to comment.