CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(visualizator)

################ SOURCES ################

SET(SRCS visualizator.cpp)
AUX_SOURCE_DIRECTORY(visualizator/commands SRCS)
AUX_SOURCE_DIRECTORY(visualizator/controllers SRCS)
AUX_SOURCE_DIRECTORY(visualizator/dialogos SRCS)
AUX_SOURCE_DIRECTORY(visualizator/dialogos/importacion SRCS)
AUX_SOURCE_DIRECTORY(visualizator/dialogos/seleccionardiagnostico SRCS)
AUX_SOURCE_DIRECTORY(visualizator/estudios SRCS)
AUX_SOURCE_DIRECTORY(visualizator/herramientas SRCS)
AUX_SOURCE_DIRECTORY(visualizator/vistas SRCS)
AUX_SOURCE_DIRECTORY(visualizator/widgets SRCS)
AUX_SOURCE_DIRECTORY(visualizator/export SRCS)
AUX_SOURCE_DIRECTORY(visualizator/export/contracts SRCS)
AUX_SOURCE_DIRECTORY(visualizator/export/tools SRCS)
AUX_SOURCE_DIRECTORY(visualizator/tools SRCS)
AUX_SOURCE_DIRECTORY(visualizator/wxvtk SRCS)
AUX_SOURCE_DIRECTORY(visualizator/wxvtk/reconstruction SRCS)
AUX_SOURCE_DIRECTORY(visualizator/wxvtk/reconstruction/commands SRCS)
AUX_SOURCE_DIRECTORY(visualizator/wxvtk/reconstruction/interactors SRCS)
AUX_SOURCE_DIRECTORY(visualizator/wxvtk/reconstruction/pipelines SRCS)
AUX_SOURCE_DIRECTORY(visualizator/wxvtk/reconstruction/volumedataset SRCS)
AUX_SOURCE_DIRECTORY(resources SRCS)

################ DEFINITIONS ################

ADD_EXTENSION_DEFINITIONS()
ADD_DEFINITIONS(-DMONOLITIC)

################ INCLUDE DIRECTORIES ################

SET(${PROJECT_NAME}_INCLUDE_DIR
	${CMAKE_CURRENT_SOURCE_DIR}
	${CMAKE_CURRENT_SOURCE_DIR}/comandos
	${CMAKE_CURRENT_SOURCE_DIR}/controllers
	${CMAKE_CURRENT_SOURCE_DIR}/dialogos
	${CMAKE_CURRENT_SOURCE_DIR}/estudios
	${CMAKE_CURRENT_SOURCE_DIR}/eventos
	${CMAKE_CURRENT_SOURCE_DIR}/exportacion
	${CMAKE_CURRENT_SOURCE_DIR}/herramientas
	${CMAKE_CURRENT_SOURCE_DIR}/vistas
	${CMAKE_CURRENT_SOURCE_DIR}/widgets
	${CMAKE_CURRENT_SOURCE_DIR}/wxvtk
	CACHE INTERNAL ""
)

INCLUDE_DIRECTORIES(${CADxCore_INCLUDE_DIR})

INCLUDE_DIRECTORIES(${${PROJECT_NAME}_INCLUDE_DIR})

IF(USE_CUSTOM_WX)
	ADD_DEFINITIONS(${wxWidgets_defines})
	INCLUDE_DIRECTORIES(${wxWidgets_INCLUDE_DIR})
	LINK_DIRECTORIES(${wxWidgets_DIR})
ELSE()
	INCLUDE(${wxWidgets_USE_FILE})
	#MESSAGE("WXLIBS = ${wxWidgets_LIBRARIES} ")
ENDIF()


IF (USE_CUSTOM_VTK)
	ADD_DEFINITIONS(${VTK_defines})
	INCLUDE_DIRECTORIES(${VTK_INCLUDE_DIR})
	LINK_DIRECTORIES(${VTK_DIR})
ELSE()
	INCLUDE(${VTK_USE_FILE})
ENDIF()



IF(USE_CUSTOM_ITK)
	ADD_DEFINITIONS(${ITK_defines})
	INCLUDE_DIRECTORIES(${ITK_INCLUDE_DIR})
	LINK_DIRECTORIES(${ITK_DIR})
ELSE()
	INCLUDE(${ITK_USE_FILE})
	#MESSAGE("ITKLIBS = ${ITK_LIBRARIES}")
ENDIF()

ADD_DEFINITIONS(${Cairo_defines})
INCLUDE_DIRECTORIES(${Cairo_INCLUDE_DIR})
LINK_DIRECTORIES(${Cairo_LIB})

ADD_DEFINITIONS(${Pixman_defines})
INCLUDE_DIRECTORIES(${Pixman_INCLUDE_DIR})
LINK_DIRECTORIES(${Pixman_LIB})

################ TARGET ################

IF(LINUX AND NOT CUSTOM_PACKAGE)
	SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
	SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 
	SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/ginkgocadx")
	SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
	LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib/ginkgocadx" isSystemDir)
	IF("${isSystemDir}" STREQUAL "-1")
		SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/ginkgocadx")
	ENDIF()
ENDIF()

ADD_LIBRARY(${PROJECT_NAME} STATIC ${SRCS} )
#ADD_EXECUTABLE(${PROJECT_NAME} WIN32 MACOSX_BUNDLE ${SRCS})

IF(LINUX)
	SET(LIBNAME "lib${PROJECT_NAME}.so.${GINKGO_VERSION_STR}")
ENDIF()
IF(MACOS)
	SET(LIBNAME "lib${PROJECT_NAME}.${GINKGO_VERSION_STR}.dylib")
ENDIF()

#ADD_CUSTOM_COMMAND( TARGET ${PROJECT_NAME} POST_BUILD COMMAND /bin/sh ARGS "${CMAKE_CURRENT_SOURCE_DIR}/../ginkgocadx/build_descriptor.sh" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBNAME}" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.inf" "${GINKGO_VERSION}" "${GINKGO_SUB_VERSION}")

SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
	VERSION "${GINKGO_VERSION_STR}" SOVERSION "${GINKGO_VERSION_STR}"
	LINK_INTERFACE_LIBRARIES ""
	INSTALL_RPATH_USE_LINK_PATH FALSE )

#INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib/ginkgocadx/Plugins)
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.inf DESTINATION lib/ginkgocadx/Plugins)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/3d_bar DESTINATION share/ginkgocadx/resources/visualizator)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/logos DESTINATION share/ginkgocadx/resources/visualizator)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/synchronization_bar DESTINATION share/ginkgocadx/resources/visualizator)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/tool_icons DESTINATION share/ginkgocadx/resources/visualizator)

INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/zh_CN/visualizator.mo DESTINATION share/ginkgocadx/lang/zh_CN)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/de/visualizator.mo DESTINATION share/ginkgocadx/lang/es)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/de/visualizator.mo DESTINATION share/ginkgocadx/lang/de)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/el/visualizator.mo DESTINATION share/ginkgocadx/lang/el)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/es/visualizator.mo DESTINATION share/ginkgocadx/lang/es)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/fr/visualizator.mo DESTINATION share/ginkgocadx/lang/fr)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/ja/visualizator.mo DESTINATION share/ginkgocadx/lang/ja)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/pl/visualizator.mo DESTINATION share/ginkgocadx/lang/pl)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/pt/visualizator.mo DESTINATION share/ginkgocadx/lang/pt)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/tr/visualizator.mo DESTINATION share/ginkgocadx/lang/tr)
################ LIBS ################

TARGET_LINK_LIBRARIES(${PROJECT_NAME} CADxCore)


TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${VTK_LIBRARIES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${ITK_LIBRARIES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${Cairo_LIBRARIES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${Pixman_LIBRARIES})

IF (LINUX)
	TARGET_LINK_LIBRARIES(${PROJECT_NAME} GL xml2)
ENDIF()

IF(MACOS)
	FIND_LIBRARY( CARBON_LIB Carbon )
	FIND_LIBRARY( OPENGL_LIB OpenGL )
	
	MARK_AS_ADVANCED( CARBON_LIB OPENGL_LIB )

	SET(LIBS ${CARBON_LIB} ${OPENGL_LIB} )
	LIST( APPEND LIBS xml2 z )

	TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIBS})

	SET_TARGET_PROPERTIES( PROPERTIES LINK_FLAGS "-Wl ${XCODE_LINK_FLAGS}" )
	
ENDIF()

MESSAGE(STATUS "OS=[${OS}], Arch=[${ARCH}], Target=[${CMAKE_BUILD_TYPE}], Project=[${PROJECT_NAME}]")

