3 find_package(Threads REQUIRED)
5 # NOTE: These flags must be added after find_package(Threads REQUIRED) otherwise
6 # they will break the configuration check.
7 if (DEFINED BENCHMARK_CXX_LINKER_FLAGS)
8 list(APPEND CMAKE_EXE_LINKER_FLAGS ${BENCHMARK_CXX_LINKER_FLAGS})
11 add_library(output_test_helper STATIC output_test_helper.cc)
13 macro(compile_benchmark_test name)
14 add_executable(${name} "${name}.cc")
15 target_link_libraries(${name} benchmark ${CMAKE_THREAD_LIBS_INIT})
16 endmacro(compile_benchmark_test)
19 macro(compile_output_test name)
20 add_executable(${name} "${name}.cc" output_test.h)
21 target_link_libraries(${name} output_test_helper benchmark
22 ${BENCHMARK_CXX_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
23 endmacro(compile_output_test)
26 # Demonstration executable
27 compile_benchmark_test(benchmark_test)
28 add_test(benchmark benchmark_test --benchmark_min_time=0.01)
30 compile_benchmark_test(filter_test)
31 macro(add_filter_test name filter expect)
32 add_test(${name} filter_test --benchmark_min_time=0.01 --benchmark_filter=${filter} ${expect})
33 add_test(${name}_list_only filter_test --benchmark_list_tests --benchmark_filter=${filter} ${expect})
34 endmacro(add_filter_test)
36 add_filter_test(filter_simple "Foo" 3)
37 add_filter_test(filter_suffix "BM_.*" 4)
38 add_filter_test(filter_regex_all ".*" 5)
39 add_filter_test(filter_regex_blank "" 5)
40 add_filter_test(filter_regex_none "monkey" 0)
41 add_filter_test(filter_regex_wildcard ".*Foo.*" 3)
42 add_filter_test(filter_regex_begin "^BM_.*" 4)
43 add_filter_test(filter_regex_begin2 "^N" 1)
44 add_filter_test(filter_regex_end ".*Ba$" 1)
46 compile_benchmark_test(options_test)
47 add_test(options_benchmarks options_test --benchmark_min_time=0.01)
49 compile_benchmark_test(basic_test)
50 add_test(basic_benchmark basic_test --benchmark_min_time=0.01)
52 compile_benchmark_test(diagnostics_test)
53 add_test(diagnostics_test diagnostics_test --benchmark_min_time=0.01)
55 compile_benchmark_test(skip_with_error_test)
56 add_test(skip_with_error_test skip_with_error_test --benchmark_min_time=0.01)
58 compile_benchmark_test(donotoptimize_test)
59 add_test(donotoptimize_test donotoptimize_test --benchmark_min_time=0.01)
61 compile_benchmark_test(fixture_test)
62 add_test(fixture_test fixture_test --benchmark_min_time=0.01)
64 compile_benchmark_test(register_benchmark_test)
65 add_test(register_benchmark_test register_benchmark_test --benchmark_min_time=0.01)
67 compile_benchmark_test(map_test)
68 add_test(map_test map_test --benchmark_min_time=0.01)
70 compile_benchmark_test(multiple_ranges_test)
71 add_test(multiple_ranges_test multiple_ranges_test --benchmark_min_time=0.01)
73 compile_output_test(reporter_output_test)
74 add_test(reporter_output_test reporter_output_test --benchmark_min_time=0.01)
76 check_cxx_compiler_flag(-std=c++03 BENCHMARK_HAS_CXX03_FLAG)
77 if (BENCHMARK_HAS_CXX03_FLAG)
78 set(CXX03_FLAGS "${CMAKE_CXX_FLAGS}")
79 string(REPLACE "-std=c++11" "-std=c++03" CXX03_FLAGS "${CXX03_FLAGS}")
80 string(REPLACE "-std=c++0x" "-std=c++03" CXX03_FLAGS "${CXX03_FLAGS}")
82 compile_benchmark_test(cxx03_test)
83 set_target_properties(cxx03_test
84 PROPERTIES COMPILE_FLAGS "${CXX03_FLAGS}")
85 add_test(cxx03 cxx03_test --benchmark_min_time=0.01)
88 # Attempt to work around flaky test failures when running on Appveyor servers.
89 if (DEFINED ENV{APPVEYOR})
90 set(COMPLEXITY_MIN_TIME "0.5")
92 set(COMPLEXITY_MIN_TIME "0.01")
94 compile_output_test(complexity_test)
95 add_test(complexity_benchmark complexity_test --benchmark_min_time=${COMPLEXITY_MIN_TIME})
97 # Add the coverage command(s)
99 string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
101 if (${CMAKE_BUILD_TYPE_LOWER} MATCHES "coverage")
102 find_program(GCOV gcov)
103 find_program(LCOV lcov)
104 find_program(GENHTML genhtml)
105 find_program(CTEST ctest)
106 if (GCOV AND LCOV AND GENHTML AND CTEST AND HAVE_CXX_FLAG_COVERAGE)
108 OUTPUT ${CMAKE_BINARY_DIR}/lcov/index.html
109 COMMAND ${LCOV} -q -z -d .
110 COMMAND ${LCOV} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o before.lcov -i
111 COMMAND ${CTEST} --force-new-ctest-process
112 COMMAND ${LCOV} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o after.lcov
113 COMMAND ${LCOV} -q -a before.lcov -a after.lcov --output-file final.lcov
114 COMMAND ${LCOV} -q -r final.lcov "'${CMAKE_SOURCE_DIR}/test/*'" -o final.lcov
115 COMMAND ${GENHTML} final.lcov -o lcov --demangle-cpp --sort -p "${CMAKE_BINARY_DIR}" -t benchmark
116 DEPENDS filter_test benchmark_test options_test basic_test fixture_test cxx03_test complexity_test
117 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
118 COMMENT "Running LCOV"
120 add_custom_target(coverage
121 DEPENDS ${CMAKE_BINARY_DIR}/lcov/index.html
122 COMMENT "LCOV report at lcov/index.html"
124 message(STATUS "Coverage command added")
126 if (HAVE_CXX_FLAG_COVERAGE)
127 set(CXX_FLAG_COVERAGE_MESSAGE supported)
129 set(CXX_FLAG_COVERAGE_MESSAGE unavailable)
132 "Coverage not available:\n"
135 " genhtml: ${GENHTML}\n"
137 " --coverage flag: ${CXX_FLAG_COVERAGE_MESSAGE}")