File: Patch.cmake

package info (click to toggle)
libmongocrypt 1.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,572 kB
  • sloc: ansic: 70,067; python: 4,547; cpp: 615; sh: 460; makefile: 44; awk: 8
file content (54 lines) | stat: -rw-r--r-- 1,836 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
find_program(GIT_EXECUTABLE git)
find_program(PATCH_EXECUTABLE patch)

#[[
    Form a new Patch-applying command for the given inputs

    make_patch_command(
        <outvar>
        [DISABLED <bool>]
        [DIRECTORY <dir>]
        [STRIP_COMPONENTS <N>]
        PATCHES [<file> ...]
    )
]]
function(make_patch_command out)
    cmake_parse_arguments(PARSE_ARGV 1 patch "" "DIRECTORY;STRIP_COMPONENTS;DISABLED" "PATCHES")
    if(patch_DISABLED)
        # Use a placeholder "no-op" patch command.
        set(cmd "${CMAKE_COMMAND}" "-E" "true")
    elseif(GIT_EXECUTABLE)
        # git ...
        set(cmd ${GIT_EXECUTABLE})

        if(patch_DIRECTORY)
            # git --work-tree=...
            list(APPEND cmd --work-tree=${patch_DIRECTORY})
        endif()
        # git ... apply ...
        list(APPEND cmd apply)
        # git ... apply -pN ...
        if(patch_STRIP_COMPONENTS)
            list(APPEND cmd -p${patch_STRIP_COMPONENTS})
        endif()
        # Ignore whitespace errors to fix patch errors on Windows: The patch file may be converted to \r\n by git, but libbson fetched with \n.
        list(APPEND cmd "--ignore-whitespace")
        # git accepts patch filepaths as positional arguments
        list(APPEND cmd ${patch_PATCHES})
    else()
        # patch ...
        set(cmd ${PATCH_EXECUTABLE})
        if(patch_DIRECTORY)
            # patch --dir=...
            list(APPEND cmd --dir=${patch_DIRECTORY})
        endif()
        # patch ... -pN ...
        if(patch_STRIP_COMPONENTS)
            list(APPEND cmd -p${patch_STRIP_COMPONENTS})
        endif()
        # Prepend "--input=" to each patch filepath and add them to the argv
        list(TRANSFORM patch_PATCHES PREPEND "--input=")
        list(APPEND cmd ${patch_PATCHES})
    endif()
    set("${out}" "${cmd}" PARENT_SCOPE)
endfunction()