• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1set(CLANG_SUPPORTED_VERSION "5.0.0")
2set(GCC_SUPPORTED_VERSION "5.5.0")
3
4if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5  if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL ${CLANG_SUPPORTED_VERSION})
6    message (WARNING
7      "Unsupported Clang version " ${CMAKE_CXX_COMPILER_VERSION}
8      ". Expected is " ${CLANG_SUPPORTED_VERSION}
9      ". Assembly tests may be broken.")
10  endif()
11elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
12  if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL ${GCC_SUPPORTED_VERSION})
13    message (WARNING
14      "Unsupported GCC version " ${CMAKE_CXX_COMPILER_VERSION}
15      ". Expected is " ${GCC_SUPPORTED_VERSION}
16      ". Assembly tests may be broken.")
17  endif()
18else()
19  message (WARNING "Unsupported compiler. Assembly tests may be broken.")
20endif()
21
22include(split_list)
23
24set(ASM_TEST_FLAGS "")
25check_cxx_compiler_flag(-O3 BENCHMARK_HAS_O3_FLAG)
26if (BENCHMARK_HAS_O3_FLAG)
27  list(APPEND ASM_TEST_FLAGS -O3)
28endif()
29
30check_cxx_compiler_flag(-g0 BENCHMARK_HAS_G0_FLAG)
31if (BENCHMARK_HAS_G0_FLAG)
32  list(APPEND ASM_TEST_FLAGS -g0)
33endif()
34
35check_cxx_compiler_flag(-fno-stack-protector BENCHMARK_HAS_FNO_STACK_PROTECTOR_FLAG)
36if (BENCHMARK_HAS_FNO_STACK_PROTECTOR_FLAG)
37  list(APPEND ASM_TEST_FLAGS -fno-stack-protector)
38endif()
39
40split_list(ASM_TEST_FLAGS)
41string(TOUPPER "${CMAKE_CXX_COMPILER_ID}" ASM_TEST_COMPILER)
42
43macro(add_filecheck_test name)
44  cmake_parse_arguments(ARG "" "" "CHECK_PREFIXES" ${ARGV})
45  add_library(${name} OBJECT ${name}.cc)
46  target_link_libraries(${name} PRIVATE benchmark::benchmark)
47  set_target_properties(${name} PROPERTIES COMPILE_FLAGS "-S ${ASM_TEST_FLAGS}")
48  set(ASM_OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${name}.s")
49  add_custom_target(copy_${name} ALL
50      COMMAND ${PROJECT_SOURCE_DIR}/tools/strip_asm.py
51        $<TARGET_OBJECTS:${name}>
52        ${ASM_OUTPUT_FILE}
53      BYPRODUCTS ${ASM_OUTPUT_FILE})
54  add_dependencies(copy_${name} ${name})
55  if (NOT ARG_CHECK_PREFIXES)
56    set(ARG_CHECK_PREFIXES "CHECK")
57  endif()
58  foreach(prefix ${ARG_CHECK_PREFIXES})
59    add_test(NAME run_${name}_${prefix}
60        COMMAND
61          ${LLVM_FILECHECK_EXE} ${name}.cc
62          --input-file=${ASM_OUTPUT_FILE}
63          --check-prefixes=CHECK,CHECK-${ASM_TEST_COMPILER}
64        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
65  endforeach()
66endmacro()
67
68