# 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
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules)
FIND_PACKAGE(Pwiz)
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)
#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")
FIND_PACKAGE( Odsstream REQUIRED )
INCLUDE_DIRECTORIES(${ODSSTREAM_INCLUDE_DIR})



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()
    MESSAGE("${lib_name}_LIBRARY -L../src -l${lib_name}")
    MESSAGE("${lib_name}_INCLUDE_DIR ../src/")
    MESSAGE("${LIBS}")
    SET(${lib_name}_LIBRARY "-L../src -l${lib_name}")
    SET(${lib_name}_INCLUDE_DIR "../src/")
  ENDIF()
  INCLUDE_DIRECTORIES(${${lib_name}_INCLUDE_DIR})
  SET(${OUTPUT_LIBS} ${${OUTPUT_LIBS}} ${${lib_name}_LIBRARY})
ENDMACRO(TEST_FIND_LIBRARY)



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

IF (USEQT5)
  IF (USEQT4)
     SET (USEQT5 1)
     SET (USEQT4 0)
  ENDIF(USEQT4)
ENDIF(USEQT5)

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

  FIND_PACKAGE( Qt5Core REQUIRED )
  FIND_PACKAGE( Qt5Xml REQUIRED )
  FIND_PACKAGE( Qt5Gui REQUIRED )
  INCLUDE_DIRECTORIES(${Qt5Core_INCLUDES} ${Qt5Xml_INCLUDES} ${Qt5Gui_INCLUDES})
  SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
 
  set(QTLIBS ${Qt5Core_LIBRARIES} ${Qt5Xml_LIBRARIES} ${Qt5Gui_LIBRARIES})
  set(ODSLIBS ${ODSSTREAM_QT5_LIBRARY})
 
ENDIF(USEQT5)

IF (USEQT4)
  #Find the bpp-core library library:
  TEST_FIND_LIBRARY(LIBS pappsomspp-qt4 pappsomspp/types.h pappsomspp/peptide/peptidenaturalisotopelist.h)

  FIND_PACKAGE( Qt4 COMPONENTS QTCORE QTXML QTGUI REQUIRED )
  
  INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTXML_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR})
  set(QTLIBS "${LIBS} ${QT_QTCORE_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTGUI_LIBRARY}")
  
  set(ODSLIBS ${ODSSTREAM_QT4_LIBRARY})
ENDIF(USEQT4)


message("qtlibs used for tests :  ${QTLIBS}")
  
   MESSAGE ("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}")
  MESSAGE ("LIBS ${LIBS}")


ADD_EXECUTABLE(test_fasta_reader test_fasta_reader.cpp)
TARGET_LINK_LIBRARIES(test_fasta_reader ${LIBS} ${QTLIBS})
ADD_TEST(test_fasta_reader "test_fasta_reader")


ADD_EXECUTABLE(test_protein test_protein.cpp)
TARGET_LINK_LIBRARIES(test_protein ${LIBS} ${QTLIBS})
ADD_TEST(test_protein "test_protein")

ADD_EXECUTABLE(test_xic test_xic.cpp)
TARGET_LINK_LIBRARIES(test_xic ${LIBS} ${QTLIBS} ${ODSLIBS})
ADD_TEST(test_xic "test_xic")


ADD_EXECUTABLE(test_massrange test_massrange.cpp)
TARGET_LINK_LIBRARIES(test_massrange ${LIBS} ${QTLIBS})
ADD_TEST(test_massrange "test_massrange")

ADD_EXECUTABLE(test_aa test_aa.cpp)
TARGET_LINK_LIBRARIES(test_aa ${LIBS} ${QTLIBS})
ADD_TEST(test_aa "test_aa")

ADD_EXECUTABLE(test_peptide test_peptide.cpp)
TARGET_LINK_LIBRARIES(test_peptide ${LIBS} ${QTLIBS})
ADD_TEST(test_peptide "test_peptide")

ADD_EXECUTABLE(test_peptidenaturalisotopelist test_peptidenaturalisotopelist.cpp)
TARGET_LINK_LIBRARIES(test_peptidenaturalisotopelist ${LIBS} ${QTLIBS})
ADD_TEST(test_peptidenaturalisotopelist "test_peptidenaturalisotopelist")


ADD_EXECUTABLE(test_natural_isotope_average test_natural_isotope_average.cpp)
TARGET_LINK_LIBRARIES(test_natural_isotope_average ${LIBS} ${QTLIBS})
ADD_TEST(test_natural_isotope_average "test_natural_isotope_average")


ADD_EXECUTABLE(test_peptidefragment test_peptidefragment.cpp)
TARGET_LINK_LIBRARIES(test_peptidefragment ${LIBS} ${QTLIBS})
ADD_TEST(test_peptidefragment "test_peptidefragment")

ADD_EXECUTABLE(test_fragmentationcid test_fragmentationcid.cpp)
TARGET_LINK_LIBRARIES(test_fragmentationcid ${LIBS} ${QTLIBS})
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 ${LIBS} ${QTLIBS})
ADD_TEST(test_big_hyperscore "test_big_hyperscore")
#ENDIF(FALSE)


ADD_EXECUTABLE(test_rawmasslist test_rawmasslist.cpp)
TARGET_LINK_LIBRARIES(test_rawmasslist ${LIBS} ${QTLIBS})
ADD_TEST(test_rawmasslist "test_rawmasslist")

IF (Pwiz_FOUND)

  ADD_EXECUTABLE(test_isotope_with_spectrum test_isotope_with_spectrum.cpp)
  TARGET_LINK_LIBRARIES(test_isotope_with_spectrum ${LIBS}  ${QTLIBS} ${Pwiz_LIBRARY} ${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 ${LIBS} ${QTLIBS} ${Pwiz_LIBRARY} ${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 ${LIBS} ${QTLIBS} ${Pwiz_LIBRARY} ${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 ${LIBS} ${QTLIBS} ${Pwiz_LIBRARY} ${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 ${LIBS} ${QTLIBS} ${Pwiz_LIBRARY} ${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 ${LIBS} ${QTLIBS} ${Pwiz_LIBRARY} ${Boost_LIBRARIES})
  ADD_TEST(test_xicextractor "test_xicextractor")
  SET(TEST_LIST ${TEST_LIST} test_xicextractor)

ENDIF(Pwiz_FOUND)

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 PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:../src")
ENDIF()

IF(WIN32)
  SET(ENV{PATH} "$ENV{PATH};..\\src")
ENDIF()
