cmake_minimum_required(VERSION 2.6)

#-----------------------------------------------------------------------------
# Required libraries

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


# Qt4
FIND_PACKAGE(Qt4 REQUIRED)
IF(QT4_FOUND)
	INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR})
	INCLUDE(${QT_USE_FILE})	
ELSE()
	MESSAGE(FATAL_ERROR "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(FATAL_ERROR "RITK not found, but needed.")
ENDIF(RITK_FOUND)

# CUDA
FIND_PACKAGE(CUDA)
IF(CUDA_FOUND)

ELSE()
	MESSAGE(FATAL_ERROR "CUDA not found, but needed.")
ENDIF(CUDA_FOUND)


#-----------------------------------------------------------------------------
# Set headers (HDRS), sources (SRCS), childs of QObject (MOC_HDRS), and Qt ui-files (UIS)

SET(	HDRS
		CUDABilateralImageFilter.h
		RangeCUDABilateralImageFilter.h
		CUDABilateralFilterWidget.h
		CUDABilateralImageFilterPlugin.h
		CUDABilateralImageFilterPluginFactory.h	
)

SET(	SRCS
		CUDABilateralImageFilter.txx
		RangeCUDABilateralImageFilter.txx
		CUDABilateralFilterWidget.cxx
		CUDABilateralImageFilterPlugin.cxx
		CUDABilateralImageFilterPluginFactory.cxx
)

SET(	CUDA_HDRS
		BilateralFilterKernel.h
)

SET(	CUDA_SRCS
		BilateralFilter.cu
)

SET(	MOC_HDRS 	
		CUDABilateralFilterWidget.h
		CUDABilateralImageFilterPlugin.h
		CUDABilateralImageFilterPluginFactory.h
)

SET(	UIS
		CUDABilateralFilterWidget.ui
)

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


#-----------------------------------------------------------------------------
# Set the name for the library (LIBRARY_NAME) and the include directories for this plugin (INCLUDE_DIRS)

SET(LIBRARY_NAME CUDABilateralFilterPlugin)

SET(INCLUDE_DIRS	
	${CMAKE_CURRENT_SOURCE_DIR}
	${CMAKE_CURRENT_BINARY_DIR}
)

#-----------------------------------------------------------------------------
# Set include directories, definitions and libs for this plugin
# OPTIONS -maxrregcount=8
INCLUDE_DIRECTORIES(
	${INCLUDE_DIRS} 
	${RITK_INCLUDE_DIRS}

)

SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

CUDA_ADD_LIBRARY(
	${LIBRARY_NAME} SHARED 
	${SRCS} 
	${HDRS} 
	${CUDA_HDRS} 
	${CUDA_SRCS}
	${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}
	${CUDA_CUDA_LIBRARY} 
	${CUDA_CUDART_LIBRARY} 
	
)

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

# Qt Plugin
ADD_DEFINITIONS(-DQT_PLUGIN)
ADD_DEFINITIONS(-DQT_SHARED)


#-----------------------------------------------------------------------------
# Installation
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 
)

