1# Find Sqlite3
2# ~~~~~~~~~~~~
3# Copyright (c) 2007, Martin Dobias <wonder.sk at gmail.com>
4# Redistribution and use is allowed according to the terms of the BSD license.
5# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
6#
7# CMake module to search for Sqlite3 library
8#
9# If it's found it sets SQLITE3_FOUND to TRUE
10# and following variables are set:
11#    SQLITE3_INCLUDE_DIR
12#    SQLITE3_LIBRARY
13#    SQLITE3_VERSION
14
15
16# find_path and find_library normally search standard locations
17# before the specified paths. To search non-standard paths first,
18# FIND_* is invoked first with specified paths and NO_DEFAULT_PATH
19# and then again with no specified paths to search the default
20# locations. When an earlier FIND_* succeeds, subsequent FIND_*s
21# searching for the same item do nothing.
22
23# try to use framework on mac
24# want clean framework path, not unix compatibility path
25if(APPLE)
26  if(CMAKE_FIND_FRAMEWORK MATCHES "FIRST"
27      OR CMAKE_FRAMEWORK_PATH MATCHES "ONLY"
28      OR NOT CMAKE_FIND_FRAMEWORK)
29    set(CMAKE_FIND_FRAMEWORK_save ${CMAKE_FIND_FRAMEWORK} CACHE STRING "" FORCE)
30    set(CMAKE_FIND_FRAMEWORK "ONLY" CACHE STRING "" FORCE)
31    #find_path(SQLITE3_INCLUDE_DIR SQLite3/sqlite3.h)
32    find_library(SQLITE3_LIBRARY SQLite3)
33    if(SQLITE3_LIBRARY)
34      # find_path doesn't add "Headers" for a framework
35      set(SQLITE3_INCLUDE_DIR ${SQLITE3_LIBRARY}/Headers
36        CACHE PATH "Path to a file.")
37    endif()
38    set(CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_save} CACHE STRING "" FORCE)
39  endif()
40endif()
41
42find_path(SQLITE3_INCLUDE_DIR sqlite3.h
43  "$ENV{LIB_DIR}/include"
44  "$ENV{LIB_DIR}/include/sqlite"
45  "$ENV{INCLUDE}"
46)
47
48find_library(SQLITE3_LIBRARY NAMES sqlite3_i sqlite3 PATHS
49  "$ENV{LIB_DIR}/lib"
50  "$ENV{LIB}/lib"
51)
52
53if(SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY)
54  set(SQLITE3_FOUND TRUE)
55endif()
56
57# Extract version information from the header file
58if(SQLITE3_INCLUDE_DIR)
59    file(STRINGS ${SQLITE3_INCLUDE_DIR}/sqlite3.h _ver_line
60         REGEX "^#define SQLITE_VERSION  *\"[0-9]+\\.[0-9]+\\.[0-9]+\""
61         LIMIT_COUNT 1)
62    string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
63           SQLITE3_VERSION "${_ver_line}")
64    unset(_ver_line)
65endif()
66
67
68if(SQLITE3_FOUND)
69  if(NOT SQLITE3_FIND_QUIETLY)
70    message(STATUS "Found Sqlite3: ${SQLITE3_LIBRARY}")
71    message(STATUS "Sqlite3 version: ${SQLITE3_VERSION}")
72  endif()
73
74else()
75
76  if(SQLITE3_FIND_REQUIRED)
77    message(FATAL_ERROR "Could not find Sqlite3")
78  endif()
79
80endif()
81