# CMake script for PAPPSOms++ library
# Author: Olivier Langella
# Created: 03/03/2015 from the CMakeLists file of the Bio++ project


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

#apt-get install libpwiz-dev libboost-dev
#CTEST_OUTPUT_ON_FAILURE=TRUE make test
#make test ARGS="-V"
#make test ARGS="-V -I 4,4"

#export LD_LIBRARY_PATH=/home/langella/developpement/git/pappsomspp/build/src:$LD_LIBRARY_PATH

#set(CMAKE_MODULE_PATH "/usr/share/cmake-3.0/Modules")

if(OdsStream_FOUND)
else (OdsStream_FOUND)
	find_package(OdsStream REQUIRED)
endif(OdsStream_FOUND)

if(TARGET OdsStream::Core)
	message("OdsStream::Core found.")
else (TARGET OdsStream::Core)
	message("OdsStream::Core not found.")
endif (TARGET OdsStream::Core)

macro(TEST_FIND_LIBRARY OUTPUT_LIBS lib_name include_to_find)
	#start:
	find_path("${CMAKE_SOURCE_DIR}/src" ${include_to_find})

	set(${lib_name}_NAMES ${lib_name} ${lib_name}.lib ${lib_name}.dll)

	find_library(${lib_name}_LIBRARY NAMES ${${lib_name}_NAMES})

	if(${lib_name}_LIBRARY)

		message("-- Library ${lib_name} found here:")
		message("   includes: ${${lib_name}_INCLUDE_DIR}")
		message("   dynamic libraries: ${${lib_name}_LIBRARY}")
		message(WARNING "Library ${lib_name} is already installed in the system tree. Test will be built against it. This may lead to unexpected results. You may want to do 'make install' before 'make test', or remove the installed version.")

	else()

		set(PappsoMSpp_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/src")
		set(PappsoMSpp_LIBRARY "${CMAKE_BINARY_DIR}/src/libpappsomspp-qt5.so")
		set(PappsoMSppWidget_LIBRARY "${CMAKE_BINARY_DIR}/src/pappsomspp/widget/libpappsomspp-widget-qt5.so")

		message("${PappsoMSpp_INCLUDE_DIR}")
		message("${PappsoMSpp_LIBRARY}")
		message("${PappsoMSppWidget_LIBRARY}")

	endif()

	set(${OUTPUT_LIBS} ${${OUTPUT_LIBS}} ${${lib_name}_LIBRARY})

endmacro(TEST_FIND_LIBRARY)



# File list
set(CPP_TEST_FILES
	saxparsers/xtandemresultshandler.cpp
	)

#Find the bpp-core library library:
test_find_library(LIBS pappsomspp-qt5 pappsomspp/types.h 
	pappsomspp/peptide/peptidenaturalisotopelist.h)

find_package(Qt5 COMPONENTS Core Xml Gui Concurrent REQUIRED)


include_directories("${CMAKE_SOURCE_DIR}/src")

add_executable(test_fasta_reader test_fasta_reader.cpp)
target_link_libraries(test_fasta_reader Qt5::Core pappsomspp-shared)
add_test(test_fasta_reader "test_fasta_reader")


add_executable(test_protein test_protein.cpp)
target_link_libraries(test_protein Qt5::Core pappsomspp-shared)
add_test(test_protein "test_protein")

add_executable(test_xic test_xic.cpp)
target_link_libraries(test_xic Qt5::Core pappsomspp-shared Qt5::Gui OdsStream::Core)
add_test(test_xic "test_xic")


add_executable(test_massrange test_massrange.cpp)
target_link_libraries(test_massrange Qt5::Core pappsomspp-shared)
add_test(test_massrange "test_massrange")

add_executable(test_aa test_aa.cpp)
target_link_libraries(test_aa Qt5::Core pappsomspp-shared)
add_test(test_aa "test_aa")

add_executable(test_peptide test_peptide.cpp)
target_link_libraries(test_peptide Qt5::Core Qt5::Gui pappsomspp-shared)
add_test(test_peptide "test_peptide")

add_executable(test_peptidenaturalisotopelist test_peptidenaturalisotopelist.cpp)
target_link_libraries(test_peptidenaturalisotopelist Qt5::Core Qt5::Gui pappsomspp-shared)
add_test(test_peptidenaturalisotopelist "test_peptidenaturalisotopelist")


add_executable(test_natural_isotope_average test_natural_isotope_average.cpp)
target_link_libraries(test_natural_isotope_average Qt5::Core pappsomspp-shared)
add_test(test_natural_isotope_average "test_natural_isotope_average")


add_executable(test_peptidefragment test_peptidefragment.cpp)
target_link_libraries(test_peptidefragment Qt5::Core Qt5::Gui pappsomspp-shared)
add_test(test_peptidefragment "test_peptidefragment")

add_executable(test_fragmentationcid test_fragmentationcid.cpp)
target_link_libraries(test_fragmentationcid Qt5::Core Qt5::Gui pappsomspp-shared)
add_test(test_fragmentationcid "test_fragmentationcid")

#IF (FALSE) 
add_executable(test_big_hyperscore test_big_hyperscore.cpp ${CPP_TEST_FILES})
target_link_libraries(test_big_hyperscore Qt5::Core Qt5::Gui Qt5::Xml pappsomspp-shared)
add_test(test_big_hyperscore "test_big_hyperscore")
#ENDIF(FALSE)


add_executable(test_rawmasslist test_rawmasslist.cpp)
target_link_libraries(test_rawmasslist Qt5::Core Qt5::Gui pappsomspp-shared)
add_test(test_rawmasslist "test_rawmasslist")


add_executable(test_isotope_with_spectrum test_isotope_with_spectrum.cpp)
target_link_libraries(test_isotope_with_spectrum Qt5::Core Qt5::Gui pappsomspp-shared  ${Boost_LIBRARIES})
add_test(test_isotope_with_spectrum "test_isotope_with_spectrum")
set(TEST_LIST ${TEST_LIST} test_isotope_with_spectrum)

add_executable(test_hyperscore test_hyperscore.cpp)
target_link_libraries(test_hyperscore Qt5::Core pappsomspp-shared Qt5::Gui  ${Boost_LIBRARIES})
add_test(test_hyperscore "test_hyperscore")
set(TEST_LIST ${TEST_LIST} test_hyperscore)

add_executable(test_xtandem_spectrum test_xtandem_spectrum.cpp)
target_link_libraries(test_xtandem_spectrum Qt5::Core pappsomspp-shared Qt5::Gui  ${Boost_LIBRARIES})
add_test(test_xtandem_spectrum "test_xtandem_spectrum")
set(TEST_LIST ${TEST_LIST} test_xtandem_spectrum)

add_executable(test_scan_15968 test_scan_15968.cpp)
target_link_libraries(test_scan_15968 Qt5::Core Qt5::Gui pappsomspp-shared  ${Boost_LIBRARIES})
add_test(test_scan_15968 "test_scan_15968")
set(TEST_LIST ${TEST_LIST} test_scan_15968)

add_executable(test_psm test_psm.cpp)
target_link_libraries(test_psm Qt5::Core pappsomspp-shared Qt5::Gui Qt5::Concurrent  ${Boost_LIBRARIES})
add_test(test_psm "test_psm")
set(TEST_LIST ${TEST_LIST} test_psm)

add_executable(test_xicextractor test_xicextractor.cpp)
target_link_libraries(test_xicextractor Qt5::Core Qt5::Gui pappsomspp-shared  ${Boost_LIBRARIES} OdsStream::Core)
add_test(test_xicextractor "test_xicextractor")
set(TEST_LIST ${TEST_LIST} test_xicextractor)

add_executable(test_trace_filters test_trace_filters.cpp)
target_link_libraries(test_trace_filters Qt5::Core Qt5::Gui Qt5::Concurrent pappsomspp-shared  ${Boost_LIBRARIES})
add_test(test_trace_filters "test_trace_filters")
set(TEST_LIST ${TEST_LIST} test_trace_filters)


add_executable(test_msrunalignment test_msrunalignment.cpp)
target_include_directories (test_msrunalignment PUBLIC ${QUAZIP_INCLUDE_DIR})
target_link_libraries(test_msrunalignment Qt5::Core Qt5::Gui Qt5::Concurrent pappsomspp-shared  ${Boost_LIBRARIES} OdsStream::Core)
add_test(test_msrunalignment "test_msrunalignment")
set(TEST_LIST ${TEST_LIST} test_msrunalignment)

add_executable(test_msrunoutput test_msrunoutput.cpp)
target_link_libraries(test_msrunoutput Qt5::Core Qt5::Gui Qt5::Concurrent pappsomspp-shared  ${Boost_LIBRARIES} OdsStream::Core)
add_test(test_msrunoutput "test_msrunoutput")
set(TEST_LIST ${TEST_LIST} test_msrunoutput)


add_executable(test_timsframe test_timsframe.cpp)
target_link_libraries(test_timsframe Qt5::Core pappsomspp-shared )
add_test(test_timsframe "test_timsframe")


if(UNIX)

	set_property(TEST  test_big_hyperscore test_xic test_protein test_fasta_reader 
		test_massrange test_aa test_peptide test_peptidenaturalisotopelist test_peptidefragment 
		test_fragmentationcid ${TEST_LIST} test_natural_isotope_average test_rawmasslist 
		test_timsframe 
		PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:../src")

endif()

if(WIN32)
	set(ENV{PATH} "$ENV{PATH};..\\src")
endif()
