You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.3 KiB

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