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


########################################################
# Files
set(${TARGET}_nongui_SRCS
  #
  # Some globals.
  nongui/globals.cpp
  #
  # The classes to look into an MS run prior to loading it
  nongui/MsRunProber.cpp
  nongui/vendor/BrukerTimsTofMsRunProber.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
  #
  # The class to load MS run data
  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
  #
  # The various MsRunDataSetTreeNodeVisitor classes.
  nongui/BaseMsRunDataSetTreeNodeVisitor.cpp
  nongui/MsRunStatisticsTreeNodeVisitor.cpp
  nongui/TicChromTreeNodeCombinerVisitor.cpp
  nongui/TicChromatogramFromMassSpecDataFile.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
  #
  # Analysis preferences
  nongui/AnalysisPreferences.cpp
)

set(${TARGET}_gui_SRCS
  gui/Application.cpp
  gui/ProgramWindow.cpp
  gui/MsRunSelectorDlg.cpp
  gui/AboutDlg.cpp
  #
  gui/ConsoleWnd.cpp
  #
  gui/MsRunReadTask.cpp
  gui/MsRunProbeTask.cpp
  #
  gui/OpenMsRunDataSetsDlg.cpp
  #
  gui/TaskMonitorCompositeWidget.cpp
  gui/TaskMonitorWnd.cpp
  #
  gui/MsRunProbeInfoViewerDlg.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 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/ProcessingFlowViewerDlg.ui
  gui/ui/XicExtractionWnd.ui
  gui/ui/AnalysisPreferencesDlg.ui
  gui/ui/ScriptingWnd.ui
  gui/ui/MsRunProbeInfoViewerDlg.ui
)

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

qt6_add_resources(${TARGET}_QRC_CPP ../${LOWCASE_PROJECT_NAME}.qrc)

# Instruct CMake to run automatically when needed the following:
set(CMAKE_AUTOMOC ON) # For meta object compiler
set(CMAKE_AUTORCC ON) # Resource files

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}
)


###############################################################
# 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}
    main.cpp
    ${${TARGET}_nongui_SRCS}
    ${${TARGET}_gui_SRCS}
    ${${TARGET}_UIS_H}
    ${${TARGET}_QRC_CPP}
    ${PLATFORM_SPECIFIC_SOURCES}
  )

  # In Debug mode we want the console to be opened so that we can read the debug
  # messages. But in Release mode the console is not desirable (the snippet
  # below removes it).
  if(CMAKE_BUILD_TYPE STREQUAL "Release")
    set_property(TARGET ${TARGET} PROPERTY WIN32_EXECUTABLE true)
  endif()

elseif(UNIX)

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

endif()


# Finally actually set the linking dependencies to the executable.
# Note that there are so many cross-dependencies that it is virtually unfeasible
# to actually link the binary without resorting to the linker dance steps below.

# Still, I discovered that the order below is good with respect of the symbols
# dependencies resolutions when linking

# The general idea is to first list the libraries that *use* symbols and later
# libraries that *provide* symbols. Which is why all the Qt libs are listed at
# the end and the private libs are listed first.
target_link_libraries(${TARGET}

  -Wl,--whole-archive
  libmass::nongui
  libmass::gui
  -Wl,--no-whole-archive

  -Wl,--no-as-needed
  PappsoMSpp::Core
  PappsoMSpp::Widget
  -Wl,--as-needed

  -Wl,--no-as-needed
  IsoSpec++::IsoSpec++
  -Wl,--as-needed

  QCustomPlotQt6::QCustomPlotQt6
  QuaZip::QuaZip

  Qt6::Widgets
  Qt6::Svg
  Qt6::PrintSupport
  Qt6::Xml
  Qt6::Network
  Qt6::Sql
)


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

# 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})


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