From fe40570608f43aade8f4262e9ca55d98a2b169fd Mon Sep 17 00:00:00 2001 From: Chuck Atkins Date: Thu, 1 Nov 2018 16:48:56 -0400 Subject: FindSQLite3: Add module to find SQLite3 --- Help/manual/cmake-modules.7.rst | 1 + Help/module/FindSQLite3.rst | 1 + Help/release/dev/FindSQLite3-module.rst | 4 ++ Modules/FindSQLite3.cmake | 66 +++++++++++++++++++++++++++++++++ Tests/CMakeLists.txt | 4 ++ Tests/FindSQLite3/CMakeLists.txt | 10 +++++ Tests/FindSQLite3/Test/CMakeLists.txt | 16 ++++++++ Tests/FindSQLite3/Test/main.c | 10 +++++ 8 files changed, 112 insertions(+) create mode 100644 Help/module/FindSQLite3.rst create mode 100644 Help/release/dev/FindSQLite3-module.rst create mode 100644 Modules/FindSQLite3.cmake create mode 100644 Tests/FindSQLite3/CMakeLists.txt create mode 100644 Tests/FindSQLite3/Test/CMakeLists.txt create mode 100644 Tests/FindSQLite3/Test/main.c diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst index c0bef08..95744df 100644 --- a/Help/manual/cmake-modules.7.rst +++ b/Help/manual/cmake-modules.7.rst @@ -237,6 +237,7 @@ They are normally called through the :command:`find_package` command. /module/FindSDL_ttf /module/FindSelfPackers /module/FindSquish + /module/FindSQLite3 /module/FindSubversion /module/FindSWIG /module/FindTCL diff --git a/Help/module/FindSQLite3.rst b/Help/module/FindSQLite3.rst new file mode 100644 index 0000000..d1910e5 --- /dev/null +++ b/Help/module/FindSQLite3.rst @@ -0,0 +1 @@ +.. cmake-module:: ../../Modules/FindSQLite3.cmake diff --git a/Help/release/dev/FindSQLite3-module.rst b/Help/release/dev/FindSQLite3-module.rst new file mode 100644 index 0000000..733a4d3 --- /dev/null +++ b/Help/release/dev/FindSQLite3-module.rst @@ -0,0 +1,4 @@ +FindSQLite3-module +------------------ + +* The :module:`FindSQLite3` module was added to find the SQLite v3.x library. diff --git a/Modules/FindSQLite3.cmake b/Modules/FindSQLite3.cmake new file mode 100644 index 0000000..374d7af --- /dev/null +++ b/Modules/FindSQLite3.cmake @@ -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() diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 1c49fea..02e56eb 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1469,6 +1469,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release add_subdirectory(FindProtobuf) endif() + if(CMake_TEST_FindSQLite3) + add_subdirectory(FindSQLite3) + endif() + if(CMake_TEST_FindTIFF) add_subdirectory(FindTIFF) endif() diff --git a/Tests/FindSQLite3/CMakeLists.txt b/Tests/FindSQLite3/CMakeLists.txt new file mode 100644 index 0000000..8bf170e --- /dev/null +++ b/Tests/FindSQLite3/CMakeLists.txt @@ -0,0 +1,10 @@ +add_test(NAME FindSQLite3.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --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 $ + ) diff --git a/Tests/FindSQLite3/Test/CMakeLists.txt b/Tests/FindSQLite3/Test/CMakeLists.txt new file mode 100644 index 0000000..bcc6ebd --- /dev/null +++ b/Tests/FindSQLite3/Test/CMakeLists.txt @@ -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) diff --git a/Tests/FindSQLite3/Test/main.c b/Tests/FindSQLite3/Test/main.c new file mode 100644 index 0000000..aeb4940 --- /dev/null +++ b/Tests/FindSQLite3/Test/main.c @@ -0,0 +1,10 @@ +#include + +#include + +int main() +{ + char sqlite3_version[] = SQLITE_VERSION; + + return strcmp(sqlite3_version, CMAKE_EXPECTED_SQLite3_VERSION); +} -- cgit v0.12