# CMake script for PAPPSOms++ library
# Author: Olivier Langella
# Created: 03/03/2015


if (ALGLIB_FOUND)
else (ALGLIB_FOUND)
    set(ALGLIB_DIR ${CMAKE_SOURCE_DIR}/cmake_modules)
    FIND_PACKAGE(ALGLIB REQUIRED)
endif (ALGLIB_FOUND)


if (Zstd_FOUND)
else (Zstd_FOUND)
    set(Zstd_DIR ${CMAKE_SOURCE_DIR}/cmake_modules)
    FIND_PACKAGE(Zstd REQUIRED)
endif (Zstd_FOUND)

if (SQLite3_FOUND)
else (SQLite3_FOUND)
    set(SQLite3_DIR ${CMAKE_SOURCE_DIR}/cmake_modules)
    FIND_PACKAGE(SQLite3 REQUIRED)
endif (SQLite3_FOUND)

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)


#############################################################
# Enable warnings and possibly treat them as errors
message(STATUS "${BoldYellow}Setting -Wall.${ColourReset}")
add_definitions(-Wall)
if(WARN_AS_ERROR)
message(STATUS "${BoldYellow}Warnings treated as errors.${ColourReset}")
add_definitions(-Werror)
endif()

SET(pappsomspp_RCCS libpappsomsppresources.qrc)

# File list
SET(CPP_FILES
	pappsomspp/utils.cpp
	pappsomspp/mzrange.cpp
	pappsomspp/precision.cpp

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

	pappsomspp/processing/filters/filtermorpho.cpp
	pappsomspp/processing/filters/filterpass.cpp
	pappsomspp/processing/filters/filterresample.cpp
	pappsomspp/processing/filters/filtersuite.cpp
	pappsomspp/processing/filters/filtertandemremovec13.cpp
	pappsomspp/processing/filters/savgolfilter.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/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/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/timsbindec.cpp
	pappsomspp/vendors/tims/timsdata.cpp
	pappsomspp/vendors/tims/timsframe.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
	)

#qt5-default qtbase5-dev

#IF (UNIX)
FIND_PACKAGE( Qt5 COMPONENTS Core Gui Svg Xml PrintSupport Sql REQUIRED )
#ENDIF (UNIX)

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

#MESSAGE ("Qt5::Core ${Qt5::Core}")

# generate rules for building source files from the resources
QT5_ADD_RESOURCES(pappsomspp_RCC_SRCS ${pappsomspp_RCCS})

# generate rules for building source files that moc generates
#QT5_WRAP_CPP(QtApp_MOC_SRCS ${QtApp_MOCS})

# Build the static lib
ADD_LIBRARY(pappsomspp-static-qt5 STATIC ${CPP_FILES} ${pappsomspp_RCC_SRCS})
target_include_directories (pappsomspp-static-qt5 PUBLIC ${Qt5Core_INCLUDES} ${Qt5Gui_INCLUDES} ${Pwiz_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})

SET_TARGET_PROPERTIES(pappsomspp-static-qt5
	PROPERTIES OUTPUT_NAME pappsomspp-qt5
	CLEAN_DIRECT_OUTPUT 1
	CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS}"
	)

if (MINGW)
	TARGET_LINK_LIBRARIES(pappsomspp-static-qt5 ${Pwiz_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::Sql
        Zstd::Zstd
        ALGLIB::ALGLIB
        SQLite::SQLite3
		)
else (MINGW)
	TARGET_LINK_LIBRARIES(pappsomspp-static-qt5 ${LIBS} ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Pwiz_LIBRARY}
		${ZLIB_LIBRARIES}
		Qt5::Gui
		Qt5::Xml
		Qt5::Svg
		Qt5::PrintSupport
		Qt5::Sql
        Zstd::Zstd
        ALGLIB::ALGLIB
        SQLite::SQLite3
        )
endif (MINGW)


ADD_LIBRARY(pappsomspp-shared-qt5 SHARED ${CPP_FILES} ${pappsomspp_RCC_SRCS})
target_include_directories (pappsomspp-shared-qt5 PUBLIC ${Qt5Core_INCLUDES} ${Qt5Gui_INCLUDES} ${Pwiz_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
SET_TARGET_PROPERTIES(pappsomspp-shared-qt5
	PROPERTIES OUTPUT_NAME pappsomspp-qt5
	CLEAN_DIRECT_OUTPUT 1
	VERSION ${PAPPSOMSPP_VERSION}
	SOVERSION ${PAPPSOMSPP_VERSION_MAJOR}
	CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS}"
	)

if (MINGW)
	TARGET_LINK_LIBRARIES(pappsomspp-shared-qt5 ${Pwiz_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::Sql
        Zstd::Zstd
        ALGLIB::ALGLIB
        SQLite::SQLite3
    )
else (MINGW)
	TARGET_LINK_LIBRARIES(pappsomspp-shared-qt5 ${LIBS} ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Pwiz_LIBRARY}
		${ZLIB_LIBRARIES}
		
		Qt5::Gui
		Qt5::Xml
		Qt5::Svg
		Qt5::PrintSupport
		Qt5::Sql
        Zstd::Zstd
        ALGLIB::ALGLIB
        SQLite::SQLite3)
endif (MINGW)


# Install libs
if (MINGW)
else (MINGW)
	INSTALL(TARGETS pappsomspp-shared-qt5 LIBRARY DESTINATION lib${LIB_SUFFIX})
endif (MINGW)
INSTALL(TARGETS pappsomspp-static-qt5 DESTINATION lib${LIB_SUFFIX})


# Install headers
INSTALL(DIRECTORY pappsomspp/ DESTINATION include/pappsomspp FILES_MATCHING PATTERN "*.h")

IF (CMAKE_SYSTEM_NAME MATCHES "Windows")
	add_subdirectory("testwin64")
ENDIF(CMAKE_SYSTEM_NAME MATCHES "Windows")


#IF(NOT PAPPSOMSPPWIDGET)
ADD_SUBDIRECTORY("pappsomspp/widget")
#ENDIF(NOT PAPPSOMSPPWIDGET)
