|
1 # Transitional support for CTest written tests |
1 message(CHECK_START "Searching for CUnit test framework") |
2 message(CHECK_START "Searching for CUnit test framework") |
2 |
3 |
3 find_path(CUNIT_INCLUDE_DIR NAMES CUnit/CUnit.h) |
4 find_path(CUNIT_INCLUDE_DIR NAMES CUnit/CUnit.h) |
4 find_library(CUNIT_LIBRARY NAMES cunit libcunit cunitlib) |
5 find_library(CUNIT_LIBRARY NAMES cunit libcunit cunitlib) |
5 include(FindPackageHandleStandardArgs) |
6 include(FindPackageHandleStandardArgs) |
6 find_package_handle_standard_args(CUnit DEFAULT_MSG CUNIT_LIBRARY CUNIT_INCLUDE_DIR) |
7 find_package_handle_standard_args(CUnit DEFAULT_MSG CUNIT_LIBRARY CUNIT_INCLUDE_DIR) |
7 |
8 |
8 if(CUNIT_FOUND) |
9 if (CUNIT_FOUND) |
9 message(CHECK_PASS "found: compiling tests.") |
10 message(CHECK_PASS "found: compiling tests.") |
10 set(TESTS |
11 set(TESTS |
11 test_allocator |
12 test_allocator |
12 test_list |
13 test_list |
13 test_tree |
14 test_tree |
14 ) |
15 ) |
15 |
16 |
16 foreach(test ${TESTS}) |
17 foreach (test ${TESTS}) |
17 add_executable(${test} util_allocator.c ${test}.c) |
18 add_executable(${test} ${test}.c) |
18 target_link_libraries(${test} PRIVATE ucx_static ${CUNIT_LIBRARY}) |
19 target_link_libraries(${test} PRIVATE ucx_static ${CUNIT_LIBRARY}) |
19 target_include_directories(${test} PRIVATE ${CUNIT_INCLUDE_DIR}) |
20 target_include_directories(${test} PRIVATE ${CUNIT_INCLUDE_DIR}) |
20 add_test(NAME ${test} COMMAND ${test} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") |
21 add_test(NAME ${test} COMMAND ${test} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") |
21 endforeach() |
22 endforeach () |
22 else() |
23 else () |
23 message(CHECK_FAIL "not found: unit tests will not be available.") |
24 message(CHECK_FAIL "not found: CUnit tests will not be available.") |
24 endif() |
25 endif () |
|
26 |
|
27 # Load Google Test Framework |
|
28 set(CMAKE_CXX_STANDARD 11) |
|
29 |
|
30 include(FetchContent) |
|
31 FetchContent_Declare( |
|
32 googletest |
|
33 GIT_REPOSITORY https://github.com/google/googletest.git |
|
34 GIT_TAG e2239ee6043f73722e7aa812a459f54a28552929 # release 1.11.0 |
|
35 ) |
|
36 # For Windows: Prevent overriding the parent project's compiler/linker settings |
|
37 set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
|
38 FetchContent_MakeAvailable(googletest) |
|
39 include(GoogleTest) |
|
40 message(STATUS "Google Test made available") |
|
41 |
|
42 set(TESTS |
|
43 selftest |
|
44 ) |
|
45 foreach (test ${TESTS}) |
|
46 add_executable(${test} ${test}.cpp) |
|
47 target_link_libraries(${test} PRIVATE ucx_static gtest_main) |
|
48 endforeach () |
|
49 gtest_discover_tests(${TESTS}) |