From e285cd034b5432e5ca60578e615daf2a9b2198b6 Mon Sep 17 00:00:00 2001 From: apprb Date: Wed, 19 Aug 2015 00:58:07 +0600 Subject: [PATCH] CMake: tests support --- build/CMakeLists.txt | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 875c745b..997c3d50 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -7,8 +7,9 @@ option(WITH_HARDENING "Use hardening compiler flags" OFF) option(WITH_LIBRARY "Build library" ON) option(WITH_BINARY "Build binary" ON) option(WITH_STATIC "Static build" OFF) -option(WITH_UPNP "Include support for UPnP client" OFF) -option(WITH_PCH "Use precompiled header" OFF) +option(WITH_UPNP "Include support for UPnP client" OFF) +option(WITH_PCH "Use precompiled header" OFF) +option(WITH_TESTS "Build unit tests" OFF) # paths set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ) @@ -70,6 +71,13 @@ set (DAEMON_SRC "${CMAKE_SOURCE_DIR}/i2p.cpp" ) +set (TESTS_SRC + "${CMAKE_SOURCE_DIR}/tests/Base64.cpp" + "${CMAKE_SOURCE_DIR}/tests/Crypto.cpp" + "${CMAKE_SOURCE_DIR}/tests/Identity.cpp" + "${CMAKE_SOURCE_DIR}/tests/Utility.cpp" +) + if (WITH_UPNP) add_definitions(-DUSE_UPNP) if (NOT MSVC) @@ -242,6 +250,7 @@ message(STATUS " BINARY : ${WITH_BINARY}") message(STATUS " STATIC BUILD : ${WITH_STATIC}") message(STATUS " UPnP : ${WITH_UPNP}") message(STATUS " PCH : ${WITH_PCH}") +message(STATUS " TESTS : ${WITH_TESTS}") message(STATUS "---------------------------------------") #Handle paths nicely @@ -299,3 +308,13 @@ if (WITH_LIBRARY) endif() install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif () + +if (WITH_TESTS) + find_package ( Boost COMPONENTS system filesystem regex program_options date_time thread chrono unit_test_framework REQUIRED ) + + add_executable(i2pd_tests ${TESTS_SRC}) + target_link_libraries(i2pd_tests common ${DL_LIB} ${Boost_LIBRARIES} ${CRYPTO++_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) + + enable_testing() + add_test(i2pdTest i2pd_tests) +endif () \ No newline at end of file