1 set(CLANG_SUPPORTED_VERSION "5.0.0")
2 set(GCC_SUPPORTED_VERSION "5.5.0")
4 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5 if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL ${CLANG_SUPPORTED_VERSION})
7 "Unsupported Clang version " ${CMAKE_CXX_COMPILER_VERSION}
8 ". Expected is " ${CLANG_SUPPORTED_VERSION}
9 ". Assembly tests may be broken.")
11 elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
12 if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL ${GCC_SUPPORTED_VERSION})
14 "Unsupported GCC version " ${CMAKE_CXX_COMPILER_VERSION}
15 ". Expected is " ${GCC_SUPPORTED_VERSION}
16 ". Assembly tests may be broken.")
19 message (WARNING "Unsupported compiler. Assembly tests may be broken.")
24 set(ASM_TEST_FLAGS "")
25 check_cxx_compiler_flag(-O3 BENCHMARK_HAS_O3_FLAG)
26 if (BENCHMARK_HAS_O3_FLAG)
27 list(APPEND ASM_TEST_FLAGS -O3)
30 check_cxx_compiler_flag(-g0 BENCHMARK_HAS_G0_FLAG)
31 if (BENCHMARK_HAS_G0_FLAG)
32 list(APPEND ASM_TEST_FLAGS -g0)
35 check_cxx_compiler_flag(-fno-stack-protector BENCHMARK_HAS_FNO_STACK_PROTECTOR_FLAG)
36 if (BENCHMARK_HAS_FNO_STACK_PROTECTOR_FLAG)
37 list(APPEND ASM_TEST_FLAGS -fno-stack-protector)
40 split_list(ASM_TEST_FLAGS)
41 string(TOUPPER "${CMAKE_CXX_COMPILER_ID}" ASM_TEST_COMPILER)
43 macro(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}>
53 BYPRODUCTS ${ASM_OUTPUT_FILE})
54 add_dependencies(copy_${name} ${name})
55 if (NOT ARG_CHECK_PREFIXES)
56 set(ARG_CHECK_PREFIXES "CHECK")
58 foreach(prefix ${ARG_CHECK_PREFIXES})
59 add_test(NAME run_${name}_${prefix}
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})