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

#CTEST_OUTPUT_ON_FAILURE=TRUE make test
#make test ARGS="-V"

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

MACRO(TEST_FIND_LIBRARY OUTPUT_LIBS lib_name include_to_find)
  #start:
  FIND_PATH(${lib_name}_INCLUDE_DIR ${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()
  
    SET(${lib_name}_LIBRARY "-L../src -l${lib_name}")
    SET(${lib_name}_INCLUDE_DIR "../src/")
  INCLUDE_DIRECTORIES(${${lib_name}_INCLUDE_DIR})
  SET(${OUTPUT_LIBS} ${${OUTPUT_LIBS}} ${${lib_name}_LIBRARY})
ENDMACRO(TEST_FIND_LIBRARY)


# File list
SET(CPP_TEST_FILES
  
  )
  
  #Find the bpp-core library library:
  TEST_FIND_LIBRARY(LIBS odsstream-qt5 odsstream/odsdocreader.h)

  FIND_PACKAGE( Qt5Core REQUIRED )
  FIND_PACKAGE( Qt5Xml REQUIRED )
  FIND_PACKAGE( Qt5Gui REQUIRED )
  INCLUDE_DIRECTORIES(${Qt5Core_INCLUDES} ${Qt5Xml_INCLUDES} ${Qt5Gui_INCLUDES} ${QUAZIP_INCLUDE_DIR})
  SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} ${Qt5Xml_EXECUTABLE_COMPILE_FLAGS} ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS}")
 
  set(QTLIBS ${Qt5Core_LIBRARIES} ${Qt5Xml_LIBRARIES} ${Qt5Gui_LIBRARIES})

ADD_EXECUTABLE(test_ods test_ods.cpp)
MESSAGE ("library: ${LIBS}")
TARGET_LINK_LIBRARIES(test_ods ${LIBS} ${QTLIBS} ${QUAZIP_QT5_LIBRARIES})
ADD_TEST(test_ods "test_ods")


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



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


IF(UNIX)
  SET_PROPERTY(TEST test_ods test_tsv test_zlib ${TEST_LIST} PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:../src")
ENDIF()

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

