forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathTesting.cmake
More file actions
83 lines (73 loc) · 2.63 KB
/
Copy pathTesting.cmake
File metadata and controls
83 lines (73 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# =============================================================================
# Setup unit-test dependencies and the AddTest helper
# ==============================================================================
# include_guard(GLOBAL)
# --- Helper Macro: Ensure a minimum C++ standard version ---
macro(set_if_higher VARIABLE VALUE)
if(${VARIABLE} LESS ${VALUE})
set(${VARIABLE} ${VALUE})
endif()
endmacro()
# Add performance test in abacus
# Benchmarks are test targets; do not make them implicitly enable the full
# unit-test tree for ordinary builds.
if(BUILD_TESTING AND ENABLE_GOOGLEBENCH)
find_package(benchmark HINTS ${BENCHMARK_DIR})
if(NOT ${benchmark_FOUND})
set(BENCHMARK_USE_BUNDLED_GTEST OFF)
include(FetchContent)
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG "origin/main"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)
set(BENCHMARK_ENABLE_TESTING OFF)
FetchContent_MakeAvailable(benchmark)
endif()
endif()
function(AddTest) # function for UT
cmake_parse_arguments(UT "DYN" "TARGET"
"LIBS;DYN_LIBS;STATIC_LIBS;SOURCES;DEPENDS" ${ARGN})
add_executable(${UT_TARGET} ${UT_SOURCES})
if(ENABLE_COVERAGE)
add_coverage(${UT_TARGET})
endif()
# Dependencies & link library
# Share the numerical/MPI/OpenMP runtime closure but not
# the optional feature closure of the final binary
target_link_libraries(${UT_TARGET} PRIVATE
${UT_LIBS}
GTest::gtest_main
GTest::gmock_main
abacus::linalg_libs)
if(BUILD_TESTING AND ENABLE_GOOGLEBENCH)
target_link_libraries(
${UT_TARGET} PRIVATE benchmark::benchmark)
endif()
# Link to build info if needed
if("${UT_SOURCES}" MATCHES "parse_args.cpp")
target_include_directories(${UT_TARGET} PUBLIC ${CMAKE_BINARY_DIR}/source/source_io)
endif()
install(TARGETS ${UT_TARGET} DESTINATION ${CMAKE_BINARY_DIR}/tests)
add_test(
NAME ${UT_TARGET}
COMMAND ${UT_TARGET}
WORKING_DIRECTORY $<TARGET_FILE_DIR:${UT_TARGET}>)
endfunction(AddTest)
if(BUILD_TESTING)
set_if_higher(CMAKE_CXX_STANDARD 14) # Required in orbital
find_package(GTest HINTS /usr/local/lib/ ${GTEST_DIR})
if(NOT ${GTest_FOUND})
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG "origin/main"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)
FetchContent_MakeAvailable(googletest)
endif()
# Integration tests are registered from source/CMakeLists.txt after the
# final executable has been created.
endif()