mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 09:46:02 -04:00
Fix linking with system library (libsqlite3)
Add FindSQLite3 from CMake v3.14 in cmake subdir custom CMake modules like FindSQLiteCpp Add this cmake subdir to CMAKE_MODULE_PATH Add a Travis CI build configuration using the libsqlite3-dev packagee from the Linux/Ubuntu distribution
This commit is contained in:
parent
a7d9456f05
commit
ab8ff7376c
37
.travis.yml
37
.travis.yml
@ -9,6 +9,13 @@ os: linux
|
|||||||
cache:
|
cache:
|
||||||
apt: true
|
apt: true
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- BUILD_TYPE=Debug
|
||||||
|
- ASAN=ON
|
||||||
|
- INTERNAL_SQLITE=ON
|
||||||
|
- VALGRIND=OFF
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
|
|
||||||
@ -31,15 +38,14 @@ matrix:
|
|||||||
- dist: bionic
|
- dist: bionic
|
||||||
env:
|
env:
|
||||||
- cc=gcc cxx=g++
|
- cc=gcc cxx=g++
|
||||||
- BUILD_TYPE=Debug
|
- GCOV=ON
|
||||||
- ASAN=ON GCOV=ON
|
|
||||||
- COVERALLS=true
|
- COVERALLS=true
|
||||||
|
|
||||||
# GCC Debug build with Valgrind instead of Address Sanitizer
|
# GCC Debug build with Valgrind instead of Address Sanitizer
|
||||||
- dist: bionic
|
- dist: bionic
|
||||||
env:
|
env:
|
||||||
- cc=gcc cxx=g++
|
- cc=gcc cxx=g++
|
||||||
- BUILD_TYPE=Debug
|
- ASAN=OFF
|
||||||
- VALGRIND=true
|
- VALGRIND=true
|
||||||
|
|
||||||
# GCC Release build
|
# GCC Release build
|
||||||
@ -48,17 +54,19 @@ matrix:
|
|||||||
- cc=gcc cxx=g++
|
- cc=gcc cxx=g++
|
||||||
- BUILD_TYPE=Release
|
- BUILD_TYPE=Release
|
||||||
|
|
||||||
|
# GCC test linking with libsqlite3-dev package
|
||||||
|
- dist: bionic
|
||||||
|
env:
|
||||||
|
- cc=gcc cxx=g++
|
||||||
|
- INTERNAL_SQLITE=OFF
|
||||||
|
|
||||||
- dist: xenial
|
- dist: xenial
|
||||||
env:
|
env:
|
||||||
- cc=gcc cxx=g++
|
- cc=gcc cxx=g++
|
||||||
- BUILD_TYPE=Debug
|
|
||||||
- ASAN=ON
|
|
||||||
|
|
||||||
- dist: trusty
|
- dist: trusty
|
||||||
env:
|
env:
|
||||||
- cc=gcc cxx=g++
|
- cc=gcc cxx=g++
|
||||||
- BUILD_TYPE=Debug
|
|
||||||
- ASAN=ON
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# Clang on Linux
|
# Clang on Linux
|
||||||
@ -67,20 +75,14 @@ matrix:
|
|||||||
- dist: bionic
|
- dist: bionic
|
||||||
env:
|
env:
|
||||||
- cc=clang cxx=clang++
|
- cc=clang cxx=clang++
|
||||||
- BUILD_TYPE=Debug
|
|
||||||
- ASAN=ON
|
|
||||||
|
|
||||||
- dist: xenial
|
- dist: xenial
|
||||||
env:
|
env:
|
||||||
- cc=clang cxx=clang++
|
- cc=clang cxx=clang++
|
||||||
- BUILD_TYPE=Debug
|
|
||||||
- ASAN=ON
|
|
||||||
|
|
||||||
- dist: trusty
|
- dist: trusty
|
||||||
env:
|
env:
|
||||||
- cc=clang cxx=clang++
|
- cc=clang cxx=clang++
|
||||||
- BUILD_TYPE=Debug
|
|
||||||
- ASAN=ON
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# Clang on OSX
|
# Clang on OSX
|
||||||
@ -90,23 +92,20 @@ matrix:
|
|||||||
- os: osx
|
- os: osx
|
||||||
env:
|
env:
|
||||||
- cc=clang cxx=clang++
|
- cc=clang cxx=clang++
|
||||||
- BUILD_TYPE=Debug
|
|
||||||
- ASAN=ON
|
|
||||||
|
|
||||||
# XCode 8.3
|
# XCode 8.3
|
||||||
- os: osx
|
- os: osx
|
||||||
osx_image: xcode8.3
|
osx_image: xcode8.3
|
||||||
env:
|
env:
|
||||||
- cc=clang cxx=clang++
|
- cc=clang cxx=clang++
|
||||||
- BUILD_TYPE=Debug
|
|
||||||
- ASAN=ON
|
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
# Coverity: don't use addons.coverity_scan since it run on every job of the build matrix, which waste resources and exhausts quotas
|
# Coverity: don't use addons.coverity_scan since it run on every job of the build matrix, which waste resources and exhausts quotas
|
||||||
# Note: the job dedicated to Coverity need to only run the shell script and then exit (to not try to build and run unit tests etc.)
|
# Note: the job dedicated to Coverity need to only run the shell script and then exit (to not try to build and run unit tests etc.)
|
||||||
- if [[ -n "$COVERITY_SCAN_PROJECT_NAME" ]] ; then curl -s https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh | bash ; exit 0 ; fi
|
- if [[ -n "$COVERITY_SCAN_PROJECT_NAME" ]] ; then curl -s https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh | bash ; exit 0 ; fi
|
||||||
|
|
||||||
- if [[ "$VALGRIND" == "true" ]]; then sudo apt-get install -qq valgrind ; fi
|
- if [[ "$INTERNAL_SQLITE" == "OFF" ]]; then sudo apt-get install libsqlite3-dev ; fi
|
||||||
|
- if [[ "$VALGRIND" == "true" ]]; then sudo apt-get install valgrind ; fi
|
||||||
- if [[ "$COVERALLS" == "true" ]]; then pip install --user cpp-coveralls ; fi
|
- if [[ "$COVERALLS" == "true" ]]; then pip install --user cpp-coveralls ; fi
|
||||||
|
|
||||||
# Set the compiler environment variables properly
|
# Set the compiler environment variables properly
|
||||||
@ -117,7 +116,7 @@ before_install:
|
|||||||
before_script:
|
before_script:
|
||||||
- mkdir build
|
- mkdir build
|
||||||
- cd build
|
- cd build
|
||||||
- cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSQLITECPP_USE_ASAN=$ASAN -DSQLITECPP_USE_GCOV=$GCOV -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON ..
|
- cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSQLITECPP_INTERNAL_SQLITE=$INTERNAL_SQLITE -DSQLITECPP_USE_ASAN=$ASAN -DSQLITECPP_USE_GCOV=$GCOV -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON ..
|
||||||
|
|
||||||
# build examples, and run tests (ie make & make test)
|
# build examples, and run tests (ie make & make test)
|
||||||
script:
|
script:
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
# Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
|
# Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
|
||||||
# or copy at http://opensource.org/licenses/MIT)
|
# or copy at http://opensource.org/licenses/MIT)
|
||||||
cmake_minimum_required(VERSION 3.1) # for "CMAKE_CXX_STANDARD" version
|
cmake_minimum_required(VERSION 3.1) # for "CMAKE_CXX_STANDARD" version
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") # custom CMake modules like FindSQLiteCpp
|
||||||
project(SQLiteCpp VERSION "2.99")
|
project(SQLiteCpp VERSION "2.99")
|
||||||
|
|
||||||
# SQLiteC++ 3.x now requires C++11 compiler
|
# SQLiteC++ 3.x now requires C++11 compiler
|
||||||
@ -154,6 +155,8 @@ set(SQLITECPP_SCRIPT
|
|||||||
cpplint.py
|
cpplint.py
|
||||||
Doxyfile
|
Doxyfile
|
||||||
cmake/FindSQLiteCpp.cmake
|
cmake/FindSQLiteCpp.cmake
|
||||||
|
cmake/FindSQLite3.cmake
|
||||||
|
cmake/SQLiteCppConfig.cmake.in
|
||||||
)
|
)
|
||||||
source_group(scripts FILES ${SQLITECPP_SCRIPT})
|
source_group(scripts FILES ${SQLITECPP_SCRIPT})
|
||||||
|
|
||||||
@ -246,6 +249,7 @@ install(FILES
|
|||||||
|
|
||||||
option(SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON)
|
option(SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON)
|
||||||
if (SQLITECPP_INTERNAL_SQLITE)
|
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
|
# build the SQLite3 C library (for ease of use/compatibility) versus Linux sqlite3-dev package
|
||||||
add_subdirectory(sqlite3)
|
add_subdirectory(sqlite3)
|
||||||
target_include_directories(sqlite3 PUBLIC "${PROJECT_SOURCE_DIR}/sqlite3")
|
target_include_directories(sqlite3 PUBLIC "${PROJECT_SOURCE_DIR}/sqlite3")
|
||||||
@ -253,8 +257,9 @@ if (SQLITECPP_INTERNAL_SQLITE)
|
|||||||
else (SQLITECPP_INTERNAL_SQLITE)
|
else (SQLITECPP_INTERNAL_SQLITE)
|
||||||
find_package (SQLite3 REQUIRED)
|
find_package (SQLite3 REQUIRED)
|
||||||
if (SQLITE3_FOUND)
|
if (SQLITE3_FOUND)
|
||||||
|
message(STATUS "Link to sqlite3 system library")
|
||||||
include_directories(${SQLITE3_INCLUDE_DIRS})
|
include_directories(${SQLITE3_INCLUDE_DIRS})
|
||||||
target_link_libraries (SQLiteCpp ${SQLITE3_LIBRARIES})
|
target_link_libraries(SQLiteCpp ${SQLITE3_LIBRARIES})
|
||||||
endif (SQLITE3_FOUND)
|
endif (SQLITE3_FOUND)
|
||||||
endif (SQLITECPP_INTERNAL_SQLITE)
|
endif (SQLITECPP_INTERNAL_SQLITE)
|
||||||
|
|
||||||
@ -336,7 +341,7 @@ if (SQLITECPP_BUILD_TESTS)
|
|||||||
else (GTEST_FOUND)
|
else (GTEST_FOUND)
|
||||||
# deactivate some warnings for compiling the googletest library
|
# deactivate some warnings for compiling the googletest library
|
||||||
if (NOT MSVC)
|
if (NOT MSVC)
|
||||||
add_compile_options(-Wno-variadic-macros -Wno-long-long -Wno-switch-enum -Wno-float-equal -Wno-conversion-null -Wno-switch-default -Wno-pedantic)
|
add_compile_options(-Wno-switch-enum)
|
||||||
endif (NOT MSVC)
|
endif (NOT MSVC)
|
||||||
|
|
||||||
# add the subdirectory containing the CMakeLists.txt for the googletest library
|
# add the subdirectory containing the CMakeLists.txt for the googletest library
|
||||||
|
66
cmake/FindSQLite3.cmake
Normal file
66
cmake/FindSQLite3.cmake
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||||
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||||
|
|
||||||
|
#[=======================================================================[.rst:
|
||||||
|
FindSQLite3
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Find the SQLite libraries, v3
|
||||||
|
|
||||||
|
IMPORTED targets
|
||||||
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
This module defines the following :prop_tgt:`IMPORTED` target:
|
||||||
|
|
||||||
|
``SQLite::SQLite3``
|
||||||
|
|
||||||
|
Result variables
|
||||||
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
This module will set the following variables if found:
|
||||||
|
|
||||||
|
``SQLite3_INCLUDE_DIRS``
|
||||||
|
where to find sqlite3.h, etc.
|
||||||
|
``SQLite3_LIBRARIES``
|
||||||
|
the libraries to link against to use SQLite3.
|
||||||
|
``SQLite3_VERSION``
|
||||||
|
version of the SQLite3 library found
|
||||||
|
``SQLite3_FOUND``
|
||||||
|
TRUE if found
|
||||||
|
|
||||||
|
#]=======================================================================]
|
||||||
|
|
||||||
|
# Look for the necessary header
|
||||||
|
find_path(SQLite3_INCLUDE_DIR NAMES sqlite3.h)
|
||||||
|
mark_as_advanced(SQLite3_INCLUDE_DIR)
|
||||||
|
|
||||||
|
# Look for the necessary library
|
||||||
|
find_library(SQLite3_LIBRARY NAMES sqlite3 sqlite)
|
||||||
|
mark_as_advanced(SQLite3_LIBRARY)
|
||||||
|
|
||||||
|
# Extract version information from the header file
|
||||||
|
if(SQLite3_INCLUDE_DIR)
|
||||||
|
file(STRINGS ${SQLite3_INCLUDE_DIR}/sqlite3.h _ver_line
|
||||||
|
REGEX "^#define SQLITE_VERSION *\"[0-9]+\\.[0-9]+\\.[0-9]+\""
|
||||||
|
LIMIT_COUNT 1)
|
||||||
|
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
|
||||||
|
SQLite3_VERSION "${_ver_line}")
|
||||||
|
unset(_ver_line)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
|
||||||
|
find_package_handle_standard_args(SQLite3
|
||||||
|
REQUIRED_VARS SQLite3_INCLUDE_DIR SQLite3_LIBRARY
|
||||||
|
VERSION_VAR SQLite3_VERSION)
|
||||||
|
|
||||||
|
# Create the imported target
|
||||||
|
if(SQLite3_FOUND)
|
||||||
|
set(SQLite3_INCLUDE_DIRS ${SQLite3_INCLUDE_DIR})
|
||||||
|
set(SQLite3_LIBRARIES ${SQLite3_LIBRARY})
|
||||||
|
if(NOT TARGET SQLite::SQLite3)
|
||||||
|
add_library(SQLite::SQLite3 UNKNOWN IMPORTED)
|
||||||
|
set_target_properties(SQLite::SQLite3 PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${SQLite3_LIBRARY}"
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${SQLite3_INCLUDE_DIR}")
|
||||||
|
endif()
|
||||||
|
endif()
|
Loading…
x
Reference in New Issue
Block a user