xref: /llvm-project/third-party/benchmark/test/AssemblyTests.cmake (revision a5b797172cc902db166e9a695716fb81405f86e4)
1*a5b79717SMircea Trofinset(CLANG_SUPPORTED_VERSION "5.0.0")
2*a5b79717SMircea Trofinset(GCC_SUPPORTED_VERSION "5.5.0")
3*a5b79717SMircea Trofin
4*a5b79717SMircea Trofinif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5*a5b79717SMircea Trofin  if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL ${CLANG_SUPPORTED_VERSION})
6*a5b79717SMircea Trofin    message (WARNING
7*a5b79717SMircea Trofin      "Unsupported Clang version " ${CMAKE_CXX_COMPILER_VERSION}
8*a5b79717SMircea Trofin      ". Expected is " ${CLANG_SUPPORTED_VERSION}
9*a5b79717SMircea Trofin      ". Assembly tests may be broken.")
10*a5b79717SMircea Trofin  endif()
11*a5b79717SMircea Trofinelseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
12*a5b79717SMircea Trofin  if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL ${GCC_SUPPORTED_VERSION})
13*a5b79717SMircea Trofin    message (WARNING
14*a5b79717SMircea Trofin      "Unsupported GCC version " ${CMAKE_CXX_COMPILER_VERSION}
15*a5b79717SMircea Trofin      ". Expected is " ${GCC_SUPPORTED_VERSION}
16*a5b79717SMircea Trofin      ". Assembly tests may be broken.")
17*a5b79717SMircea Trofin  endif()
18*a5b79717SMircea Trofinelse()
19*a5b79717SMircea Trofin  message (WARNING "Unsupported compiler. Assembly tests may be broken.")
20*a5b79717SMircea Trofinendif()
215dda2efdSMircea Trofin
225dda2efdSMircea Trofininclude(split_list)
235dda2efdSMircea Trofin
245dda2efdSMircea Trofinset(ASM_TEST_FLAGS "")
255dda2efdSMircea Trofincheck_cxx_compiler_flag(-O3 BENCHMARK_HAS_O3_FLAG)
265dda2efdSMircea Trofinif (BENCHMARK_HAS_O3_FLAG)
275dda2efdSMircea Trofin  list(APPEND ASM_TEST_FLAGS -O3)
285dda2efdSMircea Trofinendif()
295dda2efdSMircea Trofin
305dda2efdSMircea Trofincheck_cxx_compiler_flag(-g0 BENCHMARK_HAS_G0_FLAG)
315dda2efdSMircea Trofinif (BENCHMARK_HAS_G0_FLAG)
325dda2efdSMircea Trofin  list(APPEND ASM_TEST_FLAGS -g0)
335dda2efdSMircea Trofinendif()
345dda2efdSMircea Trofin
355dda2efdSMircea Trofincheck_cxx_compiler_flag(-fno-stack-protector BENCHMARK_HAS_FNO_STACK_PROTECTOR_FLAG)
365dda2efdSMircea Trofinif (BENCHMARK_HAS_FNO_STACK_PROTECTOR_FLAG)
375dda2efdSMircea Trofin  list(APPEND ASM_TEST_FLAGS -fno-stack-protector)
385dda2efdSMircea Trofinendif()
395dda2efdSMircea Trofin
405dda2efdSMircea Trofinsplit_list(ASM_TEST_FLAGS)
415dda2efdSMircea Trofinstring(TOUPPER "${CMAKE_CXX_COMPILER_ID}" ASM_TEST_COMPILER)
425dda2efdSMircea Trofin
435dda2efdSMircea Trofinmacro(add_filecheck_test name)
445dda2efdSMircea Trofin  cmake_parse_arguments(ARG "" "" "CHECK_PREFIXES" ${ARGV})
455dda2efdSMircea Trofin  add_library(${name} OBJECT ${name}.cc)
46*a5b79717SMircea Trofin  target_link_libraries(${name} PRIVATE benchmark::benchmark)
475dda2efdSMircea Trofin  set_target_properties(${name} PROPERTIES COMPILE_FLAGS "-S ${ASM_TEST_FLAGS}")
485dda2efdSMircea Trofin  set(ASM_OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${name}.s")
495dda2efdSMircea Trofin  add_custom_target(copy_${name} ALL
505dda2efdSMircea Trofin      COMMAND ${PROJECT_SOURCE_DIR}/tools/strip_asm.py
515dda2efdSMircea Trofin        $<TARGET_OBJECTS:${name}>
525dda2efdSMircea Trofin        ${ASM_OUTPUT_FILE}
535dda2efdSMircea Trofin      BYPRODUCTS ${ASM_OUTPUT_FILE})
545dda2efdSMircea Trofin  add_dependencies(copy_${name} ${name})
555dda2efdSMircea Trofin  if (NOT ARG_CHECK_PREFIXES)
565dda2efdSMircea Trofin    set(ARG_CHECK_PREFIXES "CHECK")
575dda2efdSMircea Trofin  endif()
585dda2efdSMircea Trofin  foreach(prefix ${ARG_CHECK_PREFIXES})
595dda2efdSMircea Trofin    add_test(NAME run_${name}_${prefix}
605dda2efdSMircea Trofin        COMMAND
615dda2efdSMircea Trofin          ${LLVM_FILECHECK_EXE} ${name}.cc
625dda2efdSMircea Trofin          --input-file=${ASM_OUTPUT_FILE}
635dda2efdSMircea Trofin          --check-prefixes=CHECK,CHECK-${ASM_TEST_COMPILER}
645dda2efdSMircea Trofin        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
655dda2efdSMircea Trofin  endforeach()
665dda2efdSMircea Trofinendmacro()
675dda2efdSMircea Trofin
68