CMakeLists.txt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. cmake_minimum_required(VERSION 3.8)
  2. project(TestFindPatch VERSION 1.0 LANGUAGES NONE)
  3. macro(_check)
  4. if(NOT EXISTS "${Patch_EXECUTABLE}")
  5. message(FATAL_ERROR "Failed to lookup Patch_EXECUTABLE [${Patch_EXECUTABLE}]")
  6. endif()
  7. if(NOT DEFINED PATCH_FOUND)
  8. message(FATAL_ERROR "Variable PATCH_FOUND is not defined")
  9. endif()
  10. # Is import target available ?
  11. if(NOT TARGET Patch::patch)
  12. message(FATAL_ERROR "Target Patch::patch is not defined")
  13. endif()
  14. # Check Patch::patch imported location
  15. get_property(_imported_location TARGET Patch::patch PROPERTY IMPORTED_LOCATION)
  16. if(NOT "${Patch_EXECUTABLE}" STREQUAL "${_imported_location}")
  17. message(FATAL_ERROR "\
  18. Patch_EXECUTABLE is expected to be equal to Patch::patch IMPORTED_LOCATION
  19. Patch_EXECUTABLE [${Patch_EXECUTABLE}]
  20. Patch::patch IMPORTED_LOCATION [${_imported_location}]
  21. ")
  22. endif()
  23. endmacro()
  24. find_package(Patch REQUIRED)
  25. _check()
  26. # Calling twice should not fail
  27. find_package(Patch REQUIRED)
  28. _check()
  29. add_custom_target(TestPatchVersion ALL
  30. COMMAND ${Patch_EXECUTABLE} -v
  31. )
  32. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/QUOTE.txt.baseline"
  33. [=[Because it's there.
  34. - George Mallory, 1923
  35. ]=]
  36. )
  37. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/QUOTE.txt" "Because it's there.\n")
  38. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/quote-add-author.patch"
  39. [=[diff --git a/QUOTE.txt b/QUOTE.txt
  40. index b36681d..68059b3 100644
  41. --- a/QUOTE.txt
  42. +++ b/QUOTE.txt
  43. @@ -1 +1,2 @@
  44. Because it's there.
  45. +- George Mallory
  46. ]=]
  47. )
  48. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/quote-add-date.patch"
  49. [=[diff --git a/QUOTE.txt b/QUOTE.txt
  50. index 68059b3..c6f30c2 100644
  51. --- a/QUOTE.txt
  52. +++ b/QUOTE.txt
  53. @@ -1,2 +1,2 @@
  54. Because it's there.
  55. -- George Mallory
  56. +- George Mallory, 1923
  57. ]=]
  58. )
  59. add_custom_target(TestPatch ALL
  60. COMMAND ${Patch_EXECUTABLE} -p1 -i quote-add-author.patch --binary
  61. COMMAND Patch::patch -p1 -i quote-add-date.patch --binary
  62. COMMAND ${CMAKE_COMMAND} -E compare_files QUOTE.txt QUOTE.txt.baseline
  63. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  64. )