CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(CADxCore)

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

AUX_SOURCE_DIRECTORY(api SRCS)
AUX_SOURCE_DIRECTORY(api/controllers SRCS)
AUX_SOURCE_DIRECTORY(api/controllers/proxies SRCS)
AUX_SOURCE_DIRECTORY(api/helpers SRCS)
AUX_SOURCE_DIRECTORY(api/math SRCS)
AUX_SOURCE_DIRECTORY(api/observers SRCS)
AUX_SOURCE_DIRECTORY(api/dicom SRCS)
AUX_SOURCE_DIRECTORY(api/threads SRCS)
AUX_SOURCE_DIRECTORY(api/internationalization SRCS)
AUX_SOURCE_DIRECTORY(api/toolsystem SRCS)
AUX_SOURCE_DIRECTORY(api/utils SRCS)

AUX_SOURCE_DIRECTORY(export SRCS)
AUX_SOURCE_DIRECTORY(export/tools SRCS)
AUX_SOURCE_DIRECTORY(export/observers SRCS)
AUX_SOURCE_DIRECTORY(export/contracts SRCS)

AUX_SOURCE_DIRECTORY(main SRCS)
AUX_SOURCE_DIRECTORY(main/controllers SRCS)
AUX_SOURCE_DIRECTORY(main/filtering SRCS)
AUX_SOURCE_DIRECTORY(main/utils SRCS)

AUX_SOURCE_DIRECTORY(main/gui SRCS)
AUX_SOURCE_DIRECTORY(main/gui/anonymize SRCS)
AUX_SOURCE_DIRECTORY(main/gui/acquisition SRCS)
AUX_SOURCE_DIRECTORY(main/gui/callibration SRCS)
AUX_SOURCE_DIRECTORY(main/gui/configuration SRCS)
AUX_SOURCE_DIRECTORY(main/gui/countdownmessage SRCS)
AUX_SOURCE_DIRECTORY(main/gui/dicomeditor SRCS)
AUX_SOURCE_DIRECTORY(main/gui/dicomdirexport SRCS)
AUX_SOURCE_DIRECTORY(main/gui/dicomdirmigration SRCS)
AUX_SOURCE_DIRECTORY(main/gui/export SRCS)
AUX_SOURCE_DIRECTORY(main/gui/ginkgocloud SRCS)
AUX_SOURCE_DIRECTORY(main/gui/history3 SRCS)
AUX_SOURCE_DIRECTORY(main/gui/hl7controlwindow SRCS)
AUX_SOURCE_DIRECTORY(main/gui/import SRCS)
AUX_SOURCE_DIRECTORY(main/gui/license SRCS)
AUX_SOURCE_DIRECTORY(main/gui/logcontrolwindow SRCS)
AUX_SOURCE_DIRECTORY(main/gui/login SRCS)
AUX_SOURCE_DIRECTORY(main/gui/mainwindow SRCS)
AUX_SOURCE_DIRECTORY(main/gui/open SRCS)
AUX_SOURCE_DIRECTORY(main/gui/pacsupload SRCS)
AUX_SOURCE_DIRECTORY(main/gui/paneltags SRCS)
AUX_SOURCE_DIRECTORY(main/gui/previewpanel SRCS)
AUX_SOURCE_DIRECTORY(main/gui/print SRCS)
AUX_SOURCE_DIRECTORY(main/gui/dicomprint SRCS)
AUX_SOURCE_DIRECTORY(main/gui/progress SRCS)
AUX_SOURCE_DIRECTORY(main/gui/selectpacsserver SRCS)
AUX_SOURCE_DIRECTORY(main/gui/startup SRCS)
AUX_SOURCE_DIRECTORY(main/gui/tabtoolbar SRCS)
AUX_SOURCE_DIRECTORY(main/gui/taskcontrol SRCS)
AUX_SOURCE_DIRECTORY(main/gui/toolsystem SRCS)

AUX_SOURCE_DIRECTORY(main/managers SRCS)
AUX_SOURCE_DIRECTORY(main/tools SRCS)
AUX_SOURCE_DIRECTORY(main/toolsystem SRCS)
AUX_SOURCE_DIRECTORY(main/controllers/dcmtk SRCS)
AUX_SOURCE_DIRECTORY(main/controllers/dcmtk/libi2d SRCS)
AUX_SOURCE_DIRECTORY(main/controllers/dcmtk/ofstd SRCS)
AUX_SOURCE_DIRECTORY(main/controllers/dcmtk/tls SRCS)
#AUX_SOURCE_DIRECTORY(main/controllers/dcmtk/tls/win-only SRCS)
AUX_SOURCE_DIRECTORY(main/controllers/log4cplus SRCS)
AUX_SOURCE_DIRECTORY(main/controllers/streaming SRCS)

AUX_SOURCE_DIRECTORY(commands SRCS)

AUX_SOURCE_DIRECTORY(net SRCS)

AUX_SOURCE_DIRECTORY(resources SRCS)

IF(NOT USE_SYSTEM_SQLITE)
AUX_SOURCE_DIRECTORY(sqlite SRCS)
ENDIF()


AUX_SOURCE_DIRECTORY(endpoint SRCS)

AUX_SOURCE_DIRECTORY(vtk SRCS)
AUX_SOURCE_DIRECTORY(vtk/command SRCS)
AUX_SOURCE_DIRECTORY(vtk/interactor SRCS)
AUX_SOURCE_DIRECTORY(vtk/widgets SRCS)

AUX_SOURCE_DIRECTORY(widgets SRCS)
AUX_SOURCE_DIRECTORY(widgets/gui SRCS)
AUX_SOURCE_DIRECTORY(widgets/observers SRCS)

AUX_SOURCE_DIRECTORY(wx SRCS)
AUX_SOURCE_DIRECTORY(wx/ginkgostyle SRCS)
AUX_SOURCE_DIRECTORY(wx/gnkinforme SRCS)
AUX_SOURCE_DIRECTORY(wx/iconoimagenctrl SRCS)
AUX_SOURCE_DIRECTORY(wx/maskedtextctrl SRCS)
AUX_SOURCE_DIRECTORY(wx/propgrid SRCS)
AUX_SOURCE_DIRECTORY(wx/propiedades SRCS)
AUX_SOURCE_DIRECTORY(wx/thumbnailctrl SRCS)
AUX_SOURCE_DIRECTORY(wx/timectrl SRCS)
AUX_SOURCE_DIRECTORY(wx/treelistctrl SRCS)
AUX_SOURCE_DIRECTORY(wx/VTK SRCS)
AUX_SOURCE_DIRECTORY(wx/wizardginkgo SRCS)
AUX_SOURCE_DIRECTORY(wx/wxsqlite3 SRCS)
AUX_SOURCE_DIRECTORY(wx/wxhttpengine SRCS)

AUX_SOURCE_DIRECTORY(VTKInria3D SRCS)
AUX_SOURCE_DIRECTORY(VTKInria3D/vtkVISUManagement SRCS)
AUX_SOURCE_DIRECTORY(VTKInria3D/wxVTK SRCS)

AUX_SOURCE_DIRECTORY(resources SRCS)

IF (LINUX OR MACOS)
	AUX_SOURCE_DIRECTORY(xmlrpc SRCS)
ENDIF()

IF (LINUX OR MACOS)
	LIST(REMOVE_ITEM SRCS endpoint/interfaces.cpp)
	LIST(REMOVE_ITEM SRCS endpoint/sockatmark.cpp)
ELSEIF(WINDOWS)
	SET(SRCS stdafx.cpp ${SRCS})
ENDIF()

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

ADD_CORE_DEFINITIONS()

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

SET(${PROJECT_NAME}_INCLUDE_DIR
	${CMAKE_CURRENT_SOURCE_DIR}
	${CMAKE_CURRENT_SOURCE_DIR}/vtk
	${CMAKE_CURRENT_SOURCE_DIR}/itk
	${CMAKE_CURRENT_SOURCE_DIR}/wx
	${CMAKE_CURRENT_SOURCE_DIR}/wx/VTK
	${CMAKE_CURRENT_SOURCE_DIR}/VTKInria3D
	${CMAKE_CURRENT_SOURCE_DIR}/VTKInria3D/wxVTK
	CACHE INTERNAL ""
)

INCLUDE_DIRECTORIES(${PROJECT_NAME} ${${PROJECT_NAME}_INCLUDE_DIR} )

################ LIBS ################
FIND_PATH(libjsoncpp_INCLUDE_DIR json/json.h
/usr/include/jsoncpp
)
INCLUDE_DIRECTORIES(${libjsoncpp_INCLUDE_DIR})
set(libjsoncpp_LIBRARIES jsoncpp)
MESSAGE(STATUS "libjsoncpp_LIBRARIES=${libjsoncpp_LIBRARIES} libjsoncpp_INCLUDE_DIR=${libjsoncpp_INCLUDE_DIR}")

ADD_DEFINITIONS(${libcurl_defines})
INCLUDE_DIRECTORIES(${libcurl_INCLUDE_DIR})
LINK_DIRECTORIES(${libcurl_DIR})
#MESSAGE("LIBCURLLibx = ${libcurl_LIBRARIES} LIBCURL_include = ${libcurl_INCLUDE_DIR}  LIBCURL_LINK_DIR= ${libcurl_DIR} LIBCURL_DEFINES=${libcurl_defines}")

IF(USE_CUSTOM_WX)
  ADD_DEFINITIONS(${wxWidgets_CXX_FLAGS})
  INCLUDE_DIRECTORIES(${wxWidgets_INCLUDE_DIR})
  LINK_DIRECTORIES(${wxWidgets_DIR})
ELSE()
  FIND_PACKAGE(wxWidgets 3.0.1 REQUIRED)
  foreach(d ${wxWidgets_DEFINITIONS})
    ADD_DEFINITIONS("-D${d}")
  endforeach()
  INCLUDE_DIRECTORIES(${wxWidgets_INCLUDE_DIRS})
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()

IF(USE_CUSTOM_DCMTK)
	ADD_DEFINITIONS(${DCMTK_defines})
	INCLUDE_DIRECTORIES(${DCMTK_INCLUDE_DIR})
	LINK_DIRECTORIES(${DCMTK_DIR})
ELSE()
	ADD_DEFINITIONS(-DHAVE_CONFIG_H)
	INCLUDE_DIRECTORIES(${DCMTK_INCLUDE_DIRS})
	#MESSAGE("DCMTKLIBS = ${DCMTK_LIBRARIES}")
	#MESSAGE("DCMTKINC = ${DCMTK_INCLUDE_DIRS}")
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})

IF (MACOS)
	ADD_DEFINITIONS(${XmlRpc++_defines})
	INCLUDE_DIRECTORIES(${XmlRpc++_INCLUDE_DIR})
	LINK_DIRECTORIES(${XmlRpc++_DIR})
ENDIF()

IF (LINUX)
	IF (GTK2_FOUND)
	  INCLUDE_DIRECTORIES(${GTK2_INCLUDE_DIRS})
	ELSE ()
	  MESSAGE("-----------------GTK2 NOT FOUND--------------------")
	  INCLUDE_DIRECTORIES(/usr/include/gtk-2.0
	      /usr/include/atk-1.0
	      /usr/include/pango-1.0
	      /usr/include/gio-unix-2.0/
	      /usr/include/glib-2.0
	      /usr/lib/i386-linux-gnu/glib-2.0/include
	      /usr/include/freetype2
	      /usr/include/libpng12
	      /usr/lib/gtk-2.0/include
	      /usr/include/cairo
	      /usr/include/gdk-pixbuf-2.0
	      /usr/include/pixman-1
	  )  
	ENDIF ()
ENDIF()


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

ADD_LIBRARY(${PROJECT_NAME} STATIC ${SRCS} )
#ADD_EXECUTABLE(${PROJECT_NAME} WIN32 MACOSX_BUNDLE ${SRCS})
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)

INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/acquisition DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/big_icons DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/cursors DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/history DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/logos DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/marking_bar DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/menu_tabs DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/tool_icons DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/wizards DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/angle_bar DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/cine_bar DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/grid_bar DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/layout_bar DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/magnifier_bar DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/menu_icons DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/progress_bar DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/files/windowlevel_bar DESTINATION share/ginkgocadx/resources/cadxcore)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/zh_CN/cadxcore.mo DESTINATION share/ginkgocadx/lang/zh_CN)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/zh_CN/wxstd.mo DESTINATION share/ginkgocadx/lang/zh_CN)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/de/cadxcore.mo DESTINATION share/ginkgocadx/lang/de)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/de/wxstd.mo DESTINATION share/ginkgocadx/lang/de)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/el/wxstd.mo DESTINATION share/ginkgocadx/lang/el)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/el/cadxcore.mo DESTINATION share/ginkgocadx/lang/el)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/es/wxstd.mo DESTINATION share/ginkgocadx/lang/es)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/es/cadxcore.mo DESTINATION share/ginkgocadx/lang/es)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/fr/wxstd.mo DESTINATION share/ginkgocadx/lang/fr)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/fr/cadxcore.mo DESTINATION share/ginkgocadx/lang/fr)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/ja/wxstd.mo DESTINATION share/ginkgocadx/lang/ja)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/ja/cadxcore.mo DESTINATION share/ginkgocadx/lang/ja)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/pl/wxstd.mo DESTINATION share/ginkgocadx/lang/pl)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/pl/cadxcore.mo DESTINATION share/ginkgocadx/lang/pl)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/pt/wxstd.mo DESTINATION share/ginkgocadx/lang/pt)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/pt/cadxcore.mo DESTINATION share/ginkgocadx/lang/pt)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/sr/cadxcore.mo DESTINATION share/ginkgocadx/lang/sr)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/tr/wxstd.mo DESTINATION share/ginkgocadx/lang/tr)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lang/tr/cadxcore.mo DESTINATION share/ginkgocadx/lang/tr)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/conformance.xml DESTINATION share/ginkgocadx)
################ LIBS ################
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libjsoncpp_LIBRARIES})

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libcurl_LIBRARIES})

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${wxWidgets_LIBRARIES})

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${VTK_LIBRARIES})

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${ITK_LIBRARIES})

IF(USE_CUSTOM_DCMTK)
	TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${DCMTK_LIBRARIES})
ELSE()
	TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${DCMTK_LIBRARIES} wrap)
ENDIF()

IF(USE_SYSTEM_SQLITE)
	TARGET_LINK_LIBRARIES(${PROJECT_NAME} sqlite3)
ENDIF()

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${Cairo_LIBRARIES})

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${Pixman_LIBRARIES})

IF (MACOS)
	TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${XmlRpc++_LIBRARIES})
ENDIF()

IF(LINUX)
	TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${GTK2_LIBRARIES})
	TARGET_LINK_LIBRARIES(${PROJECT_NAME} ssl GL crypto 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 ssl crypto 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}]")

