File: CMakeLists.txt

package info (click to toggle)
cmake 4.2.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 152,456 kB
  • sloc: ansic: 403,896; cpp: 303,920; sh: 4,105; python: 3,583; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 111; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (77 lines) | stat: -rw-r--r-- 2,024 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
cmake_minimum_required(VERSION 3.10)
project(TestFindPatch VERSION 1.0 LANGUAGES NONE)

macro(_check)
  if(NOT EXISTS "${Patch_EXECUTABLE}")
    message(FATAL_ERROR "Failed to lookup Patch_EXECUTABLE [${Patch_EXECUTABLE}]")
  endif()

  if(NOT DEFINED Patch_FOUND)
    message(FATAL_ERROR "Variable Patch_FOUND is not defined")
  endif()

  # Is import target available ?
  if(NOT TARGET Patch::patch)
    message(FATAL_ERROR "Target Patch::patch is not defined")
  endif()

  # Check Patch::patch imported location
  get_property(_imported_location TARGET Patch::patch PROPERTY IMPORTED_LOCATION)
  if(NOT "${Patch_EXECUTABLE}" STREQUAL "${_imported_location}")
    message(FATAL_ERROR "\
Patch_EXECUTABLE is expected to be equal to Patch::patch IMPORTED_LOCATION
  Patch_EXECUTABLE [${Patch_EXECUTABLE}]
  Patch::patch IMPORTED_LOCATION [${_imported_location}]
")
  endif()

endmacro()

find_package(Patch REQUIRED)
_check()

# Calling twice should not fail
find_package(Patch REQUIRED)
_check()

add_custom_target(TestPatchVersion ALL
  COMMAND ${Patch_EXECUTABLE} -v
  )

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/QUOTE.txt.baseline"
[=[Because it's there.
- George Mallory, 1923
]=]
)

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/QUOTE.txt" "Because it's there.\n")

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/quote-add-author.patch"
[=[diff --git a/QUOTE.txt b/QUOTE.txt
index b36681d..68059b3 100644
--- a/QUOTE.txt
+++ b/QUOTE.txt
@@ -1 +1,2 @@
 Because it's there.
+- George Mallory
]=]
)

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/quote-add-date.patch"
[=[diff --git a/QUOTE.txt b/QUOTE.txt
index 68059b3..c6f30c2 100644
--- a/QUOTE.txt
+++ b/QUOTE.txt
@@ -1,2 +1,2 @@
 Because it's there.
-- George Mallory
+- George Mallory, 1923
]=]
)

add_custom_target(TestPatch ALL
  COMMAND ${Patch_EXECUTABLE} -p1 -i quote-add-author.patch --binary
  COMMAND Patch::patch -p1 -i quote-add-date.patch --binary
  COMMAND ${CMAKE_COMMAND} -E compare_files QUOTE.txt QUOTE.txt.baseline
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  )