From 997871c0e5e7dbeb8ca43b8f46b85a61796698c7 Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Sat, 11 Jul 2020 17:52:13 +0200 Subject: [PATCH] [CMakeLists.txt] Added option to disable building tests. --- .travis.yml | 2 ++ CMakeLists.txt | 32 ++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0ed38c48e..5a77c0aa6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,12 +23,14 @@ addons: - libxi-dev - g++-8 - cmake + - cxxtest script: - mkdir build - cd build - cmake .. - make -j8 + - ./openminer_tests notifications: email: false diff --git a/CMakeLists.txt b/CMakeLists.txt index 337e81797..20b70f48a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,8 @@ endif () set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +set(OM_BUILD_TESTS ON CACHE BOOL "Enable building tests if CxxTest is available") + include_directories(external) #------------------------------------------------------------------------------ @@ -131,22 +133,24 @@ add_subdirectory(source/client) #------------------------------------------------------------------------------ # Unit testing #------------------------------------------------------------------------------ -find_package(CxxTest QUIET) +if(OM_BUILD_TESTS) + find_package(CxxTest QUIET) -if(CXXTEST_FOUND) - include_directories(${CXXTEST_INCLUDE_DIRS}) - enable_testing() + if(CXXTEST_FOUND) + include_directories(${CXXTEST_INCLUDE_DIRS}) + enable_testing() - file(GLOB_RECURSE HEADER_FILES source/*.hpp) - foreach(HEADER_FILE ${HEADER_FILES}) - get_filename_component(HEADER_DIRECTORY ${HEADER_FILE} DIRECTORY) - include_directories(${HEADER_DIRECTORY}) - endforeach(HEADER_FILE) + file(GLOB_RECURSE HEADER_FILES source/*.hpp) + foreach(HEADER_FILE ${HEADER_FILES}) + get_filename_component(HEADER_DIRECTORY ${HEADER_FILE} DIRECTORY) + include_directories(${HEADER_DIRECTORY}) + endforeach(HEADER_FILE) - file(GLOB_RECURSE TEST_FILES tests/*.hpp) - CXXTEST_ADD_TEST(${CMAKE_PROJECT_NAME}_tests unit-test.cpp ${TEST_FILES}) - target_link_libraries(${CMAKE_PROJECT_NAME}_tests ${CMAKE_PROJECT_NAME}_common ${CMAKE_PROJECT_NAME}_server_lib) -else() - message(WARNING "CxxTest not found!") + file(GLOB_RECURSE TEST_FILES tests/*.hpp) + CXXTEST_ADD_TEST(${CMAKE_PROJECT_NAME}_tests unit-test.cpp ${TEST_FILES}) + target_link_libraries(${CMAKE_PROJECT_NAME}_tests ${CMAKE_PROJECT_NAME}_common ${CMAKE_PROJECT_NAME}_server_lib) + else() + message(WARNING "CxxTest not found!") + endif() endif()