# 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( Qt5 COMPONENTS Core Gui Svg Xml PrintSupport Sql Network Concurrent REQUIRED )
qt5_add_resources(xtpcpp_RCC_SRCS ${xtpcpp_RCCS})


find_package(ZLIB REQUIRED)


if(QCustomPlot_FOUND)
  message("QCustomPlot_INCLUDES found ${QCustomPlot_INCLUDE_DIRS}")
else(QCustomPlot_FOUND)
  find_package( QCustomPlot REQUIRED )
endif(QCustomPlot_FOUND)


if(RData_FOUND)
  message("RData_INCLUDE_DIRS found ${RData_INCLUDE_DIRS}")
  message("RData_LIBRARIES found ${RData_LIBRARIES}")
else(RData_FOUND)
  find_package(RData REQUIRED)
endif(RData_FOUND)

if(Grantlee5_FOUND)
else(Grantlee5_FOUND)
  message("Grantlee library not found")
endif(Grantlee5_FOUND)


#sudo apt-get install libpappsomspp-dev
if(PappsoMSpp_FOUND)
else(PappsoMSpp_FOUND)
  message("PAPPSOms++ library not found")
  message("did you apt-get install libpappsomspp-dev ?")
endif(PappsoMSpp_FOUND)


if(PappsoMSppWidget_FOUND)
else(PappsoMSppWidget_FOUND)
  message("PAPPSOms++ widget library not found")
  message("did you apt-get install libpappsomspp-widget-dev ?")
endif(PappsoMSppWidget_FOUND)

message("PAPPSOms++ library : ${PappsoMSpp_LIBRARIES}")


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

# File list
set(CPP_FILES
  core/automaticfilterparameters.cpp
  core/condor_process/condorprocess.cpp
  core/condor_process/condorqueueparser.cpp
  core/identificationgroup.cpp
  core/identification_sources/identificationdatasource.cpp
  core/identification_sources/identificationmascotdatfile.cpp
  core/identification_sources/identificationmzidentmlfile.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/masschroq_run/masschroqbatchprocess.cpp
  core/masschroq_run/masschroqcondorprocess.cpp
  core/masschroq_run/masschroqfileparameters.cpp
  core/mcqr/mcqrexperiment.cpp
  core/qvalue/computeqvalues.cpp
  core/tandem_run/tandembatchprocess.cpp
  core/tandem_run/tandemcondorprocess.cpp
  core/tandem_run/tandemparameters.cpp
  core/alignmentgroup.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/ptm/ptmacetylation.cpp
  grouping/ptm/ptminterface.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/ptmphospho.cpp
  grouping/ptm/ptmsamplescan.cpp
  input/mascot/mascotdatparser.cpp
  input/mascot/mimeparser.cpp
  input/mzidentml/msrunsaxhandler.cpp
  input/mzidentml/mzidentmlsaxhandler.cpp
  input/tandem/tandeminfoparser.cpp
  input/tandem/tandemparamparser.cpp
  #  input/identificationpwizreader.cpp
  input/metadataodshandler.cpp
  input/pepxmlsaxhandler.cpp
  input/xpipsaxhandler.cpp
  input/xtandemsaxhandler.cpp
  input/xtpxpipsaxhandler.cpp
  output/mcqr/mcqrdata.cpp
  output/mcqr/mcqrscprotein.cpp
  output/mcqr/mcqrscpeptide.cpp
  output/ods/mass_delta/validmassdeltasheet.cpp
  output/ods/mass_delta/notvalidmassdeltasheet.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/mcqrmetadatasheet.cpp
  output/ods/odsexport.cpp
  output/ods/peptidepossheet.cpp
  output/ods/peptidesheet.cpp
  output/ods/proteinsheet.cpp
  output/ods/qvaluessheet.cpp
  output/ods/samplesheet.cpp
  output/ods/simplesheet.cpp
  output/ods/spectrasheet.cpp
  output/ods/spectrasheetall.cpp
  output/ods/xicareasheet.cpp
  output/ods/xicinfosheet.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/ptmbuilder.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
  ./core/mcqr/mcqrqprocess.cpp
  ./gui/about_dialog/aboutdialog.cpp
  ./gui/choose_modification_dialog/choosemodificationdialog.cpp
  ./gui/edit/deepprot_gui/modification_browser/modificationbrowser.cpp
  ./gui/edit/deepprot_gui/deepprotgui.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_spreadsheet_dialog/exportspreadsheetdialog.cpp
  ./gui/load_results_dialog/loadresultsdialog.cpp
  ./gui/lists/ms_identification_run_list_view/msidentificationlistwindow.cpp
  ./gui/lists/ms_identification_run_list_view/msidentificationtablemodel.cpp
  ./gui/lists/ms_identification_run_list_view/msidentificationtableproxymodel.cpp
  ./gui/lists/ms_identification_run_list_view/ms_identification_worker/msidlistworkerstatus.cpp
  ./gui/lists/ms_identification_run_list_view/engine_detail_view/enginedetailwindow.cpp
  ./gui/masschroq_run_dialog/masschroqrundialog.cpp
  ./gui/mcqr_param_dialog/mcqrparamallquantidialog.cpp
  ./gui/mcqr_run_view/mcqrparamwidget.cpp
  ./gui/mcqr_run_view/mcqrrunview.cpp
  ./gui/mcqr_run_view/mcqr_sds_widget/mcqrsdswidget.cpp
  ./gui/mcqr_run_view/mcqr_sds_xic_widget/mcqrsdsxicwidget.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/Alignment_group_menu/alignmentgroupmenu.cpp
  ./gui/widgets/automatic_filter_widget/automaticfilterwidget.cpp
  ./gui/widgets/engines_view/xtandemparamwidget.cpp
  ./gui/widgets/engines_view/noengineparamwidget.cpp
  ./gui/widgets/qcp_massdelta/massdeltawidget.cpp
  ./gui/widgets/qcp_massdelta/qcpmassdelta.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/xic_widgets/xicexportparam.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/deepprot_gui/modification_browser/uimodificationbrowser.ui
  ./gui/edit/deepprot_gui/deepprot_gui.ui
  ./gui/edit/edit_alignment_param/masschroq_param_view.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_spreadsheet_dialog/export_spreadsheet_dialog.ui
  ./gui/lists/ms_identification_run_list_view/ms_identification_run_view.ui
  ./gui/lists/ms_identification_run_list_view/engine_detail_view/engine_detail_view.ui
  ./gui/load_results_dialog/load_results_dialog.ui
  ./gui/masschroq_run_dialog/masschroq_run_dialog.ui
  ./gui/mcqr_param_dialog/mcqr_param_all_quanti_dialog.ui
  ./gui/mcqr_run_view/mcqr_run_view.ui
  ./gui/mcqr_run_view/mcqr_sds_widget/mcqr_sds_widget.ui
  ./gui/mcqr_run_view/mcqr_sds_xic_widget/mcqr_sds_xic_widget.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/engines_view/xtandem_view_widget.ui
  ./gui/widgets/engines_view/no_engine_view_widget.ui
  ./gui/widgets/qcp_massdelta/qcpmassdelta.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_widgets/xic_export_param.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}")




if(UNIX AND NOT APPLE)

  add_executable(${TARGET} main.cpp ${CPP_FILES} ${XTPCPP_SRCS} ${GUI_UI_HDRS} ${xtpcpp_RCC_SRCS})
  add_executable(tandemwrapper tandemwrapper.cpp)


elseif(APPLE)

  add_executable(${TARGET} main.cpp ${CPP_FILES} ${XTPCPP_SRCS} ${GUI_UI_HDRS} ${xtpcpp_RCC_SRCS}
    ${PLATFORM_SPECIFIC_SOURCES}
    ../src/resources/xtandempipeline_icon.icns
    )

  set_target_properties(${TARGET} PROPERTIES 
    MACOSX_BUNDLE_ICON_FILE xtandempipeline_icon.icns)

elseif(MXE)

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

  target_compile_options(${TARGET} PRIVATE -mwindows)
  set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "-Wl,--subsystem,windows ${CMAKE_EXE_LINKER_FLAGS}")
  target_compile_options(tandemwrapper PRIVATE -mwindows)
  set_target_properties(tandemwrapper PROPERTIES LINK_FLAGS "-Wl,--subsystem,windows ${CMAKE_EXE_LINKER_FLAGS}")

endif()




target_link_libraries(tandemwrapper Qt5::Core Qt5::Xml PappsoMSpp::Core)

target_include_directories(${TARGET} PUBLIC
  ${Quazip5_INCLUDE_DIRS}
  ${QCustomPlot_INCLUDE_DIR}
  )

target_link_libraries(${TARGET}
  OdsStream::Core
  PappsoMSpp::Core
  PappsoMSpp::Widget
  Grantlee5::Templates
  RData::Core
  Qt5::Core
  Qt5::Gui
  Qt5::Xml
  Qt5::Svg
  Qt5::PrintSupport
  Qt5::Network
  Qt5::Sql
  Qt5::Concurrent
  ZLIB::ZLIB
  QCustomPlot::QCustomPlot
  ${Quazip5_LIBRARY}
  )




install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET} DESTINATION bin)

install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/tandemwrapper DESTINATION bin)

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

