find_package(Qt4 COMPONENTS QtTest REQUIRED)

enable_testing()
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})

if(NOT BUILD_TESTS)
  set(_add_executable_param EXCLUDE_FROM_ALL)
endif(NOT BUILD_TESTS)

set(test_SRCS
  opensslexceptiontest.cpp
  signingexceptiontest.cpp
  extensiontest.cpp
  keytest.cpp
  requesttest.cpp
  commontest.cpp
  certificatetest.cpp
 )

FOREACH(it ${test_SRCS})
  GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
  GET_FILENAME_COMPONENT(test ${it} NAME_WE)
  qt4_make_output_file(${it} "" moc outfile)
  qt4_generate_moc(${it} ${outfile})
  add_executable(${test} ${_add_executable_param} ${it} ${outfile})
  add_test(${test} ${CMAKE_CURRENT_BINARY_DIR}/${test})
  target_link_libraries(${test}
    kca_ossl-2
    ${QT_QTCORE_LIBRARY}
    ${QT_QTNETWORK_LIBRARY}
    ${QT_QTTEST_LIBRARY}
   )

  set(all_tests ${all_tests} ${test})
ENDFOREACH(it)

add_custom_target(all_tests DEPENDS ${all_tests})
