[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / third-party / benchmark / test / AssemblyTests.cmake
blob3d078586f1de1494650b73447bedd711b1c1c651
2 include(split_list)
4 set(ASM_TEST_FLAGS "")
5 check_cxx_compiler_flag(-O3 BENCHMARK_HAS_O3_FLAG)
6 if (BENCHMARK_HAS_O3_FLAG)
7   list(APPEND ASM_TEST_FLAGS -O3)
8 endif()
10 check_cxx_compiler_flag(-g0 BENCHMARK_HAS_G0_FLAG)
11 if (BENCHMARK_HAS_G0_FLAG)
12   list(APPEND ASM_TEST_FLAGS -g0)
13 endif()
15 check_cxx_compiler_flag(-fno-stack-protector BENCHMARK_HAS_FNO_STACK_PROTECTOR_FLAG)
16 if (BENCHMARK_HAS_FNO_STACK_PROTECTOR_FLAG)
17   list(APPEND ASM_TEST_FLAGS -fno-stack-protector)
18 endif()
20 split_list(ASM_TEST_FLAGS)
21 string(TOUPPER "${CMAKE_CXX_COMPILER_ID}" ASM_TEST_COMPILER)
23 macro(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()
45 endmacro()