FindSoci.cmake 2.99 KB
Newer Older
Benjamin REIS's avatar
Benjamin REIS committed
1 2 3 4 5 6 7
###############################################################################
# CMake module to search for SOCI library
#
# WARNING: This module is experimental work in progress.
#
# This module defines:
#  SOCI_INCLUDE_DIRS        = include dirs to be used when using the soci library
8
#  SOCI_LIBRARIES           = full path to the soci library
Benjamin REIS's avatar
Benjamin REIS committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#  SOCI_VERSION             = the soci version found (not yet. soci does not provide that info.)
#  SOCI_FOUND               = true if soci was found
#
# For each component you specify in find_package(), the following variables are set.
#
#  SOCI_${COMPONENT}_PLUGIN = full path to the soci plugin
#  SOCI_${COMPONENT}_FOUND
#
# Copyright (c) 2011 Michael Jansen <info@michael-jansen.biz>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
###############################################################################
#
### Global Configuration Section
#
26 27 28
if(ANDROID)
SET(_SOCI_ALL_PLUGINS    sqlite3)
else()
29
SET(_SOCI_ALL_PLUGINS    mysql sqlite3)
30 31
endif()

32
SET(_SOCI_REQUIRED_VARS  SOCI_INCLUDE_DIRS SOCI_LIBRARIES)
33
SET(_SOCI_VERSION "_4_0")
Benjamin REIS's avatar
Benjamin REIS committed
34 35 36 37

#
### FIRST STEP: Find the soci headers.
#
jehan's avatar
jehan committed
38
FIND_PATH(SOCI_INCLUDE_DIRS soci/soci.h
Benjamin REIS's avatar
Benjamin REIS committed
39
    DOC "Soci (http://soci.sourceforge.net) include directory")
40
MARK_AS_ADVANCED(SOCI_INCLUDE_DIRS)
Benjamin REIS's avatar
Benjamin REIS committed
41 42 43 44

#
### SECOND STEP: Find the soci core library. Respect LIB_SUFFIX
#
45
FIND_LIBRARY(SOCI_LIBRARIES
46
    NAMES soci_core soci_core${_SOCI_VERSION}
47 48
    PATH_SUFFIXES lib lib64)
MARK_AS_ADVANCED(SOCI_LIBRARIES)
Benjamin REIS's avatar
Benjamin REIS committed
49

50
GET_FILENAME_COMPONENT(SOCI_LIBRARY_DIR ${SOCI_LIBRARIES} PATH)
Benjamin REIS's avatar
Benjamin REIS committed
51 52 53 54 55
MARK_AS_ADVANCED(SOCI_LIBRARY_DIR)

#
### THIRD STEP: Find all installed plugins if the library was found
#
56
IF(SOCI_INCLUDE_DIRS AND SOCI_LIBRARIES)
Benjamin REIS's avatar
Benjamin REIS committed
57 58 59 60 61 62

    MESSAGE(STATUS "Soci found: Looking for plugins")
    FOREACH(plugin IN LISTS _SOCI_ALL_PLUGINS)

        FIND_LIBRARY(
            SOCI_${plugin}_PLUGIN
63
            NAMES soci_${plugin} soci_${plugin}${_SOCI_VERSION}
64
            PATH_SUFFIXES lib lib64)
Benjamin REIS's avatar
Benjamin REIS committed
65 66 67 68 69
        MARK_AS_ADVANCED(SOCI_${plugin}_PLUGIN)

        IF(SOCI_${plugin}_PLUGIN)
            MESSAGE(STATUS "    * Plugin ${plugin} found ${SOCI_${plugin}_PLUGIN}.")
            SET(SOCI_${plugin}_FOUND True)
70 71 72 73

            if(IOS OR ANDROID)
                list(APPEND SOCI_LIBRARIES ${SOCI_${plugin}_PLUGIN})
            endif()
Benjamin REIS's avatar
Benjamin REIS committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
        ELSE()
            MESSAGE(STATUS "    * Plugin ${plugin} not found.")
            SET(SOCI_${plugin}_FOUND False)
        ENDIF()

    ENDFOREACH()

    #
    ### FOURTH CHECK: Check if the required components were all found
    #
    FOREACH(component ${Soci_FIND_COMPONENTS})
        IF(NOT SOCI_${component}_FOUND)
            MESSAGE(SEND_ERROR "Required component ${component} not found. It seems that Soci was built without support of ${component}, consider rebuilding it.")
        ENDIF()
    ENDFOREACH()

ENDIF()

#
### ADHERE TO STANDARDS
#
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Soci DEFAULT_MSG ${_SOCI_REQUIRED_VARS})