|
1 | 1 | function(apply_patch_once patch_name target_dir patch_file) |
2 | | - # Store marker in build dir so it is cleaned with the build directory, |
3 | | - # avoiding stale markers when submodule sources are reset by git. |
4 | | - set(mark_file "${CMAKE_CURRENT_BINARY_DIR}/.${patch_name}_patched") |
| 2 | + set(mark_file "${target_dir}/.${patch_name}_patched") |
5 | 3 |
|
6 | 4 | if(EXISTS "${mark_file}") |
| 5 | + #message(STATUS "Patch '${patch_name}' already applied to ${target_dir}, skipping.") |
7 | 6 | return() |
8 | 7 | endif() |
9 | 8 |
|
10 | 9 | if(NOT EXISTS "${patch_file}") |
11 | 10 | message(FATAL_ERROR "Patch file '${patch_file}' not found!") |
12 | 11 | endif() |
13 | 12 |
|
| 13 | + #message(STATUS "Applying patch '${patch_name}' to ${target_dir} ...") |
14 | 14 | execute_process( |
15 | | - COMMAND git apply --check --ignore-space-change --ignore-whitespace "${patch_file}" |
16 | | - WORKING_DIRECTORY "${target_dir}" |
17 | | - RESULT_VARIABLE check_result |
18 | | - OUTPUT_QUIET ERROR_QUIET |
| 15 | + COMMAND git apply --ignore-space-change --ignore-whitespace "${patch_file}" |
| 16 | + WORKING_DIRECTORY "${target_dir}" |
| 17 | + RESULT_VARIABLE patch_result |
| 18 | + OUTPUT_VARIABLE patch_stdout |
| 19 | + ERROR_VARIABLE patch_stderr |
19 | 20 | ) |
20 | 21 |
|
21 | | - if (check_result EQUAL 0) |
22 | | - execute_process( |
23 | | - COMMAND git apply --ignore-space-change --ignore-whitespace "${patch_file}" |
24 | | - WORKING_DIRECTORY "${target_dir}" |
25 | | - RESULT_VARIABLE patch_result |
26 | | - OUTPUT_VARIABLE patch_stdout |
27 | | - ERROR_VARIABLE patch_stderr |
28 | | - ) |
29 | | - if (NOT patch_result EQUAL 0) |
30 | | - message(FATAL_ERROR "Failed to apply patch '${patch_name}' to ${target_dir}:\n${patch_stderr}") |
31 | | - endif () |
| 22 | + if(NOT patch_result EQUAL 0) |
| 23 | + message(FATAL_ERROR "Failed to apply patch '${patch_name}' to ${target_dir}:\n${patch_stderr}") |
32 | 24 | else() |
33 | | - # Patch cannot be applied cleanly - verify it is already applied |
34 | | - execute_process( |
35 | | - COMMAND git apply --reverse --check --ignore-space-change --ignore-whitespace "${patch_file}" |
36 | | - WORKING_DIRECTORY "${target_dir}" |
37 | | - RESULT_VARIABLE reverse_result |
38 | | - OUTPUT_QUIET ERROR_QUIET |
39 | | - ) |
40 | | - if (NOT reverse_result EQUAL 0) |
41 | | - message(FATAL_ERROR "Patch '${patch_name}' cannot be applied to ${target_dir} and does not appear to be already applied.") |
42 | | - endif () |
| 25 | + #message(STATUS "Patch '${patch_name}' applied successfully:\n${patch_stdout}") |
| 26 | + file(WRITE "${mark_file}" "patched") |
43 | 27 | endif() |
44 | | - |
45 | | - file(WRITE "${mark_file}" "patched") |
46 | 28 | endfunction() |
0 commit comments