#  (The MIT License)
#
#  Copyright (c) 2015 Mohammad S. Babaei
#
#  Permission is hereby granted, free of charge, to any person obtaining a copy
#  of this software and associated documentation files (the "Software"), to deal
#  in the Software without restriction, including without limitation the rights
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#  copies of the Software, and to permit persons to whom the Software is
#  furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in
#  all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#  THE SOFTWARE.


SET ( Boost_FIND_REQUIRED TRUE )
SET ( Boost_USE_MULTITHREADED ON )
SET ( Boost_USE_STATIC_LIBS OFF )
SET ( Boost_USE_STATIC_RUNTIME OFF )
SET ( CPPDB_FIND_REQUIRED TRUE )
SET ( CPPDB_MYSQL_DRIVER_FIND_REQUIRED FALSE )
SET ( CPPDB_PGSQL_DRIVER_FIND_REQUIRED FALSE )
SET ( CPPDB_SQLITE3_DRIVER_FIND_REQUIRED TRUE )
SET ( CRYPTOPP_FIND_REQUIRED TRUE )
SET ( CURLPP_FIND_REQUIRED TRUE )
SET ( GEOIP_FIND_REQUIRED TRUE )
SET ( GIT_FIND_REQUIRED TRUE )
SET ( GRAPHICS_MAGICKPP_FIND_REQUIRED FALSE )
SET ( GRAPHICS_MAGICK_FIND_REQUIRED FALSE )
SET ( GRAPHICS_MAGICK_WAND_FIND_REQUIRED FALSE )
SET ( GRAPHICS_MAGICKPP_CONFIG_FIND_REQUIRED FALSE )
SET ( GRAPHICS_MAGICK_CONFIG_FIND_REQUIRED FALSE )
SET ( GRAPHICS_MAGICK_WAND_CONFIG_FIND_REQUIRED FALSE )
SET ( GULP_FIND_REQUIRED TRUE )
SET ( GEOLITE_COUNTRY_FIND_REQUIRED TRUE )
SET ( GEOLITE_CITY_FIND_REQUIRED TRUE )
SET ( IMAGE_MAGICKPP_FIND_REQUIRED FALSE )
SET ( IMAGE_MAGICK_CORE_FIND_REQUIRED FALSE )
SET ( IMAGE_MAGICK_WAND_FIND_REQUIRED FALSE )
SET ( IMAGE_MAGICKPP_CONFIG_FIND_REQUIRED FALSE )
SET ( IMAGE_MAGICK_CONFIG_FIND_REQUIRED FALSE )
SET ( IMAGE_MAGICK_CORE_CONFIG_FIND_REQUIRED FALSE )
SET ( IMAGE_MAGICK_WAND_CONFIG_FIND_REQUIRED FALSE )
SET ( KVM_FIND_REQUIRED TRUE )
SET ( LIBB64_FIND_REQUIRED TRUE )
SET ( LIBCURL_FIND_REQUIRED TRUE )
SET ( LIBSTATGRAB_FIND_REQUIRED TRUE )
SET ( LIBZIP_FIND_REQUIRED TRUE )
SET ( MAGICKPP_FIND_REQUIRED TRUE )
SET ( MYSQL_FIND_REQUIRED FALSE )
SET ( NPM_FIND_REQUIRED TRUE )
SET ( PGSQL_FIND_REQUIRED FALSE )
SET ( SQLITE3_FIND_REQUIRED TRUE )
SET ( Threads_FIND_REQUIRED TRUE )
SET ( VMIME_FIND_REQUIRED TRUE )
SET ( WT_FIND_REQUIRED TRUE )
IF ( "${WT_APPLICATION_TYPE}" STREQUAL "FASTCGI" )
    SET ( WT_FCGI_FIND_REQUIRED TRUE )
    SET ( WT_HTTPD_FIND_REQUIRED FALSE )
ELSEIF ( "${WT_APPLICATION_TYPE}" STREQUAL "WTHTTPD" )
    SET ( WT_FCGI_FIND_REQUIRED FALSE )
    SET ( WT_HTTPD_FIND_REQUIRED TRUE )
ENDIF (  )
SET ( WT_RESOURCES_FIND_REQUIRED TRUE )

SET ( PREFERRED_MAGICK_IMPLEMENTATION "GM" CACHE STRING "" )
SET_PROPERTY( CACHE PREFERRED_MAGICK_IMPLEMENTATION PROPERTY STRINGS "GM" "IM" )



### Boost ###
FIND_PACKAGE (Boost 1.55.0
    COMPONENTS
        #bzip2 date_time filesystem iostreams regex system thread zlib
        date_time filesystem iostreams random regex system thread
    )
INCLUDE_DIRECTORIES ( SYSTEM ${Boost_INCLUDE_DIRS} )


### CppDB ###
FIND_PACKAGE ( CppDB )
INCLUDE_DIRECTORIES ( SYSTEM ${CPPDB_INCLUDE_DIR} )


### Crypto++ ###
FIND_PACKAGE ( Cryptopp )
INCLUDE_DIRECTORIES ( SYSTEM ${CRYPTOPP_INCLUDE_DIR} )


### cURLpp ###
FIND_PACKAGE ( cURLpp )
INCLUDE_DIRECTORIES ( SYSTEM ${CURLPP_INCLUDE_DIR} )


### GeoIP ###
FIND_PACKAGE ( GeoIP )
INCLUDE_DIRECTORIES ( SYSTEM ${GEOIP_INCLUDE_DIR} )


### Git ###
FIND_PACKAGE ( Git )
IF ( NOT GIT_FOUND )
    IF ( GIT_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find Git" )
    ENDIF (  )
ENDIF (  )


### Gulp ###
FIND_PACKAGE ( Gulp )


### kvm ###
IF ( ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" )
    FIND_PACKAGE ( KVM )
    LINK_DIRECTORIES ( ${KVM_LIBRARY} )
ENDIF (  )


### libb64 ###
FIND_PACKAGE ( libb64 )
INCLUDE_DIRECTORIES ( SYSTEM ${LIBB64_INCLUDE_DIR} )


### libcurl ###
FIND_PACKAGE ( libcurl )
INCLUDE_DIRECTORIES ( SYSTEM ${LIBCURL_INCLUDE_DIR} )


### libstatgrab ###
FIND_PACKAGE ( libstatgrab )
INCLUDE_DIRECTORIES ( SYSTEM ${LIBSTATGRAB_INCLUDE_DIR} )


### libzip ###
FIND_PACKAGE ( libzip )
INCLUDE_DIRECTORIES ( SYSTEM ${LIBZIP_INCLUDE_DIR} )


### Magick ###
FIND_PACKAGE ( Magick )
INCLUDE_DIRECTORIES ( SYSTEM ${MAGICKPP_INCLUDE_DIR} )
IF ( ${PREFERRED_MAGICK_IMPLEMENTATION} MATCHES "IM" )
    SET ( MAGICKCORE_QUANTUM_DEPTH 8 )
    SET ( MAGICKCORE_HDRI_ENABLE FALSE )
ENDIF (  )


### MySQL ###
FIND_PACKAGE ( MySQL )
INCLUDE_DIRECTORIES ( SYSTEM ${MYSQL_INCLUDE_DIR} )


### npm ###
FIND_PACKAGE ( npm )


### pgSQL ###
FIND_PACKAGE ( pgSQL )
INCLUDE_DIRECTORIES ( SYSTEM ${PGSQL_INCLUDE_DIR} )


### SQLite 3 ###
FIND_PACKAGE ( SQLite3 )
INCLUDE_DIRECTORIES ( SYSTEM ${SQLITE3_INCLUDE_DIR} )


### Threads ###
FIND_PACKAGE ( Threads )
IF ( NOT Threads_FOUND )
    IF ( Threads_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find Threads" )
    ENDIF (  )
ENDIF (  )

### VMime ###
FIND_PACKAGE ( VMime )
INCLUDE_DIRECTORIES ( SYSTEM ${VMIME_INCLUDE_DIR} )


### Wt ###
FIND_PACKAGE ( Wt )
INCLUDE_DIRECTORIES ( SYSTEM ${WT_INCLUDE_DIR} )


### SQL Drivers Check ###
IF ( NOT DEFINED MYSQL_FOUND
        AND NOT DEFINED PGSQL_FOUND
        AND NOT DEFINED SQLITE3_FOUND )
    MESSAGE ( FATAL_ERROR "Could not find a suitable SQL driver." )
ENDIF (  )

IF ( NOT DEFINED CPPDB_MYSQL_DRIVER_FOUND
        AND NOT DEFINED CPPDB_PGSQL_DRIVER_FOUND
        AND NOT DEFINED CPPDB_SQLITE3_DRIVER_FOUND )
    MESSAGE ( FATAL_ERROR "Could not find a suitable CppDB driver." )
ENDIF (  )


