mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-20 21:40:15 +08:00
FindSQLite3: Add module to find SQLite3
This commit is contained in:
@@ -237,6 +237,7 @@ They are normally called through the :command:`find_package` command.
|
|||||||
/module/FindSDL_ttf
|
/module/FindSDL_ttf
|
||||||
/module/FindSelfPackers
|
/module/FindSelfPackers
|
||||||
/module/FindSquish
|
/module/FindSquish
|
||||||
|
/module/FindSQLite3
|
||||||
/module/FindSubversion
|
/module/FindSubversion
|
||||||
/module/FindSWIG
|
/module/FindSWIG
|
||||||
/module/FindTCL
|
/module/FindTCL
|
||||||
|
1
Help/module/FindSQLite3.rst
Normal file
1
Help/module/FindSQLite3.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.. cmake-module:: ../../Modules/FindSQLite3.cmake
|
4
Help/release/dev/FindSQLite3-module.rst
Normal file
4
Help/release/dev/FindSQLite3-module.rst
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
FindSQLite3-module
|
||||||
|
------------------
|
||||||
|
|
||||||
|
* The :module:`FindSQLite3` module was added to find the SQLite v3.x library.
|
66
Modules/FindSQLite3.cmake
Normal file
66
Modules/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_CURRENT_LIST_DIR}/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()
|
@@ -1469,6 +1469,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
|
|||||||
add_subdirectory(FindProtobuf)
|
add_subdirectory(FindProtobuf)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(CMake_TEST_FindSQLite3)
|
||||||
|
add_subdirectory(FindSQLite3)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(CMake_TEST_FindTIFF)
|
if(CMake_TEST_FindTIFF)
|
||||||
add_subdirectory(FindTIFF)
|
add_subdirectory(FindTIFF)
|
||||||
endif()
|
endif()
|
||||||
|
10
Tests/FindSQLite3/CMakeLists.txt
Normal file
10
Tests/FindSQLite3/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
add_test(NAME FindSQLite3.Test COMMAND
|
||||||
|
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
|
||||||
|
--build-and-test
|
||||||
|
"${CMake_SOURCE_DIR}/Tests/FindSQLite3/Test"
|
||||||
|
"${CMake_BINARY_DIR}/Tests/FindSQLite3/Test"
|
||||||
|
${build_generator_args}
|
||||||
|
--build-project TestFindSQLite3
|
||||||
|
--build-options ${build_options}
|
||||||
|
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
|
||||||
|
)
|
16
Tests/FindSQLite3/Test/CMakeLists.txt
Normal file
16
Tests/FindSQLite3/Test/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.4)
|
||||||
|
project(TestFindSQLite3 C)
|
||||||
|
include(CTest)
|
||||||
|
|
||||||
|
find_package(SQLite3 REQUIRED)
|
||||||
|
|
||||||
|
add_definitions(-DCMAKE_EXPECTED_SQLite3_VERSION="${SQLite3_VERSION}")
|
||||||
|
|
||||||
|
add_executable(test_tgt main.c)
|
||||||
|
target_link_libraries(test_tgt SQLite::SQLite3)
|
||||||
|
add_test(NAME test_tgt COMMAND test_tgt)
|
||||||
|
|
||||||
|
add_executable(test_var main.c)
|
||||||
|
target_include_directories(test_var PRIVATE ${SQLite3_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(test_var PRIVATE ${SQLite3_LIBRARIES})
|
||||||
|
add_test(NAME test_var COMMAND test_var)
|
10
Tests/FindSQLite3/Test/main.c
Normal file
10
Tests/FindSQLite3/Test/main.c
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <sqlite3.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
char sqlite3_version[] = SQLITE_VERSION;
|
||||||
|
|
||||||
|
return strcmp(sqlite3_version, CMAKE_EXPECTED_SQLite3_VERSION);
|
||||||
|
}
|
Reference in New Issue
Block a user