patch.cmake 1.79 KB
Newer Older
1
#
Julien Michel's avatar
Julien Michel committed
2
# Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#
# This file is part of Orfeo Toolbox
#
#     https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
20

21
find_program(PATCH_PROGRAM NAMES patch)
22 23 24
if(NOT PATCH_PROGRAM)
  message(FATAL_ERROR "patch program not found. PATCH_PROGRAM. search names :' patch'")
endif()
25

26 27
separate_arguments(DOT_DIFF_FILES)
list(SORT DOT_DIFF_FILES)
28

29 30 31 32
if(NOT PATCH_ARGS)
  set(PATCH_ARGS "-ut")
endif()

33 34 35 36
foreach(dot_diff_file ${DOT_DIFF_FILES})
  message("Input patch file: ${dot_diff_file}")
  execute_process(
    COMMAND
37 38
    ${CMAKE_COMMAND} -E chdir ${SOURCE_DIR}
    ${PATCH_PROGRAM} "${PATCH_ARGS}" "-p1" "-i" "${dot_diff_file}"
39 40 41 42
    RESULT_VARIABLE patch_rv
    OUTPUT_VARIABLE patch_ov
    OUTPUT_STRIP_TRAILING_WHITESPACE
    ERROR_STRIP_TRAILING_WHITESPACE)
43

44
  set(PATCHING_FAILED FALSE)
45

46 47
  if(NOT "${patch_rv}" STREQUAL "0")
    if( NOT "${patch_ov}" MATCHES "previously applied")
48 49
      set(PATCHING_FAILED TRUE)
    endif()
50
  endif()
51

52 53 54
  if( "${patch_ov}" MATCHES "FAILED")
    set(PATCHING_FAILED TRUE)
  endif()
55

56
  if(PATCHING_FAILED)
57 58
    message(FATAL_ERROR
      "${PATCH_PROGRAM} ${PATCH_ARGS} -p1 -i ${dot_diff_file} failed\n error: ${patch_ov} \n")
59
  else()
60
    message("${patch_ov}")
61
  endif()
62

63 64 65
  unset(patch_rv)
  unset(patch_ov)
endforeach()