diff --git a/.gitignore b/.gitignore index c3be379d..94f66b35 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,10 @@ doc/html/* /COPYING.txt /build/ +# CTest-generated files +/CTestTestfile.cmake +/Testing/ + # Mac ._DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt index 918479a8..67c4a9d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,21 +197,57 @@ OPTION( IF(VMIME_BUILD_TESTS) + ENABLE_TESTING() + + INCLUDE(cmake/FindCppUnit.cmake) + INCLUDE_DIRECTORIES(${CPPUNIT_INCLUDE_DIR}) + FILE( GLOB_RECURSE VMIME_TESTS_SRC_FILES - tests/*Test.cpp tests/testRunner.cpp tests/testUtils.cpp + ${CMAKE_SOURCE_DIR}/tests/*Test.cpp ) + # Build one file for each test + FOREACH(VMIME_TEST_SRC_FILE ${VMIME_TESTS_SRC_FILES}) + + # "/path/to/vmime/tests/module/testFile.cpp" --> "module_testFile" + GET_FILENAME_COMPONENT(VMIME_TEST_SRC_PATH "${VMIME_TEST_SRC_FILE}" PATH) + STRING(REPLACE "${CMAKE_SOURCE_DIR}" "" VMIME_TEST_SRC_PATH "${VMIME_TEST_SRC_PATH}") + GET_FILENAME_COMPONENT(VMIME_TEST_NAME "${VMIME_TEST_SRC_FILE}" NAME_WE) + SET(VMIME_TEST_NAME "${VMIME_TEST_SRC_PATH}/${VMIME_TEST_NAME}") + STRING(REPLACE "/" "_" VMIME_TEST_NAME "${VMIME_TEST_NAME}") + STRING(REPLACE "_tests_" "" VMIME_TEST_NAME "${VMIME_TEST_NAME}") + + ADD_EXECUTABLE( + ${VMIME_TEST_NAME} + ${VMIME_TEST_SRC_FILE} ${CMAKE_SOURCE_DIR}/tests/testRunner.cpp ${CMAKE_SOURCE_DIR}/tests/testUtils.cpp + ) + + TARGET_LINK_LIBRARIES( + ${VMIME_TEST_NAME} + ${VMIME_LIBRARY_NAME} + ${CPPUNIT_LIBRARY} + ) + + ADD_DEPENDENCIES( + ${VMIME_TEST_NAME} + ${VMIME_LIBRARY_NAME} + ) + + ADD_TEST( + ${VMIME_TEST_NAME} + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${VMIME_TEST_NAME} + ) + + ENDFOREACH() + + # Build one file for all tests ADD_EXECUTABLE( "run-tests" - ${VMIME_TESTS_SRC_FILES} + ${VMIME_TESTS_SRC_FILES} ${CMAKE_SOURCE_DIR}/tests/testRunner.cpp ${CMAKE_SOURCE_DIR}/tests/testUtils.cpp ) - INCLUDE(cmake/FindCppUnit.cmake) - - INCLUDE_DIRECTORIES(${CPPUNIT_INCLUDE_DIR}) - TARGET_LINK_LIBRARIES( "run-tests" ${VMIME_LIBRARY_NAME}