Warning, /pim/akonadi/cmake/modules/FindSqlite.cmake is written in an unsupported language. File is not indexed.

0001 #
0002 # - Try to find Sqlite
0003 # Once done this will define
0004 #
0005 #  SQLITE_FOUND - system has Sqlite
0006 #  SQLITE_INCLUDE_DIR - the Sqlite include directory
0007 #  SQLITE_LIBRARIES - Link these to use Sqlite
0008 #  SQLITE_MIN_VERSION - The minimum SQLite version
0009 #
0010 # SPDX-FileCopyrightText: 2008 Gilles Caulier <caulier.gilles@gmail.com>
0011 # SPDX-FileCopyrightText: 2010 Christophe Giboudeaux <cgiboudeaux@gmail.com>
0012 # SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
0013 #
0014 # SPDX-License-Identifier: BSD-3-Clause
0015 #
0016 if(NOT SQLITE_MIN_VERSION)
0017   set(SQLITE_MIN_VERSION "3.6.16")
0018 endif(NOT SQLITE_MIN_VERSION)
0019 
0020 if ( SQLITE_INCLUDE_DIR AND SQLITE_LIBRARIES )
0021    # in cache already
0022    SET(Sqlite_FIND_QUIETLY TRUE)
0023 endif ( SQLITE_INCLUDE_DIR AND SQLITE_LIBRARIES )
0024 
0025 # use pkg-config to get the directories and then use these values
0026 # in the FIND_PATH() and FIND_LIBRARY() calls
0027 if( NOT WIN32 )
0028   find_package(PkgConfig)
0029 
0030   pkg_check_modules(PC_SQLITE sqlite3)
0031 
0032   set(SQLITE_DEFINITIONS ${PC_SQLITE_CFLAGS_OTHER})
0033 endif( NOT WIN32 )
0034 
0035 if(PC_SQLITE_FOUND)
0036   find_path(SQLITE_INCLUDE_DIR
0037             NAMES sqlite3.h
0038             PATHS ${PC_SQLITE_INCLUDEDIR}
0039             NO_DEFAULT_PATH
0040            )
0041 
0042   find_library(SQLITE_LIBRARIES
0043                NAMES sqlite3
0044                PATHS ${PC_SQLITE_LIBDIR}
0045                NO_DEFAULT_PATH
0046               )
0047 else(PC_SQLITE_FOUND)
0048   find_path(SQLITE_INCLUDE_DIR
0049             NAMES sqlite3.h
0050            )
0051 
0052   find_library(SQLITE_LIBRARIES
0053                NAMES sqlite3
0054               )
0055 endif(PC_SQLITE_FOUND)
0056 
0057 if( UNIX )
0058   find_file(SQLITE_STATIC_LIBRARIES
0059             libsqlite3.a
0060             ${PC_SQLITE_LIBDIR}
0061            )
0062 else( UNIX )
0063   # todo find static libs for other systems
0064   # fallback to standard libs
0065   set( SQLITE_STATIC_LIBRARIES ${SQLITE_LIBRARIES} )
0066 endif( UNIX )
0067 
0068 if(EXISTS ${SQLITE_INCLUDE_DIR}/sqlite3.h)
0069   file(READ ${SQLITE_INCLUDE_DIR}/sqlite3.h SQLITE3_H_CONTENT)
0070   string(REGEX MATCH "SQLITE_VERSION[ ]*\"[0-9.]*\"\n" SQLITE_VERSION_MATCH "${SQLITE3_H_CONTENT}")
0071 
0072   if(SQLITE_VERSION_MATCH)
0073     string(REGEX REPLACE ".*SQLITE_VERSION[ ]*\"(.*)\"\n" "\\1" SQLITE_VERSION ${SQLITE_VERSION_MATCH})
0074 
0075     if(SQLITE_VERSION VERSION_LESS "${SQLITE_MIN_VERSION}")
0076         message(STATUS "Sqlite ${SQLITE_VERSION} was found, but at least version ${SQLITE_MIN_VERSION} is required")
0077         set(SQLITE_VERSION_OK FALSE)
0078     else(SQLITE_VERSION VERSION_LESS "${SQLITE_MIN_VERSION}")
0079         set(SQLITE_VERSION_OK TRUE)
0080     endif(SQLITE_VERSION VERSION_LESS "${SQLITE_MIN_VERSION}")
0081 
0082   endif(SQLITE_VERSION_MATCH)
0083 
0084   if (SQLITE_VERSION_OK)
0085     file(WRITE ${CMAKE_BINARY_DIR}/sqlite_check_unlock_notify.cpp
0086          "#include <sqlite3.h>
0087           int main(int argc, char **argv) {
0088             return sqlite3_unlock_notify(0, 0, 0);
0089           }")
0090     try_compile(SQLITE_HAS_UNLOCK_NOTIFY
0091                 ${CMAKE_BINARY_DIR}/sqlite_check_unlock_notify
0092                 ${CMAKE_BINARY_DIR}/sqlite_check_unlock_notify.cpp
0093                 LINK_LIBRARIES ${SQLITE_LIBRARIES}
0094                 CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:PATH=${SQLITE_INCLUDE_DIR}")
0095     if (NOT SQLITE_HAS_UNLOCK_NOTIFY)
0096         message(STATUS "Sqlite ${SQLITE_VERSION} was found, but it is not compiled with -DSQLITE_ENABLE_UNLOCK_NOTIFY")
0097     endif()
0098   endif()
0099 endif()
0100 
0101 include(FindPackageHandleStandardArgs)
0102 find_package_handle_standard_args( Sqlite DEFAULT_MSG
0103                                    SQLITE_INCLUDE_DIR
0104                                    SQLITE_LIBRARIES
0105                                    SQLITE_VERSION_OK
0106                                    SQLITE_HAS_UNLOCK_NOTIFY)
0107 
0108 if(Sqlite_FOUND AND NOT TARGET Sqlite::Sqlite)
0109   add_library(Sqlite::Sqlite UNKNOWN IMPORTED)
0110   set_target_properties(Sqlite::Sqlite PROPERTIES
0111     IMPORTED_LOCATION "${SQLITE_LIBRARIES}"
0112     INTERFACE_INCLUDE_DIRECTORIES "${SQLITE_INCLUDE_DIR}"
0113   )
0114 endif()
0115 
0116 # show the SQLITE_INCLUDE_DIR and SQLITE_LIBRARIES variables only in the advanced view
0117 mark_as_advanced( SQLITE_INCLUDE_DIR SQLITE_LIBRARIES )
0118