1
2include(split_list)
3
4set(ASM_TEST_FLAGS "")
5check_cxx_compiler_flag(-O3 BENCHMARK_HAS_O3_FLAG)
6if (BENCHMARK_HAS_O3_FLAG)
7  list(APPEND ASM_TEST_FLAGS -O3)
8endif()
9
10check_cxx_compiler_flag(-g0 BENCHMARK_HAS_G0_FLAG)
11if (BENCHMARK_HAS_G0_FLAG)
12  list(APPEND ASM_TEST_FLAGS -g0)
13endif()
14
15check_cxx_compiler_flag(-fno-stack-protector BENCHMARK_HAS_FNO_STACK_PROTECTOR_FLAG)
16if (BENCHMARK_HAS_FNO_STACK_PROTECTOR_FLAG)
17  list(APPEND ASM_TEST_FLAGS -fno-stack-protector)
18endif()
19
20split_list(ASM_TEST_FLAGS)
21string(TOUPPER "${CMAKE_CXX_COMPILER_ID}" ASM_TEST_COMPILER)
22
23macro(add_filecheck_test name)
24  cmake_parse_arguments(ARG "" "" "CHECK_PREFIXES" ${ARGV})
25  add_library(${name} OBJECT ${name}.cc)
26  set_target_properties(${name} PROPERTIES COMPILE_FLAGS "-S ${ASM_TEST_FLAGS}")
27  set(ASM_OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${name}.s")
28  add_custom_target(copy_${name} ALL
29      COMMAND ${PROJECT_SOURCE_DIR}/tools/strip_asm.py
30        $<TARGET_OBJECTS:${name}>
31        ${ASM_OUTPUT_FILE}
32      BYPRODUCTS ${ASM_OUTPUT_FILE})
33  add_dependencies(copy_${name} ${name})
34  if (NOT ARG_CHECK_PREFIXES)
35    set(ARG_CHECK_PREFIXES "CHECK")
36  endif()
37  foreach(prefix ${ARG_CHECK_PREFIXES})
38    add_test(NAME run_${name}_${prefix}
39        COMMAND
40          ${LLVM_FILECHECK_EXE} ${name}.cc
41          --input-file=${ASM_OUTPUT_FILE}
42          --check-prefixes=CHECK,CHECK-${ASM_TEST_COMPILER}
43        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
44  endforeach()
45endmacro()
46
47