# CMake script for PAPPSOms++ library
# Author: Olivier Langella
# Created: 03/03/2015
# Rework: April 2020 (Coronavirus confinement)

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


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


add_definitions(-DWITHOUT_MZ5)


########################################################
# Files
set(CPP_FILES
	pappsomspp/utils.cpp
	pappsomspp/mzrange.cpp
	pappsomspp/precision.cpp

	pappsomspp/processing/combiners/mzintegrationparams.cpp
	pappsomspp/processing/combiners/tracecombiner.cpp
	pappsomspp/processing/combiners/traceminuscombiner.cpp
	pappsomspp/processing/combiners/tracepluscombiner.cpp

	pappsomspp/processing/filters/filterchargedeconvolution.cpp
	pappsomspp/processing/filters/filtercomplementionenhancer.cpp
	pappsomspp/processing/filters/filterlocalmaximum.cpp
	pappsomspp/processing/filters/filtermorpho.cpp
	pappsomspp/processing/filters/filternameinterface.cpp
	pappsomspp/processing/filters/filterpass.cpp
	pappsomspp/processing/filters/filterpseudocentroid.cpp
	pappsomspp/processing/filters/filterremovec13.cpp
	pappsomspp/processing/filters/filterresample.cpp
	pappsomspp/processing/filters/filtersuite.cpp
	pappsomspp/processing/filters/filtersuitestring.cpp
	pappsomspp/processing/filters/filtertandemremovec13.cpp
	pappsomspp/processing/filters/filtertriangle.cpp
	pappsomspp/processing/filters/savgolfilter.cpp

	pappsomspp/processing/filters/pwiz/ms/peakpickerqtof.hpp
	pappsomspp/processing/filters/pwiz/ms/simplepicker.hpp
	pappsomspp/processing/filters/pwiz/resample/convert2dense.hpp

	pappsomspp/processing/tandemwrapper/tandemwrapperrun.cpp
	pappsomspp/processing/tandemwrapper/xtandeminputsaxhandler.cpp
	pappsomspp/processing/tandemwrapper/xtandemoutputsaxhandler.cpp
	pappsomspp/processing/tandemwrapper/xtandempresetsaxhandler.cpp

	pappsomspp/massspectrum/massspectrumid.cpp
	pappsomspp/massspectrum/massspectrum.cpp
	pappsomspp/massspectrum/qualifiedmassspectrum.cpp

	pappsomspp/processing/combiners/massdatacombinerinterface.cpp
	pappsomspp/processing/combiners/massspectrumcombiner.cpp
	pappsomspp/processing/combiners/massspectrumpluscombiner.cpp
	pappsomspp/processing/combiners/massspectrumminuscombiner.cpp

	pappsomspp/amino_acid/aabase.cpp
	pappsomspp/amino_acid/aa.cpp
	pappsomspp/amino_acid/aamodification.cpp

	pappsomspp/fasta/fastafileindexer.cpp
	pappsomspp/fasta/fastareader.cpp
	pappsomspp/fasta/fastaoutputstream.cpp

	pappsomspp/grouping/grpexperiment.cpp
	pappsomspp/grouping/grppeptide.cpp
	pappsomspp/grouping/grpprotein.cpp
	pappsomspp/grouping/grpgroup.cpp
	pappsomspp/grouping/grpsubgroup.cpp
	pappsomspp/grouping/grppeptideset.cpp
	pappsomspp/grouping/grpmappeptidetogroup.cpp
	pappsomspp/grouping/grpmappeptidetosubgroupset.cpp
	pappsomspp/grouping/grpsubgroupset.cpp
	pappsomspp/grouping/grpgroupingmonitor.cpp

	pappsomspp/msfile/msfileaccessor.cpp
	pappsomspp/msfile/msfilereader.cpp
	pappsomspp/msfile/pwizmsfilereader.cpp
	pappsomspp/msfile/timsmsfilereader.cpp
	pappsomspp/msfile/xymsfilereader.cpp

	pappsomspp/msrun/alignment/msrunretentiontime.cpp
	pappsomspp/msrun/alignment/template.cpp
	pappsomspp/msrun/output/mzxmloutput.cpp
	pappsomspp/msrun/output/mgfoutput.cpp
	pappsomspp/msrun/msrundatasettreenode.cpp
	pappsomspp/msrun/msrundatasettree.cpp
	pappsomspp/msrun/msrunid.cpp
	pappsomspp/msrun/msrunreader.cpp
	pappsomspp/msrun/private/pwizmsrunreader.cpp
	pappsomspp/msrun/private/timsmsrunreader.cpp
	pappsomspp/msrun/private/timsmsrunreaderms2.cpp
	pappsomspp/msrun/private/timsmsrunreaderms2selected.cpp
	pappsomspp/msrun/xymsrunreader.cpp

	pappsomspp/obo/obopsimod.cpp
	pappsomspp/obo/filterobopsimodsink.cpp
	pappsomspp/obo/filterobopsimodtermaccession.cpp
	pappsomspp/obo/filterobopsimodtermlabel.cpp
	pappsomspp/obo/filterobopsimodtermdiffmono.cpp
	pappsomspp/obo/filterobopsimodtermname.cpp

	pappsomspp/peptide/ion.cpp
	pappsomspp/peptide/peptideinterface.cpp
	pappsomspp/peptide/peptide.cpp
	pappsomspp/peptide/peptidefragment.cpp
	pappsomspp/peptide/peptidefragmention.cpp
	pappsomspp/peptide/peptidefragmentionlistbase.cpp
	pappsomspp/peptide/peptidenaturalisotope.cpp
	pappsomspp/peptide/peptidenaturalisotopelist.cpp
	pappsomspp/peptide/peptidenaturalisotopeaverage.cpp
	pappsomspp/peptide/peptiderawfragmentmasses.cpp
	pappsomspp/peptide/peptidestrparser.cpp

	pappsomspp/protein/protein.cpp
	pappsomspp/protein/enzyme.cpp
	pappsomspp/protein/peptidesizefilter.cpp
	pappsomspp/protein/peptidebuilder.cpp
	pappsomspp/protein/peptidevariablemodificationbuilder.cpp
	pappsomspp/protein/peptidevariablemodificationreplacement.cpp
	pappsomspp/protein/peptidefixedmodificationbuilder.cpp
	pappsomspp/protein/peptidemodificatorbase.cpp
	pappsomspp/protein/peptidemodificatortee.cpp
	pappsomspp/protein/peptidemethioninremove.cpp
	pappsomspp/protein/peptidemodificatorpipeline.cpp
	pappsomspp/protein/peptidesemienzyme.cpp

	pappsomspp/psm/experimental/ionisotoperatioscore.cpp
	pappsomspp/psm/morpheus/morpheusscore.cpp
	pappsomspp/psm/peakionmatch.cpp
	pappsomspp/psm/peakionisotopematch.cpp
	pappsomspp/psm/peptidespectrummatch.cpp
	pappsomspp/psm/peptideisotopespectrummatch.cpp
	pappsomspp/psm/xtandem/xtandemhyperscore.cpp
	pappsomspp/psm/xtandem/xtandemhyperscorebis.cpp
	pappsomspp/psm/xtandem/xtandemspectrumprocess.cpp

	pappsomspp/trace/datapoint.cpp
	pappsomspp/trace/linearregression.cpp
	pappsomspp/trace/maptrace.cpp
	pappsomspp/trace/trace.cpp

	pappsomspp/vendors/tims/mzcalibration/mzcalibrationinterface.cpp
	pappsomspp/vendors/tims/mzcalibration/mzcalibrationmodel1.cpp
	pappsomspp/vendors/tims/mzcalibration/mzcalibrationstore.cpp
	pappsomspp/vendors/tims/xicextractor/timsdirectxicextractor.cpp
	pappsomspp/vendors/tims/xicextractor/timsxicextractorinterface.cpp
	pappsomspp/vendors/tims/timsbindec.cpp
	pappsomspp/vendors/tims/timsdata.cpp
	pappsomspp/vendors/tims/timsframe.cpp
	pappsomspp/vendors/tims/timsframebase.cpp
	pappsomspp/vendors/tims/timsms2centroidfilter.cpp

	pappsomspp/xic/xic.cpp
	pappsomspp/xic/qualifiedxic.cpp
	pappsomspp/xic/xicpeptideinterface.cpp
	pappsomspp/xic/xicpeptidefragmention.cpp
	pappsomspp/xic/xicpeptidefragmentionnaturalisotope.cpp

	pappsomspp/processing/detection/tracedetectionzivy.cpp
	pappsomspp/processing/detection/tracedetectionmoulon.cpp
	pappsomspp/processing/detection/tracepeak.cpp

	pappsomspp/xicextractor/private/msrunslice.cpp
	pappsomspp/xicextractor/private/msrunxicextractor.cpp
	pappsomspp/xicextractor/private/msrunxicextractordisk.cpp
	pappsomspp/xicextractor/private/msrunxicextractordiskbuffer.cpp
	pappsomspp/xicextractor/msrunxicextractorfactory.cpp
	pappsomspp/xicextractor/msrunxicextractorinterface.cpp
	)


find_package(Qt5 COMPONENTS Core Gui Svg Xml PrintSupport Sql Concurrent REQUIRED)

message("Qt5Core_LIBRARIES ${Qt5Core_LIBRARIES}")
message("QT_CORE_LIB ${QT_CORE_LIB}")

set(pappsomspp_RCCS libpappsomsppresources.qrc)
# generate rules for building source files from the resources
qt5_add_resources(pappsomspp_RCC_SRCS ${pappsomspp_RCCS})

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


#############################################################
# Build the static lib
add_library(pappsomspp-static STATIC ${CPP_FILES} ${pappsomspp_RCC_SRCS})

set_target_properties(pappsomspp-static
	PROPERTIES OUTPUT_NAME pappsomspp
	CLEAN_DIRECT_OUTPUT 1
	LINK_FLAGS -Wl,--whole-archive
	)

target_include_directories(pappsomspp-static PUBLIC
	${PwizLite_INCLUDE_DIRS}
	)

target_link_libraries(pappsomspp-static 
	Qt5::Core
	Qt5::Gui
	Qt5::Xml
	Qt5::Svg
	Qt5::PrintSupport
	Qt5::Sql
	Qt5::Concurrent
	Zstd::Zstd
	Alglib::Alglib
	SQLite::SQLite3
	Boost::iostreams
	Boost::filesystem
	Boost::thread
	Boost::chrono
	ZLIB::ZLIB
	PwizLite::PwizLite
	)


# FIXME: should check that this still required. It was years ago.
if(WIN32 OR _WIN32)

	target_link_libraries(pappsomspp-static 
		stdc++
		)
endif()


#############################################################
# Build the shared lib
add_library(pappsomspp-shared SHARED ${CPP_FILES} ${pappsomspp_RCC_SRCS})

set_target_properties(pappsomspp-shared
	PROPERTIES OUTPUT_NAME pappsomspp
	CLEAN_DIRECT_OUTPUT 1
	VERSION ${PAPPSOMSPP_VERSION}
	SOVERSION ${PAPPSOMSPP_VERSION_MAJOR}
    LINK_FLAGS "${LINKER_FLAGS}"
	)

target_include_directories(pappsomspp-shared PUBLIC
	${PwizLite_INCLUDE_DIRS}
	)

target_link_libraries(pappsomspp-shared 
	Qt5::Core
	Qt5::Gui
	Qt5::Xml
	Qt5::Svg
	Qt5::PrintSupport
	Qt5::Sql
	Qt5::Concurrent
	Zstd::Zstd
	SQLite::SQLite3
	Alglib::Alglib
	Boost::iostreams
	Boost::filesystem
	Boost::thread
	Boost::chrono
	ZLIB::ZLIB
	PwizLite::PwizLite
	)


# Should check that this still required. It was years ago.
if(WIN32 OR _WIN32)

	target_link_libraries(pappsomspp-shared 
		stdc++
		)

endif()


# Install libs

install(TARGETS pappsomspp-shared 
	LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
	# This one is for WIN32
	RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
	)

install(TARGETS pappsomspp-static 
	ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})


# Install headers
install(DIRECTORY pappsomspp/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pappsomspp 
	FILES_MATCHING PATTERN "*.h"
	PATTERN "*.hpp")

add_subdirectory("pappsomspp/widget")
