message(\n${BoldRed}"Now configuring src/ for ${CMAKE_PROJECT_NAME}"${ColourReset}\n)


########################################################
# Files
set(${TARGET}_nongui_SRCS
  #
  # Some globals.
  nongui/globals.cpp
  #
  # The classes for the IsoSpec calculations.
  nongui/Atom.cpp
  nongui/AtomCount.cpp
  nongui/Formula.cpp
  nongui/IsoSpecEntity.cpp
  nongui/Isotope.cpp
  nongui/Ponderable.cpp
  #
  # The main class that hold the mass data.
  nongui/MsRunDataSet.cpp
  #
  # The class to handle the statistics computation about a given MsRunDataSet.
  nongui/MsRunDataSetStats.cpp

  nongui/MassSpecDataFileLoader.cpp
  #
  # The classe that monitors integrators.
  nongui/MassDataIntegratorTask.cpp
  #
  # The base class of the integrators.
  nongui/MassDataIntegrator.cpp
  #
  # The various integrators that use BaseMsRunDataSetTreeNodeVisitor.
  nongui/MsRunDataSetTreeMassDataIntegratorToRt.cpp
  #nongui/MsRunDataSetTreeMassDataIntegratorToMz.cpp
  #nongui/MsRunDataSetTreeMassDataIntegratorToDt.cpp
  #nongui/MsRunDataSetTreeMassDataIntegratorToDtRtMz.cpp
  #nongui/MsRunDataSetTreeMassDataIntegratorToTicInt.cpp
  #
  # The various MsRunDataSetTreeNodeVisitor classes.
  nongui/BaseMsRunDataSetTreeNodeVisitor.cpp
  nongui/MsRunStatisticsTreeNodeVisitor.cpp
  nongui/TicChromTreeNodeCombinerVisitor.cpp
  nongui/TicChromatogramFromMassSpecDataFile.cpp
  #nongui/IntensityTreeNodeCombinerVisitor.cpp
  #nongui/RtDtMzColorMapsTreeNodeCombinerVisitor.cpp
  #nongui/RtDtColorMapTreeNodeCombinerVisitor.cpp
  #nongui/TraceTreeNodeCombinerVisitor.cpp
  #nongui/MassSpectrumTreeNodeCombinerVisitor.cpp
  #nongui/DriftSpectrumTreeNodeCombinerVisitor.cpp
  nongui/MultiTreeNodeCombinerVisitor.cpp
  #
  # The various integrators that use QualifiedMassSpectrumVector.
  nongui/QualifiedMassSpectrumVectorMassDataIntegrator.cpp
  nongui/QualifiedMassSpectrumVectorMassDataIntegratorToRt.cpp
  nongui/QualifiedMassSpectrumVectorMassDataIntegratorToMz.cpp
  nongui/QualifiedMassSpectrumVectorMassDataIntegratorToDt.cpp
  nongui/QualifiedMassSpectrumVectorMassDataIntegratorToTicInt.cpp
  nongui/QualifiedMassSpectrumVectorMassDataIntegratorToDtRtMz.cpp
  nongui/QualifiedMassSpectrumVectorMassDataIntegratorToRtDt.cpp
  #
  # The classes that handle the processing flow
  nongui/ProcessingFlow.cpp
  nongui/ProcessingStep.cpp
  nongui/ProcessingType.cpp
  #
  # The classes that handle the parameters for the various integrations and the
  # display of traces.
  nongui/MsFragmentationSpec.cpp
  #
  # Peak-shaping classes (Gaussian Lorentzian peak shapes).
  nongui/MassPeakShaperConfig.cpp
  nongui/MassPeakShaper.cpp
  #
  # Analysis preferences
  nongui/AnalysisPreferences.cpp
  )

set(${TARGET}_gui_SRCS
  main.cpp
  gui/Application.cpp
  gui/ProgramWindow.cpp
  gui/MsRunSelectorDlg.cpp
  gui/AboutDlg.cpp
  #
  gui/ConsoleWnd.cpp
  #
  gui/MsRunReadTask.cpp
  #
  gui/OpenMsRunDataSetsDlg.cpp
  gui/ColorSelector.cpp
  #
  gui/TaskMonitorCompositeWidget.cpp
  gui/TaskMonitorWnd.cpp
  #
  # The ms run data set tree view classes
  gui/MsRunDataSetTableViewWnd.cpp
  gui/MsRunDataSetTableViewItem.cpp
  gui/MsRunDataSetTableView.cpp
  gui/MsRunDataSetTableViewModel.cpp
  gui/MsRunDataSetTableViewProxyModel.cpp
  #	
  # The MS fragmentation specification dialog
  gui/MsFragmentationSpecDlg.cpp
  #
  # The M/Z integration parameters dialog
  gui/MzIntegrationParamsDlg.cpp
  #
  # The Savitzky-Golay filter params dialog
  gui/SavitzkyGolayFilterParamsDlg.cpp
  #
  # The data plot graph/widget tree classes
  gui/DataPlottableNode.cpp
  gui/DataPlottableTree.cpp
  #
  # The trace plot widgets derived from pappso::BaseTracePlotWidget
  gui/TicXicChromTracePlotWidget.cpp
  gui/MassSpecTracePlotWidget.cpp
  gui/DriftSpecTracePlotWidget.cpp
  #
  # The trace plot composite widgets
  gui/BasePlotCompositeWidget.cpp
  gui/BaseTracePlotCompositeWidget.cpp
  gui/TicXicChromTracePlotCompositeWidget.cpp
  gui/MassSpecTracePlotCompositeWidget.cpp
  gui/DriftSpecTracePlotCompositeWidget.cpp
  #
  # The color map plot composite widgets
  gui/BaseColorMapPlotCompositeWidget.cpp
  gui/TicXicChromMassSpecColorMapPlotCompositeWidget.cpp
  gui/TicXicChromDriftSpecColorMapPlotCompositeWidget.cpp
  gui/DriftSpecMassSpecColorMapPlotCompositeWidget.cpp
  #
  # The plot windows
  gui/BasePlotWnd.cpp
  #	
  # Trace plot windows
  gui/BaseTracePlotWnd.cpp
  gui/BaseColorMapPlotWnd.cpp
  gui/TicXicChromTracePlotWnd.cpp
  gui/MassSpecTracePlotWnd.cpp
  gui/DriftSpecTracePlotWnd.cpp
  #
  # Color map plot windows
  gui/TicXicChromMassSpecColorMapWnd.cpp
  gui/TicXicChromDriftSpecColorMapWnd.cpp
  gui/DriftSpecMassSpecColorMapWnd.cpp
  #
  # The save plot to graphics file
  gui/SaveToGraphicsFileDlg.cpp
  #
  # The IsoSpec computations-related widgets
  gui/IsoSpecDlg.cpp
  gui/IsoSpecTableView.cpp
  gui/IsoSpecTableViewModel.cpp
  gui/MassPeakShaperDlg.cpp
  #
  # The ProcessingFlow viewer dialog window
  gui/ProcessingFlowViewerDlg.cpp
  #
  # The XIC chromatogram feature
  gui/XicExtractionWnd.cpp
  #
  # Analysis preferences
  gui/AnalysisPreferencesDlg.cpp
  #
  # Labelled widget-based QAction classes
  gui/LabelledDoubleSpinBoxAction.cpp
  gui/LabelledNumberLineEditAction.cpp
  #
  # Plot overlay transparent widget
  gui/PlotAreaOverlay.cpp
  )

set(${TARGET}_UIS
  gui/ui/AboutDlg.ui
  gui/ui/MsRunSelectorDlg.ui
  gui/ui/OpenMsRunDataSetsDlg.ui
  gui/ui/MsRunDataSetTableViewWnd.ui
  gui/ui/BasePlotWnd.ui
  gui/ui/BasePlotCompositeWidget.ui
  gui/ui/TaskMonitorCompositeWidget.ui
  gui/ui/TaskMonitorWnd.ui
  gui/ui/ConsoleWnd.ui
  gui/ui/MsFragmentationSpecDlg.ui
  gui/ui/MzIntegrationParamsDlg.ui
  gui/ui/SavitzkyGolayFilterParamsDlg.ui
  gui/ui/SaveToGraphicsFileDlg.ui
  gui/ui/IsoSpecDlg.ui
  gui/ui/MassPeakShaperDlg.ui	
  gui/ui/ElementGroupBoxWidget.ui
  gui/ui/ProcessingFlowViewerDlg.ui
  gui/ui/XicExtractionWnd.ui
  gui/ui/AnalysisPreferencesDlg.ui)


find_package(Qt5 COMPONENTS Widgets Xml Svg PrintSupport REQUIRED)

qt5_wrap_ui(${TARGET}_UIS_H ${${TARGET}_UIS})

qt5_add_resources(${TARGET}_QRC_CPP ../minexpert2.qrc)

# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

### These two lines required because now CMake only automocs
### the generated files and not the source files.
# NOT sure about this. Let's comment that for the moment.
# set_source_files_properties(${${TARGET}_UIS_H} PROPERTIES SKIP_AUTOMOC ON)
# set_source_files_properties(${${TARGET}_QRC_CPP} PROPERTIES SKIP_AUTOMOC ON)

include_directories(

  # The config file is binary directory-specific !!!
  # For the config.h file generated from config.h.in
  # For the ui_Xyyyyy.h files
  ${CMAKE_CURRENT_BINARY_DIR}

  # For all the source subdirectories
  ${CMAKE_SOURCE_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}

  ${Qt5Widgets_INCLUDE_DIRS}
  ${Qt5Xml_INCLUDE_DIRS}
  ${Qt5Svg_INCLUDE_DIRS}
  ${Qt5Sql_INCLUDE_DIRS}
  ${Qt5PrintSupport_INCLUDE_DIRS}
  ${IsoSpec++_INCLUDE_DIRS}
  )


###############################################################
# Configuration of the binary to be built
###############################################################

# Only now can we add the executable, because we have defined the sources of the
# object library above.

if(WIN32 OR _WIN32)

  add_executable(${TARGET} WIN32
    ${${TARGET}_nongui_SRCS}
    ${${TARGET}_gui_SRCS}
    ${${TARGET}_UIS_H}
    ${${TARGET}_QRC_CPP}
    ${PLATFORM_SPECIFIC_SOURCES}
    )

elseif(UNIX AND NOT APPLE)

  add_executable(${TARGET}
    ${${TARGET}_nongui_SRCS}
    ${${TARGET}_gui_SRCS}
    ${${TARGET}_UIS_H}
    ${${TARGET}_QRC_CPP}
    ${PLATFORM_SPECIFIC_SOURCES}
    )

elseif(APPLE)

  add_executable(${TARGET} MACOSX_BUNDLE
    ${${TARGET}-exec_SRCS}
    ${${TARGET}_nongui_SRCS}
    ${${TARGET}_gui_SRCS}
    ${${TARGET}_UIS_H}
    ${${TARGET}_QRC_CPP}
    ${PLATFORM_SPECIFIC_SOURCES}
    ../images/icons/${TARGET}.icns
    )

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

  # We need to specify that manually because FindOpenMP() does 
  # not work on macports as of 20200727.
  target_include_directories(${TARGET}
    PUBLIC ${OpenMP_INCLUDE_DIRS})
  target_link_libraries(${TARGET}
    OpenMP::OpenMP)

endif()


# Finally actually set the linking dependencies to the executable.
target_link_libraries(${TARGET}
  Qt5::Widgets
  Qt5::Xml
  Qt5::Svg
  Qt5::PrintSupport
  QCustomPlot::QCustomPlot
  IsoSpec++::IsoSpec++
  PappsoMSpp::Core
  PappsoMSpp::Widget
  )


#### Debugging stuff
message(STATUS required_target_link_libraries: ${required_target_link_libraries})

message(STATUS "Now printing all the include directories -I...")

get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
  message(STATUS "included dir='${dir}'")
endforeach()

message(STATUS "Now printing all the linking directories -L...")

get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY LINK_DIRECTORIES)
foreach(dir ${dirs})
  message(STATUS "link directory dir='${dir}'")
endforeach()

if(PROFILE)
  message(STATUS "Profiling is requested, adding linker -pg flag.")
  set (CMAKE_EXE_LINKER_FLAGS "-pg")
endif()

if(NOT APPLE)
  # We want to install the binary arch-dependent target in
  # specific situations. To have proper control, we define the arch
  # component.
  install(TARGETS ${TARGET}
    RUNTIME
    COMPONENT arch
    DESTINATION ${BIN_DIR})
endif()


message("")
message(STATUS "${BoldGreen}Finished configuring of ${TARGET}.${ColourReset}")
message("")
