CheckOutput.cmake 661 B

1234567891011121314151617181920212223
  1. # Add rules to check the generated executable works.
  2. set(hello_output "${CMAKE_CURRENT_BINARY_DIR}/hello.output")
  3. add_custom_command(
  4. OUTPUT "${hello_output}"
  5. COMMAND "$<TARGET_FILE:hello>" > "${hello_output}"
  6. DEPENDS hello
  7. VERBATIM
  8. )
  9. if(NOT DEFINED HELLO_OUTPUT_STRING)
  10. set(HELLO_OUTPUT_STRING "Hello world!\n")
  11. endif()
  12. set(hello_output_ref "${CMAKE_CURRENT_BINARY_DIR}/hello.output.ref")
  13. file(WRITE "${hello_output_ref}" "${HELLO_OUTPUT_STRING}")
  14. add_custom_target(check_output ALL
  15. COMMAND "${CMAKE_COMMAND}" -E compare_files
  16. "${hello_output}" "${hello_output_ref}"
  17. DEPENDS "${hello_output}" "${hello_output_ref}"
  18. VERBATIM
  19. )