SET ( Boost_FIND_REQUIRED TRUE )
SET ( Boost_USE_MULTITHREADED ON )
SET ( Boost_USE_STATIC_LIBS OFF )

SET ( CPPDP_FIND_REQUIRED TRUE )

SET ( CRYPTOPP_FIND_REQUIRED TRUE )

SET ( GEOIP_FIND_REQUIRED TRUE )
SET ( GEOLITE_COUNTRY_FIND_REQUIRED TRUE )
SET ( GEOLITE_CITY_FIND_REQUIRED TRUE )

SET ( GM_MAGICKPP_FIND_REQUIRED TRUE )
SET ( GM_MAGICKPP_CONFIG_FIND_REQUIRED TRUE )

SET ( IM_MAGICKPP_FIND_REQUIRED FALSE )
SET ( IM_MAGICKPP_CONFIG_FIND_REQUIRED FALSE )

SET ( POPPLER_CPP_FIND_REQUIRED TRUE )

SET ( SQLITE_FIND_REQUIRED TRUE )

SET ( STATGRAB_FIND_REQUIRED TRUE )

SET ( WT_FIND_REQUIRED TRUE )
SET ( WT_FCGI_FIND_REQUIRED TRUE )



### Boost ###

FIND_PACKAGE (Boost 1.48.0
    COMPONENTS
        date_time filesystem program_options
        random regex signals system thread
    )


IF ( Boost_FOUND )
    SET ( DEP_FOUND TRUE )
ELSE ( Boost_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( Boost_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find Boost" )
    ENDIF ( Boost_FIND_REQUIRED )
ENDIF ( Boost_FOUND )



### CppDB ###

FIND_PATH ( CPPDB_INCLUDE_DIR NAMES cppdb PATHS /usr/include/ /usr/local/include/ )
FIND_LIBRARY ( CPPDB_LIBRARY NAMES cppdb PATHS /usr/lib /usr/local/lib )

IF ( CPPDB_INCLUDE_DIR AND CPPDB_LIBRARY )
    SET ( CPPDB_FOUND TRUE )
ENDIF ( CPPDB_INCLUDE_DIR AND CPPDB_LIBRARY )


IF ( CPPDB_FOUND )
    SET ( DEP_FOUND TRUE )
    IF ( NOT CPPDB_FIND_QUIETLY )
        MESSAGE ( STATUS "Found CppDB:" )
        MESSAGE ( STATUS "  (Headers)       ${CPPDB_INCLUDE_DIR}" )
        MESSAGE ( STATUS "  (Library)       ${CPPDB_LIBRARY}" )
    ENDIF ( NOT CPPDB_FIND_QUIETLY )
ELSE ( CPPDB_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( CPPDB_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find CppDB" )
    ENDIF ( CPPDB_FIND_REQUIRED )
ENDIF ( CPPDB_FOUND )



### Crypto++ ###

FIND_PATH ( CRYPTOPP_INCLUDE_DIR NAMES cryptopp PATHS /usr/include/ /usr/local/include/ )
FIND_LIBRARY ( CRYPTOPP_LIBRARY NAMES cryptopp PATHS /usr/lib /usr/local/lib )

IF ( CRYPTOPP_INCLUDE_DIR AND CRYPTOPP_LIBRARY )
    SET ( CRYPTOPP_FOUND TRUE )
ENDIF ( CRYPTOPP_INCLUDE_DIR AND CRYPTOPP_LIBRARY )


IF ( CRYPTOPP_FOUND )
    SET ( DEP_FOUND TRUE )
    IF ( NOT CRYPTOPP_FIND_QUIETLY )
        MESSAGE ( STATUS "Found Crypto++:" )
        MESSAGE ( STATUS "  (Headers)       ${CRYPTOPP_INCLUDE_DIR}" )
        MESSAGE ( STATUS "  (Library)       ${CRYPTOPP_LIBRARY}" )
    ENDIF ( NOT CRYPTOPP_FIND_QUIETLY )
ELSE ( CRYPTOPP_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( CRYPTOPP_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find Crypto++" )
    ENDIF ( CRYPTOPP_FIND_REQUIRED )
ENDIF ( CRYPTOPP_FOUND )



### GeoIP ###

FIND_PATH ( GEOIP_INCLUDE_DIR NAMES GeoIP.h PATHS /usr/include/ /usr/local/include/ )
FIND_LIBRARY ( GEOIP_LIBRARY NAMES GeoIP PATHS /usr/lib /usr/local/lib )
FIND_FILE ( GEOLITE_COUNTRY_DB NAMES GeoIP/GeoIP.dat PATHS /usr/share/ /usr/local/share/ )
FIND_FILE ( GEOLITE_CITY_DB NAMES GeoIP/GeoLiteCity.dat PATHS /usr/share/ /usr/local/share/ )

IF ( GEOIP_INCLUDE_DIR AND GEOIP_LIBRARY )
    SET ( GEOIP_FOUND TRUE )
ENDIF ( GEOIP_INCLUDE_DIR AND GEOIP_LIBRARY )

IF ( GEOLITE_COUNTRY_DB)
    SET ( GEOLITE_COUNTRY_FOUND TRUE )
ENDIF ( GEOLITE_COUNTRY_DB)

IF ( GEOLITE_CITY_DB)
    SET ( GEOLITE_CITY_FOUND TRUE )
ENDIF ( GEOLITE_CITY_DB)


IF ( GEOIP_FOUND )
    SET ( DEP_FOUND TRUE )
    IF ( NOT GEOIP_FIND_QUIETLY )
        MESSAGE ( STATUS "Found GeoIP:" )
        MESSAGE ( STATUS "  (Headers)       ${GEOIP_INCLUDE_DIR}" )
        MESSAGE ( STATUS "  (Library)       ${GEOIP_LIBRARY}" )
    ENDIF ( NOT GEOIP_FIND_QUIETLY )
ELSE ( GEOIP_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( GEOIP_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find GeoIP" )
    ENDIF ( GEOIP_FIND_REQUIRED )
ENDIF ( GEOIP_FOUND )


IF ( GEOLITE_COUNTRY_FOUND )
    SET ( DEP_FOUND TRUE )
    MESSAGE ( STATUS "  (Country db)    ${GEOLITE_COUNTRY_DB}" )
ELSE ( GEOLITE_COUNTRY_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( GEOLITE_COUNTRY_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find GeoLite-Country db" )
    ENDIF ( GEOLITE_COUNTRY_FIND_REQUIRED )
ENDIF ( GEOLITE_COUNTRY_FOUND )


IF ( GEOLITE_CITY_FOUND )
    SET ( DEP_FOUND TRUE )
    MESSAGE ( STATUS "  (City db)       ${GEOLITE_CITY_DB}" )
ELSE ( GEOLITE_CITY_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( GEOLITE_CITY_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find GeoLite-City db" )
    ENDIF ( GEOLITE_CITY_FIND_REQUIRED )
ENDIF ( GEOLITE_CITY_FOUND )



### GM/Magick++ ###

FIND_PATH ( GM_MAGICKPP_INCLUDE_DIR NAMES GraphicsMagick PATHS /usr/include/ /usr/local/include/ )
FIND_LIBRARY ( GM_MAGICKPP_LIBRARY NAMES GraphicsMagick++ PATHS /usr/lib /usr/local/lib )
FIND_FILE ( GM_MAGICKPP_CONFIG_SCRIPT NAMES GraphicsMagick++-config PATHS /usr/bin /usr/local/bin )

IF ( GM_MAGICKPP_INCLUDE_DIR AND GM_MAGICKPP_LIBRARY )
    SET ( GM_MAGICKPP_FOUND TRUE )
ENDIF ( GM_MAGICKPP_INCLUDE_DIR AND GM_MAGICKPP_LIBRARY )

IF ( GM_MAGICKPP_CONFIG_SCRIPT)
    SET ( GM_MAGICKPP_CONFIG_FOUND TRUE )
ENDIF ( GM_MAGICKPP_CONFIG_SCRIPT)


IF ( GM_MAGICKPP_FOUND )
    SET ( DEP_FOUND TRUE )
    IF ( NOT GM_MAGICKPP_FIND_QUIETLY )
        MESSAGE ( STATUS "Found GraphicsMagick++:" )
        MESSAGE ( STATUS "  (Headers)       ${GM_MAGICKPP_INCLUDE_DIR}" )
        MESSAGE ( STATUS "  (Library)       ${GM_MAGICKPP_LIBRARY}" )
    ENDIF ( NOT GM_MAGICKPP_FIND_QUIETLY )
ELSE ( GM_MAGICKPP_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( GM_MAGICKPP_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find GraphicsMagick++" )
    ENDIF ( GM_MAGICKPP_FIND_REQUIRED )
ENDIF ( GM_MAGICKPP_FOUND )


IF ( GM_MAGICKPP_CONFIG_FOUND )
    SET ( DEP_FOUND TRUE )
    IF ( NOT GM_MAGICKPP_CONFIG_FIND_QUIETLY )
        EXEC_PROGRAM ("${GM_MAGICKPP_CONFIG_SCRIPT}" ARGS --cppflags | sed 's/-I//g' OUTPUT_VARIABLE GM_MAGICKPP_INCLUDE_DIR)
        #EXEC_PROGRAM ("${GM_MAGICKPP_CONFIG_SCRIPT}" ARGS --libs | cut -d ' ' -f '2-99' | sed 's/ -l/ /g' | sed 's/-l//' OUTPUT_VARIABLE GM_MAGICKPP_FLAGS)
        EXEC_PROGRAM ("${GM_MAGICKPP_CONFIG_SCRIPT}" ARGS --libs OUTPUT_VARIABLE GM_MAGICKPP_FLAGS)
        MESSAGE ( STATUS "  (Helper Script) ${GM_MAGICKPP_CONFIG_SCRIPT}" )
    ENDIF ( NOT GM_MAGICKPP_CONFIG_FIND_QUIETLY )
ELSE ( GM_MAGICKPP_CONFIG_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( GM_MAGICKPP_CONFIG_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find GraphicsMagick++ Helper Script" )
    ENDIF ( GM_MAGICKPP_CONFIG_FIND_REQUIRED )
ENDIF ( GM_MAGICKPP_CONFIG_FOUND )



### IM/Magick++ ###

FIND_PATH ( IM_MAGICKPP_INCLUDE_DIR NAMES ImageMagick PATHS /usr/include/ /usr/local/include/ )
FIND_LIBRARY ( IM_MAGICKPP_LIBRARY NAMES Magick++ PATHS /usr/lib /usr/local/lib )
FIND_FILE ( IM_MAGICKPP_CONFIG_SCRIPT NAMES Magick++-config PATHS /usr/bin /usr/local/bin )

IF ( IM_MAGICKPP_INCLUDE_DIR AND IM_MAGICKPP_LIBRARY )
    SET ( IM_MAGICKPP_FOUND TRUE )
ENDIF ( IM_MAGICKPP_INCLUDE_DIR AND IM_MAGICKPP_LIBRARY )

IF ( IM_MAGICKPP_CONFIG_SCRIPT)
    SET ( IM_MAGICKPP_CONFIG_FOUND TRUE )
ENDIF ( IM_MAGICKPP_CONFIG_SCRIPT)


IF ( IM_MAGICKPP_FOUND )
    SET ( DEP_FOUND TRUE )
    IF ( NOT IM_MAGICKPP_FIND_QUIETLY )
        MESSAGE ( STATUS "Found ImageMagick++:" )
        MESSAGE ( STATUS "  (Headers)       ${IM_MAGICKPP_INCLUDE_DIR}" )
        MESSAGE ( STATUS "  (Library)       ${IM_MAGICKPP_LIBRARY}" )
    ENDIF ( NOT IM_MAGICKPP_FIND_QUIETLY )
ELSE ( IM_MAGICKPP_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( IM_MAGICKPP_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find ImageMagick++" )
    ENDIF ( IM_MAGICKPP_FIND_REQUIRED )
ENDIF ( IM_MAGICKPP_FOUND )


IF ( IM_MAGICKPP_CONFIG_FOUND )
    SET ( DEP_FOUND TRUE )
    IF ( NOT IM_MAGICKPP_CONFIG_FIND_QUIETLY )
        EXEC_PROGRAM ("${IM_MAGICKPP_CONFIG_SCRIPT}" ARGS --cppflags | cut -d ' ' -f '1-1' | sed 's/-I//g' | sed 's/-I//g' OUTPUT_VARIABLE IM_MAGICKPP_INCLUDE_DIR)
        #EXEC_PROGRAM ("${IM_MAGICKPP_CONFIG_SCRIPT}" ARGS --libs | cut -d ' ' -f '2-99' | sed 's/ -l/ /g' | sed 's/-l//' OUTPUT_VARIABLE IM_MAGICKPP_FLAGS)
        EXEC_PROGRAM ("${IM_MAGICKPP_CONFIG_SCRIPT}" ARGS --libs OUTPUT_VARIABLE IM_MAGICKPP_FLAGS)
        MESSAGE ( STATUS "  (Helper Script) ${IM_MAGICKPP_CONFIG_SCRIPT}" )
    ENDIF ( NOT IM_MAGICKPP_CONFIG_FIND_QUIETLY )
ELSE ( IM_MAGICKPP_CONFIG_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( IM_MAGICKPP_CONFIG_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find GraphicsMagick++ Helper Script" )
    ENDIF ( IM_MAGICKPP_CONFIG_FIND_REQUIRED )
ENDIF ( IM_MAGICKPP_CONFIG_FOUND )



### poppler ###

FIND_PATH ( POPPLER_CPP_INCLUDE_DIR NAMES poppler/cpp PATHS /usr/include/ /usr/local/include/ )
FIND_LIBRARY ( POPPLER_CPP_LIBRARY NAMES poppler-cpp PATHS /usr/lib /usr/local/lib ) 

IF ( POPPLER_CPP_INCLUDE_DIR AND POPPLER_CPP_LIBRARY )
    SET ( POPPLER_CPP_FOUND TRUE )
ENDIF ( POPPLER_CPP_INCLUDE_DIR AND POPPLER_CPP_LIBRARY )


IF ( POPPLER_CPP_FOUND )
    SET ( DEP_FOUND TRUE )
    IF ( NOT POPPLER_CPP_FIND_QUIETLY )
        MESSAGE ( STATUS "Found Poppler:" )
        MESSAGE ( STATUS "  (Headers)       ${POPPLER_CPP_INCLUDE_DIR}" )
        MESSAGE ( STATUS "  (Library)       ${POPPLER_CPP_LIBRARY}" )
    ENDIF ( NOT POPPLER_CPP_FIND_QUIETLY )
ELSE ( POPPLER_CPP_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( POPPLER_CPP_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find Poppler" )
    ENDIF ( POPPLER_CPP_FIND_REQUIRED )
ENDIF ( POPPLER_CPP_FOUND )



### SQLite ###

FIND_PATH ( SQLITE_INCLUDE_DIR NAMES sqlite3.h PATHS /usr/include/ /usr/local/include/ )
FIND_LIBRARY ( SQLITE_LIBRARY NAMES sqlite3 PATHS /usr/lib /usr/local/lib ) 

IF ( SQLITE_INCLUDE_DIR AND SQLITE_LIBRARY )
    SET ( SQLITE_FOUND TRUE )
ENDIF ( SQLITE_INCLUDE_DIR AND SQLITE_LIBRARY )


IF ( SQLITE_FOUND )
    SET ( DEP_FOUND TRUE )
    IF ( NOT SQLITE_FIND_QUIETLY )
        MESSAGE ( STATUS "Found SQLite3:" )
        MESSAGE ( STATUS "  (Headers)       ${SQLITE_INCLUDE_DIR}" )
        MESSAGE ( STATUS "  (Library)       ${SQLITE_LIBRARY}" )
    ENDIF ( NOT SQLITE_FIND_QUIETLY )
ELSE ( SQLITE_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( SQLITE_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find SQLite3" )
    ENDIF ( SQLITE_FIND_REQUIRED )
ENDIF ( SQLITE_FOUND )



### statgrab ###

FIND_PATH ( STATGRAB_INCLUDE_DIR NAMES statgrab.h PATHS /usr/include/ /usr/local/include/ )
FIND_LIBRARY ( STATGRAB_LIBRARY NAMES statgrab PATHS /usr/lib /usr/local/lib )
FIND_LIBRARY ( DEVSTAT_LIBRARY NAMES devstat PATHS /usr/lib /usr/local/lib )

IF ( STATGRAB_INCLUDE_DIR AND STATGRAB_LIBRARY )
    SET ( STATGRAB_FOUND TRUE )
ENDIF ( STATGRAB_INCLUDE_DIR AND STATGRAB_LIBRARY )

IF ( DEVSTAT_LIBRARY )
    SET ( DEVSTAT_FOUND TRUE )
ENDIF ( DEVSTAT_LIBRARY )


IF ( STATGRAB_FOUND )
    SET ( DEP_FOUND TRUE )
    IF ( NOT STATGRAB_FIND_QUIETLY )
        MESSAGE ( STATUS "Found statgrab:" )
        MESSAGE ( STATUS "  (Headers)       ${STATGRAB_INCLUDE_DIR}" )
        MESSAGE ( STATUS "  (Library)       ${STATGRAB_LIBRARY}" )
    ENDIF ( NOT STATGRAB_FIND_QUIETLY )
ELSE ( STATGRAB_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( STATGRAB_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find statgrab" )
    ENDIF ( STATGRAB_FIND_REQUIRED )
ENDIF ( STATGRAB_FOUND )

IF (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
    IF ( DEVSTAT_FOUND )
            MESSAGE ( STATUS "  (DepLib)        ${DEVSTAT_LIBRARY}" )
    ELSE ( DEVSTAT_FOUND )
        SET ( DEP_FOUND FALSE )
        IF ( DEVSTAT_FIND_REQUIRED )
            MESSAGE ( FATAL_ERROR "Could not find devstat" )
        ENDIF ( DEVSTAT_FIND_REQUIRED )
    ENDIF ( DEVSTAT_FOUND )
ELSE ()
    SET ( DEVSTAT_LIBRARY "" )
ENDIF ()



### VMime ###

FIND_PATH ( VMIME_INCLUDE_DIR NAMES vmime PATHS /usr/include/ /usr/local/include/ )
FIND_LIBRARY ( VMIME_LIBRARY NAMES vmime PATHS /usr/lib /usr/local/lib ) 

IF ( VMIME_INCLUDE_DIR AND VMIME_LIBRARY )
    SET ( VMIME_FOUND TRUE )
    SET ( VMIME_INCLUDE_DIR "${VMIME_INCLUDE_DIR}/${VMIME_HEADER_DIR}" )
ENDIF ( VMIME_INCLUDE_DIR AND VMIME_LIBRARY )


IF ( VMIME_FOUND )
    SET ( DEP_FOUND TRUE )
IF ( NOT VMIME_FIND_QUIETLY )
        MESSAGE ( STATUS "Found VMime:" )
        MESSAGE ( STATUS "  (Headers)       ${VMIME_INCLUDE_DIR}" )
        MESSAGE ( STATUS "  (Library)       ${VMIME_LIBRARY}" )
    ENDIF ( NOT VMIME_FIND_QUIETLY )
ELSE ( VMIME_FOUND )
    SET ( DEP_FOUND FALSE )
IF ( VMIME_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find VMime" )
    ENDIF ( VMIME_FIND_REQUIRED )
ENDIF ( VMIME_FOUND )



### Wt ###

FIND_PATH ( WT_INCLUDE_DIR NAMES Wt PATHS /srv/samsungdforum.ir/lib/wt/include/ NO_DEFAULT_PATH )
FIND_LIBRARY ( WT_LIBRARY NAMES wt PATHS /srv/samsungdforum.ir/lib/wt/lib/ NO_DEFAULT_PATH )
FIND_LIBRARY ( WT_FCGI_LIBRARY NAMES wtfcgi PATHS /srv/samsungdforum.ir/lib/wt/lib/ NO_DEFAULT_PATH )

IF ( WT_INCLUDE_DIR AND WT_LIBRARY )
    SET ( WT_FOUND TRUE )
ENDIF ( WT_INCLUDE_DIR AND WT_LIBRARY )

IF ( WT_FCGI_LIBRARY )
    SET ( WT_FCGI_FOUND TRUE )
ENDIF ( WT_FCGI_LIBRARY )


IF ( WT_FOUND )
    SET ( DEP_FOUND TRUE )
    IF ( NOT WT_FIND_QUIETLY )
        MESSAGE ( STATUS "Found Wt:" )
        MESSAGE ( STATUS "  (Headers)       ${WT_INCLUDE_DIR}" )
        MESSAGE ( STATUS "  (Library)       ${WT_LIBRARY}" )
    ENDIF ( NOT WT_FIND_QUIETLY )
ELSE ( WT_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( WT_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find Wt" )
    ENDIF ( WT_FIND_REQUIRED )
ENDIF ( WT_FOUND )


IF ( WT_FCGI_FOUND )
    SET ( DEP_FOUND TRUE )
    IF ( NOT WT_FCGI_FIND_QUIETLY )
        MESSAGE ( STATUS "  (FastCGI Lib)   ${WT_FCGI_LIBRARY}" )
    ENDIF ( NOT WT_FCGI_FIND_QUIETLY )
ELSE ( WT_FCGI_FOUND )
    SET ( DEP_FOUND FALSE )
    IF ( WT_FCGI_FIND_REQUIRED )
        MESSAGE ( FATAL_ERROR "Could not find WtFastCGI" )
    ENDIF ( WT_FCGI_FIND_REQUIRED )
ENDIF ( WT_FCGI_FOUND )




