IF(NOT MATOG_FOUND)
	SET(MATOG_FOUND "NO")

	IF(NOT MATOG_DIR)
		SET(MATOG_DIR $ENV{MATOG_DIR} CACHE PATH "MATOG root dir")
	ENDIF()

	IF(NOT MATOG_DIR)
		MESSAGE("Please set the environment variable MATOG_DIR to the path of MATOG.")
	ENDIF()

	# search for headers
	FIND_PATH(MATOG_INCLUDE_DIR "matog/matog.h" PATHS ${MATOG_DIR} PATH_SUFFIXES "include")

	# search for executables
	FIND_PROGRAM(MATOG_BINARY "matog-code" PATHS ${MATOG_DIR} PATH_SUFFIXES "bin")

	# search for libraries
	FIND_LIBRARY(MATOG_INTERNAL_LIBRARY			"matog-internal"		PATHS ${MATOG_DIR} PATH_SUFFIXES "lib")
	FIND_LIBRARY(MATOG_RUNTIME_LIBRARY			"matog-runtime"			PATHS ${MATOG_DIR} PATH_SUFFIXES "lib")
	FIND_LIBRARY(MATOG_LOG_LIBRARY				"matog-log"				PATHS ${MATOG_DIR} PATH_SUFFIXES "lib")
	FIND_LIBRARY(MATOG_UTIL_LIBRARY       		"matog-util"			PATHS ${MATOG_DIR} PATH_SUFFIXES "lib")
	FIND_LIBRARY(MATOG_SQLITE_LIBRARY			"matog-sqlite3"			PATHS ${MATOG_DIR} PATH_SUFFIXES "lib")
	FIND_LIBRARY(MATOG_CTEMPLATE_LIBRARY		"matog-ctemplate"		PATHS ${MATOG_DIR} PATH_SUFFIXES "lib")
	FIND_LIBRARY(MATOG_JSONCPP_LIBRARY			"matog-jsoncpp"			PATHS ${MATOG_DIR} PATH_SUFFIXES "lib")

	IF(
		MATOG_INCLUDE_DIR AND 
		MATOG_BINARY AND 
		MATOG_DIR AND
		MATOG_INTERNAL_LIBRARY AND 
		MATOG_RUNTIME_LIBRARY AND 
		MATOG_LOG_LIBRARY AND 
		MATOG_UTIL_LIBRARY AND 
		MATOG_SQLITE_LIBRARY AND 
		MATOG_CTEMPLATE_LIBRARY AND 
		MATOG_JSONCPP_LIBRARY
	)
		SET(MATOG_FOUND "YES")
	
		SET(MATOG_LIBRARIES 
			${MATOG_INTERNAL_LIBRARY} 
			${MATOG_RUNTIME_LIBRARY} 
			${MATOG_LOG_LIBRARY} 
			${MATOG_UTIL_LIBRARY} 
			${MATOG_SQLITE_LIBRARY} 
			${MATOG_CTEMPLATE_LIBRARY} 
			${MATOG_JSONCPP_LIBRARY}
			${CUDA_cupti_LIBRARY}
		)
	
		MARK_AS_ADVANCED(
			${MATOG_LIBRARIES} 
			${MATOG_INCLUDE_DIR} 
			${MATOG_BINARY} 
			${MATOG_INTERNAL_LIBRARY} 
			${MATOG_RUNTIME_LIBRARY} 
			${MATOG_LOG_LIBRARY} 
			${MATOG_UTIL_LIBRARY} 
			${MATOG_SQLITE_LIBRARY} 
			${MATOG_CTEMPLATE_LIBRARY} 
			${MATOG_JSONCPP_LIBRARY}
		)	
	
		MESSAGE(STATUS "Found MATOG")
	ELSE()
		MESSAGE(STATUS "MATOG not found")
		MESSAGE(STATUS "MATOG_DIR                     = ${MATOG_DIR}")
		MESSAGE(STATUS "MATOG_INCLUDE_DIR             = ${MATOG_INCLUDE_DIR}")
		MESSAGE(STATUS "MATOG_BINARY                  = ${MATOG_BINARY}")
		MESSAGE(STATUS "MATOG_INTERNAL_LIBRARY        = ${MATOG_INTERNAL_LIBRARY}")
		MESSAGE(STATUS "MATOG_RUNTIME_LIBRARY         = ${MATOG_RUNTIME_LIBRARY}")
		MESSAGE(STATUS "MATOG_LOG_LIBRARY             = ${MATOG_LOG_LIBRARY}")
		MESSAGE(STATUS "MATOG_UTIL_LIBRARY            = ${MATOG_UTIL_LIBRARY}")
		MESSAGE(STATUS "MATOG_SQLITE_LIBRARY          = ${MATOG_SQLITE_LIBRARY}")
		MESSAGE(STATUS "MATOG_CTEMPLATE_LIBRARY       = ${MATOG_CTEMPLATE_LIBRARY}")
		MESSAGE(STATUS "MATOG_JSONCPP_LIBRARY         = ${MATOG_JSONCPP_LIBRARY}")
	ENDIF()

	IF(MATOG_FIND_REQUIRED AND NOT MATOG_FOUND)
		MESSAGE(FATAL_ERROR "Could NOT find MATOG.")
	ENDIF()

	INCLUDE_DIRECTORIES(${MATOG_INCLUDE_DIR})
ENDIF()