cmake_minimum_required(VERSION 2.6)

# ITK
FIND_PACKAGE(ITK REQUIRED)
IF(ITK_FOUND)
	INCLUDE_DIRECTORIES(${ITK_INCLUDE_DIRS})
	INCLUDE(${ITK_USE_FILE})
ELSE()
	MESSAGE("ITK not found, but needed.")
ENDIF(ITK_FOUND)

# VTK
FIND_PACKAGE(VTK REQUIRED)
IF(VTK_FOUND)
	INCLUDE(${VTK_USE_FILE})
	INCLUDE_DIRECTORIES(${VTK_INCLUDE_DIRS})
ELSE()
	MESSAGE("VTK not found, but needed.")
ENDIF(VTK_FOUND)

# Qt4
FIND_PACKAGE(Qt4 REQUIRED)
IF(QT4_FOUND)
	INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR})
	INCLUDE(${QT_USE_FILE})	
ELSE()
	MESSAGE("QT4 not found, but needed.")
ENDIF(QT4_FOUND)

# RITK
FIND_PACKAGE(RITK REQUIRED)
IF(RITK_FOUND)
	INCLUDE_DIRECTORIES(${RITK_INCLUDE_DIR})
	INCLUDE(${RITK_USE_FILE})	
ELSE()
	MESSAGE("RITK not found, but needed.")
ENDIF(RITK_FOUND)


# OpenNI 
SET(OPEN_NI_INCLUDE_DIR $ENV{OPEN_NI_INCLUDE})
IF(DEFINED OPEN_NI_INCLUDE_DIR)
	INCLUDE_DIRECTORIES(${OPEN_NI_INCLUDE_DIR})
ELSE()
	MESSAGE("OpenNI not found, but needed.")
ENDIF()
FIND_LIBRARY(OPEN_NI_LIBRARY NAMES openNI PATHS $ENV{OPEN_NI_LIB})
LINK_DIRECTORIES($ENV{OPEN_NI_LIB})

# NITE 
SET(NITE_INCLUDE_DIR $ENV{NITE_INCLUDE})
IF(DEFINED NITE_INCLUDE_DIR)
	INCLUDE_DIRECTORIES(${NITE_INCLUDE_DIR})
ELSE()
	MESSAGE("NITE not found, but needed.")
ENDIF()
FIND_LIBRARY(NITE_LIBRARY NAMES XnVCNITE_1_3_1 PATHS $ENV{NITE_LIB})
LINK_DIRECTORIES($ENV{NITE_LIB})


#-----------------------------------------------------------------------------

SET(HDRS
	KinectNITESourcePluginFactory.h
	KinectNITESourcePlugin.h
	KinectNITERImageSource.h
	KinectNITESourcePluginWidget.h
)

SET(SRCS
	KinectNITESourcePluginFactory.cxx
	KinectNITESourcePlugin.cxx
	KinectNITERImageSource.txx
	KinectNITESourcePluginWidget.cxx
	KinectNITEInstantiations.cxx
)


#-----------------------------------------------------------------------------

# Qt
# all childs of qobject have to be put here
SET(MOC_HDRS 	
	KinectNITESourcePlugin.h
	KinectNITESourcePluginWidget.h
	KinectNITESourcePluginFactory.h
)

SET(UIS
	KinectNITESourcePluginWidget.ui
)

QT4_WRAP_UI(UI_HDRS ${UIS})	
QT4_WRAP_CPP(MOC_SRCS ${MOC_HDRS})

#-----------------------------------------------------------------------------

# Set the name for the library
SET(LIBRARY_NAME KinectNITESourcePlugin)
SET(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Declare as plugin library
SET(PLUGIN_LIBRARIES
	${PLUGIN_LIBRARIES}
	${LIBRARY_NAME}
	CACHE INTERNAL ""
)

# Set include directories
SET(INCLUDE_DIRS	
	${CMAKE_CURRENT_SOURCE_DIR}
	${CMAKE_CURRENT_BINARY_DIR}
	${KINECTIMAGEPLUGIN_INCLUDE_DIRS}
)

# Declare as plugin include directories
SET(PLUGIN_INCLUDE_DIRS
	${PLUGIN_INCLUDE_DIRS}
	${INCLUDE_DIRS}
	CACHE INTERNAL ""
)

# QT plugin
ADD_DEFINITIONS(-DQT_PLUGIN)
ADD_DEFINITIONS(-DQT_SHARED)

INCLUDE_DIRECTORIES(${INCLUDE_DIRS} ${RITK_INCLUDE_DIRS} ${KINECTIMAGEPLUGIN_INCLUDE_DIRS})
ADD_LIBRARY(${LIBRARY_NAME} SHARED 
	${SRCS} 
	${HDRS} 
	${MOC_SRCS} 
	${UI_HDRS}
) 


TARGET_LINK_LIBRARIES(${LIBRARY_NAME} 
	debug ${RITK_COMMON_LIBRARY_DEBUG}
	debug ${RITK_CORE_LIBRARY_DEBUG}
	debug ${RITK_CUDA_LIBRARY_DEBUG}
	optimized ${RITK_COMMON_LIBRARY}
	optimized ${RITK_CORE_LIBRARY}
	optimized ${RITK_CUDA_LIBRARY}
	${ITK_LIBRARIES} 
	${QT_LIBRARIES} 
	${OPEN_NI_LIBRARY}
	${NITE_LIBRARY}
	${KINECTIMAGEPLUGIN_LIBRARY}
) 

SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES 
	DEBUG_POSTFIX "d")

INSTALL(TARGETS ${LIBRARY_NAME} CONFIGURATIONS RELEASE
	RUNTIME DESTINATION ${RITK_BINARY_DIR}/release/plugins
	LIBRARY DESTINATION ${RITK_BINARY_DIR}/release/plugins
)

INSTALL(TARGETS ${LIBRARY_NAME} CONFIGURATIONS DEBUG
	RUNTIME DESTINATION ${RITK_BINARY_DIR}/debug/plugins
	LIBRARY DESTINATION ${RITK_BINARY_DIR}/debug/plugins 
)
