# CMake script for xtpcpp
# Author: Olivier Langella
# Created: 03/03/2015


SET(xtpcpp_RCCS xtpcpp.qrc)
# Appeler automatique le moc quand nécessaire
#SET(CMAKE_AUTOMOC ON)
# Les fichiers générés par le moc sont générés dans le dossier bin, dire à CMake de toujours 	
# inclure les entêtes de ce dossier
#SET(CMAKE_INCLUDE_CURRENT_DIR ON)

#FIND_PACKAGE(Boost REQUIRED)
#INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS})

FIND_PACKAGE( Qt5 COMPONENTS Core Gui Svg Xml PrintSupport Network REQUIRED )
QT5_ADD_RESOURCES(xtpcpp_RCC_SRCS ${xtpcpp_RCCS})

FIND_PACKAGE( ZLIB REQUIRED )

if (QCustomPlot_FOUND)
    MESSAGE("QCustomPlot_INCLUDES found ${QCustomPlot_INCLUDES}")
else (QCustomPlot_FOUND)
    FIND_PACKAGE( QCustomPlot REQUIRED )
endif (QCustomPlot_FOUND)
    
if (ODSSTREAM_QT5_FOUND)
else (ODSSTREAM_QT5_FOUND)
    FIND_PACKAGE( Odsstream REQUIRED ) #ODSSTREAM_INCLUDE_DIR AND ODSSTREAM_LIBRARY
endif (ODSSTREAM_QT5_FOUND)

#SET (ODSSTREAM_DIR  "/home/olivier/eclipse/git/libodsstream")
#SET (ODSSTREAM_INCLUDE_DIR "${ODSSTREAM_DIR}/src")
#SET (ODSSTREAM_QT5_LIBRARY "${ODSSTREAM_DIR}/build/src/libodsstream-qt5.so")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Xml_EXECUTABLE_COMPILE_FLAGS} ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS} ${Qt5Svg_EXECUTABLE_COMPILE_FLAGS}")



#sudo apt-get install libpappsomspp-dev
if (PAPPSOMSPP_QT5_FOUND)
else (PAPPSOMSPP_QT5_FOUND)
    MESSAGE("looking for PAPPSOms++ library")
	FIND_PACKAGE( Pappsomspp REQUIRED )
endif (PAPPSOMSPP_QT5_FOUND)

IF (PAPPSOMSPP_QT5_FOUND)
ELSE (PAPPSOMSPP_QT5_FOUND)
  MESSAGE("PAPPSOms++ library not found")
  MESSAGE("did you apt-get install libpappsomspp-dev ?")
ENDIF (PAPPSOMSPP_QT5_FOUND)

IF (PAPPSOMSPP_WIDGET_QT5_FOUND)
ELSE (PAPPSOMSPP_WIDGET_QT5_FOUND)
  MESSAGE("PAPPSOms++ widget library not found")
  MESSAGE("did you apt-get install libpappsomspp-widget-dev ?")
ENDIF (PAPPSOMSPP_WIDGET_QT5_FOUND)

MESSAGE("PAPPSOms++ library : ${PAPPSOMSPP_QT5_LIBRARY}")

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules)

if (Pwiz_FOUND)
else (Pwiz_FOUND)
    FIND_PACKAGE(Pwiz REQUIRED COMPONENTS chrono filesystem iostreams program_options serialization system thread)
endif (Pwiz_FOUND)

if (Boost_FOUND)
else (Boost_FOUND)
    FIND_PACKAGE(Boost REQUIRED)
endif (Boost_FOUND)



if (Boost_FOUND)
    MESSAGE("Boost_LIBRARIES found ${Boost_LIB_VERSION}")
endif (Boost_FOUND)


IF (Pwiz_FOUND)
  #INCLUDE_DIRECTORIES( ${Pwiz_INCLUDE_DIR})
  #FIND_PACKAGE(Boost REQUIRED)
  #INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS})
ELSE (Pwiz_FOUND)
  MESSAGE("Proteowizard library not found")
  MESSAGE("did you apt-get install libpwiz-dev libboost-dev ?")
ENDIF (Pwiz_FOUND)

configure_file (${CMAKE_SOURCE_DIR}/src/config.h.cmake ${CMAKE_SOURCE_DIR}/src/config.h)

# File list
SET(CPP_FILES
  core/automaticfilterparameters.cpp
  core/identificationgroup.cpp
  core/identification_sources/identificationdatasource.cpp
  core/identification_sources/identificationmascotdatfile.cpp
  core/identification_sources/identificationpepxmlfile.cpp
  core/identification_sources/identificationpwizfile.cpp
  core/identification_sources/identificationxtandemfile.cpp
  core/labeling/label.cpp
  core/labeling/labelingmethod.cpp
  core/qvalue/computeqvalues.cpp
  core/tandem_run/tandembatchprocess.cpp
  core/tandem_run/tandemcondorprocess.cpp
  core/tandem_run/tandemparameters.cpp
  core/msrun.cpp
  core/peptideevidence.cpp
  core/peptidematch.cpp
  core/peptidextp.cpp
  core/project.cpp
  core/proteinmatch.cpp
  core/proteinxtp.cpp
  core/sequencedatabase.cpp
  files/fastafile.cpp
  files/tandemparametersfile.cpp
  files/xpipfile.cpp
  grouping/groupingexperiment.cpp
  grouping/groupinggroup.cpp
  grouping/groupingpeptidemass.cpp
  grouping/ptm/ptmgroupingexperiment.cpp
  grouping/ptm/ptmisland.cpp
  grouping/ptm/ptmislandgroup.cpp
  grouping/ptm/ptmislandsubgroup.cpp
  grouping/ptm/ptmsamplescan.cpp
  input/mascot/mascotdatparser.cpp
  input/mascot/mimeparser.cpp
  input/condorqxmlsaxhandler.cpp
  input/identificationpwizreader.cpp
  input/pepxmlsaxhandler.cpp
  input/xpipsaxhandler.cpp
  input/xtandemparamsaxhandler.cpp
  input/xtandemsaxhandler.cpp
  input/xtpxpipsaxhandler.cpp
  output/mcqr/mcqrscprotein.cpp
  output/mcqr/mcqrscpeptide.cpp
  output/ods/ptm/ptmislandsheet.cpp
  output/ods/ptm/ptmspectrasheet.cpp
  output/ods/comparbasesheet.cpp
  output/ods/comparspecificspectrasheet.cpp
  output/ods/comparspectrabypeptide.cpp
  output/ods/comparspectrasheet.cpp
  output/ods/groupingsheet.cpp
  output/ods/infosheet.cpp
  output/ods/odsexport.cpp
  output/ods/peptidepossheet.cpp
  output/ods/peptidesheet.cpp
  output/ods/proteinsheet.cpp
  output/ods/samplesheet.cpp
  output/ods/simplesheet.cpp
  output/ods/spectrasheet.cpp
  output/exportfastafile.cpp
  output/masschroqml.cpp
  output/masschroqprm.cpp
  output/mcqrspectralcount.cpp
  output/proticdbml.cpp
  output/xpip.cpp
  utils/fastafilestore.cpp
  utils/identificationdatasourcestore.cpp
  utils/groupstore.cpp
  utils/httpversion.cpp
  utils/msrunstatisticshandler.cpp
  utils/msrunstore.cpp
  utils/peptideevidencestore.cpp
  utils/peptidestore.cpp
  utils/proteinstore.cpp
  utils/utils.cpp
)

# we need this to be able to include headers produced by uic in our code
# (CMAKE_BINARY_DIR holds a path to the build directory, while INCLUDE_DIRECTORIES() works just like INCLUDEPATH from qmake)

SET(XTPCPP_SRCS
  ./gui/about_dialog/aboutdialog.cpp
  ./gui/choose_modification_dialog/choosemodificationdialog.cpp
  ./gui/edit/edit_label_methods/editlabelmethods.cpp
  ./gui/edit/edit_modifications/editmodifications.cpp
  ./gui/edit/edit_settings/editsettings.cpp
  ./gui/edit/edit_tandem_preset_dialog/edittandempresetdialog.cpp
  ./gui/export/export_masschroq_dialog/exportmasschroqdialog.cpp
  ./gui/export/export_masschroq_dialog/masschroqfileparameters.cpp
  ./gui/export/export_spreadsheet_dialog/exportspreadsheetdialog.cpp
  ./gui/load_results_dialog/loadresultsdialog.cpp
  ./gui/mainwindow.cpp
  ./gui/peptide_detail_view/peptidewindow.cpp
  ./gui/peptide_list_view/peptidelistwindow.cpp
  ./gui/peptide_list_view/peptidetablemodel.cpp
  ./gui/peptide_list_view/peptidetableproxymodel.cpp
  ./gui/project_view/identification_group_widget/identificationgroupwidget.cpp
  ./gui/project_view/projectwindow.cpp
  ./gui/protein_view/proteinwindow.cpp
  ./gui/protein_list_view/proteinlistwindow.cpp
  ./gui/protein_list_view/proteintablemodel.cpp
  ./gui/protein_list_view/proteintableproxymodel.cpp
  ./gui/ptm_island_list_view/ptmislandlistwindow.cpp
  ./gui/ptm_island_list_view/ptmislandtablemodel.cpp
  ./gui/ptm_island_list_view/ptmislandproxymodel.cpp
  ./gui/ptm_peptide_list_view/ptmpeptidelistwindow.cpp
  ./gui/ptm_peptide_list_view/ptmpeptidetablemodel.cpp
  ./gui/ptm_peptide_list_view/ptmpeptidetableproxymodel.cpp
  ./gui/ptm_peptide_list_view/ptmsequencedelegate.cpp
  ./gui/tandem_run_dialog/tandemrundialog.cpp
  ./gui/waiting_message_dialog/waitingmessagedialog.cpp
  ./gui/widgets/automatic_filter_widget/automaticfilterwidget.cpp
  ./gui/widgets/contaminant_widget/contaminantwidget.cpp
  ./gui/widgets/decoy_widget/decoywidget.cpp
  ./gui/widgets/xic_extraction_method_widget/xicextractionmethodwidget.cpp
  ./gui/widgets/massitemdelegate.cpp
  ./gui/xic_view/xic_box/xicbox.cpp
  ./gui/xic_view/xic_widgets/zivydialog.cpp
  ./gui/xic_view/xic_widgets/zivywidget.cpp
  ./gui/xic_view/xicwindow.cpp
  ./gui/xic_view/xicworkerthread.cpp
  ./gui/workerthread.cpp
  ./utils/workmonitor.cpp
)

SET (GUI_UIS
  ./gui/about_dialog/about_dialog.ui
  ./gui/choose_modification_dialog/choose_modification_dialog.ui
  ./gui/edit/edit_label_methods/edit_label_methods.ui
  ./gui/edit/edit_modifications/edit_modifications.ui
  ./gui/edit/edit_settings/edit_settings.ui
  ./gui/edit/edit_tandem_preset_dialog/edit_tandem_preset_dialog.ui
  ./gui/export/export_masschroq_dialog/export_masschroq_dialog.ui
  ./gui/export/export_spreadsheet_dialog/export_spreadsheet_dialog.ui
  ./gui/load_results_dialog/load_results_dialog.ui
  ./gui/main.ui
  ./gui/peptide_detail_view/peptide_detail_view.ui
  ./gui/peptide_list_view/peptide_view.ui
  ./gui/project_view/identification_group_widget/identification_group_widget.ui
  ./gui/project_view/project_view.ui
  ./gui/protein_list_view/protein_view.ui
  ./gui/protein_view/protein_detail_view.ui
  ./gui/ptm_island_list_view/ptm_island_list_view.ui
  ./gui/ptm_peptide_list_view/ptm_peptide_list_view.ui
  ./gui/tandem_run_dialog/tandem_run_dialog.ui
  ./gui/waiting_message_dialog/waiting_message_dialog.ui
  ./gui/widgets/automatic_filter_widget/automatic_filter_widget.ui
  ./gui/widgets/contaminant_widget/contaminant_widget.ui
  ./gui/widgets/decoy_widget/decoy_widget.ui
  ./gui/xic_view/xic_box/xic_box.ui
  ./gui/xic_view/xic_widgets/zivy_widget.ui
  ./gui/xic_view/xic_window.ui
)


# this will run uic on .ui files:
QT5_WRAP_UI( GUI_UI_HDRS ${GUI_UIS} )


MESSAGE("XTPCPP_SRCS:  ${XTPCPP_SRCS}")


ADD_EXECUTABLE(xtpcpp main.cpp ${CPP_FILES} ${XTPCPP_SRCS} ${GUI_UI_HDRS} ${xtpcpp_RCC_SRCS})

target_include_directories (xtpcpp PUBLIC ${Pwiz_INCLUDE_DIR} ${PAPPSOMSPP_INCLUDE_DIR} ${ODSSTREAM_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} ${QCustomPlot_INCLUDES} ${QUAZIP_INCLUDE_DIR})

target_compile_definitions(xtpcpp PUBLIC ${QT_DEFINITIONS})
  SET_TARGET_PROPERTIES(xtpcpp
    PROPERTIES OUTPUT_NAME xtpcpp
    CLEAN_DIRECT_OUTPUT 1
    #COMPILE_DEFINITIONS "${QT_DEFINITIONS}"
    #INCLUDE_DIRECTORIES "${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR}"
    )
if (MINGW)
    TARGET_LINK_LIBRARIES(xtpcpp 
    ${PAPPSOMSPP_QT5_LIBRARY} 
    ${PAPPSOMSPP_WIDGET_QT5_LIBRARY} 
    ${Pwiz_LIBRARY} 
    ${ODSSTREAM_QT5_LIBRARY} 
    ${QCustomPlot_LIBRARIES}
    ${Boost_chrono_LIBRARY}
    ${Boost_filesystem_LIBRARY}
    ${Boost_iostreams_LIBRARY}
    ${Boost_program_options_LIBRARY}
    ${Boost_serialization_LIBRARY}
    ${Boost_system_LIBRARY}
    ${Boost_thread_LIBRARY}
    ${ZLIB_LIBRARIES}
    Qt5::Gui Qt5::Xml Qt5::Svg Qt5::PrintSupport Qt5::Network)
else (MINGW)
    TARGET_LINK_LIBRARIES(xtpcpp ${PAPPSOMSPP_QT5_LIBRARY} ${PAPPSOMSPP_WIDGET_QT5_LIBRARY} ${Pwiz_LIBRARY} ${ODSSTREAM_QT5_LIBRARY} ${QCustomPlot_LIBRARIES}
    Qt5::Gui Qt5::Xml Qt5::Svg Qt5::PrintSupport Qt5::Network)
endif (MINGW)

INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/xtpcpp DESTINATION bin)

#configure_file (${CMAKE_SOURCE_DIR}/templates/share/applications/pt-peptideviewer.desktop.cmake ${CMAKE_BINARY_DIR}/templates/share/applications/pt-peptideviewer.desktop)

