test-AArch-CMakeLists


  • 基础设置
find_package(GTest CONFIG REQUIRED)
list(APPEND PROJECT_LIBRARIES GTest::gtest)

enable_testing()
enable_language(ASM)
  • 添加可执行文件

Lift.cpp/Tests.S生成lift-aarch64-tests

Run.cpp/Tests.S/tests_aarch64.S生成run-aarch64-tests

add_executable(lift-aarch64-tests
  EXCLUDE_FROM_ALL
  Lift.cpp
  Tests.S
)

add_executable(run-aarch64-tests
  EXCLUDE_FROM_ALL
  Run.cpp
  Tests.S
  tests_aarch64.S
)

  • 在lift-aarch64-tests 作用域中设置 POSITION_INDEPENDENT_CODE 为ON

    COMPILE_FLAGS为”-fPIC -pie”

    设置 OBJECT_DEPENDS 为”${AARCH64_TEST_FILES}”

  • 在run-aarch64-tests作用域中设置 POSITION_INDEPENDENT_CODE为 ON

​ COMPILE_FLAGS 为”-fPIC -pie”

​ OBJECT_DEPENDS 为”${AARCH64_TEST_FILES}”

set_target_properties(lift-aarch64-tests PROPERTIES
  POSITION_INDEPENDENT_CODE ON
  COMPILE_FLAGS "-fPIC -pie"
)

set_target_properties(lift-aarch64-tests PROPERTIES OBJECT_DEPENDS "${AARCH64_TEST_FILES}")

set_target_properties(run-aarch64-tests PROPERTIES
  POSITION_INDEPENDENT_CODE ON
  COMPILE_FLAGS "-fPIC -pie"
  OBJECT_DEPENDS "${AARCH64_TEST_FILES}"
)
  • 设置编译选项
target_compile_options(lift-aarch64-tests
  PRIVATE ${AARCH64_TEST_FLAGS}
  -DIN_TEST_GENERATOR
)
  • file

会产生一个由所有匹配globbing表达式的文件组成的列表,并将其保存到变量中

file(GLOB AARCH64_TEST_FILES
  "${CMAKE_CURRENT_LIST_DIR}/*/*.S"
)
  • 输出文件执行命令

生成:

tests_aarch64.bc

tests_aarch64.S

执行:COMMND后面的命令


add_custom_command(
  OUTPUT tests_aarch64.bc
  COMMAND lift-aarch64-tests --arch aarch64 --bc_out tests_aarch64.bc
  DEPENDS lift-aarch64-tests semantics
)

add_custom_command(
  OUTPUT  tests_aarch64.S
  COMMAND ${CMAKE_BC_COMPILER}
          -Wno-override-module
          -S -O1 -g0
          -c tests_aarch64.bc
          -o tests_aarch64.S
  DEPENDS tests_aarch64.bc
)
  • 目标文件与库文件进行连接
target_link_libraries(lift-aarch64-tests PUBLIC remill ${PROJECT_LIBRARIES} )
target_include_directories(lift-aarch64-tests PUBLIC ${PROJECT_INCLUDEDIRECTORIES})
target_include_directories(lift-aarch64-tests PRIVATE ${CMAKE_SOURCE_DIR})

target_link_libraries(run-aarch64-tests PUBLIC remill ${PROJECT_LIBRARIES})
target_include_directories(run-aarch64-tests PUBLIC ${PROJECT_INCLUDEDIRECTORIES})
target_include_directories(run-aarch64-tests PRIVATE ${CMAKE_SOURCE_DIR})
  • 开启项目测试工作
add_test(NAME "aarch64" COMMAND "run-aarch64-tests")
  • 在顶层和目标层之间添加依赖关系
add_dependencies(test_dependencies run-aarch64-tests)

文章作者: XX
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 XX !
  目录