Skip to content

Commit

Permalink
[CMakeLists.txt] Added option to disable building tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Jul 12, 2020
1 parent bf793e9 commit 5db8341
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ addons:
- libxi-dev
- g++-8
- cmake
- cxxtest

script:
- mkdir build
- cd build
- cmake ..
- make -j8
# - ./openminer_tests

notifications:
email: false
Expand Down
32 changes: 18 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ endif ()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

option(OM_BUILD_TESTS ON "Enable building tests if CxxTest is available")

include_directories(external)

#------------------------------------------------------------------------------
Expand Down Expand Up @@ -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()

0 comments on commit 5db8341

Please sign in to comment.