vcpkg/scripts/cmake/vcpkg_apply_patches.cmake

46 lines
1.6 KiB
CMake
Raw Normal View History

2017-01-06 06:37:37 +08:00
#.rst:
# .. command:: vcpkg_apply_patches
#
# Apply a set of patches to a source tree.
#
# ::
# vcpkg_apply_patches(SOURCE_PATH <source_path>
# PATCHES patch1 [patch ...]
# )
#
# ``SOURCE_PATH``
# The source path in which apply the patches.
# ``PATCHES``
# A list of patches that are applied to the source tree
# ``QUIET``
# If this option is passed, the warning message when applyng
# a patch fails is not printed. This is convenient for patches
# that are known to fail even on a clean source tree, and for
2017-01-06 06:37:37 +08:00
# which the standard warning message would be confusing for the user.
#
2016-09-19 11:50:08 +08:00
function(vcpkg_apply_patches)
2017-01-06 06:37:37 +08:00
cmake_parse_arguments(_ap "QUIET" "SOURCE_PATH" "PATCHES" ${ARGN})
2016-09-19 11:50:08 +08:00
find_program(GIT NAMES git git.cmd)
2016-09-19 11:50:08 +08:00
set(PATCHNUM 0)
foreach(PATCH ${_ap_PATCHES})
message(STATUS "Applying patch ${PATCH}")
set(LOGNAME patch-${TARGET_TRIPLET}-${PATCHNUM})
execute_process(
COMMAND ${GIT} --work-tree=. --git-dir=.git apply "${PATCH}" --ignore-whitespace --whitespace=nowarn --verbose
2016-09-19 11:50:08 +08:00
OUTPUT_FILE ${CURRENT_BUILDTREES_DIR}/${LOGNAME}-out.log
ERROR_FILE ${CURRENT_BUILDTREES_DIR}/${LOGNAME}-err.log
WORKING_DIRECTORY ${_ap_SOURCE_PATH}
RESULT_VARIABLE error_code
)
2017-01-06 06:37:37 +08:00
if(error_code AND NOT ${_ap_QUIET})
message(STATUS "Applying patch failed. This is expected if this patch was previously applied.")
endif()
2016-09-19 11:50:08 +08:00
message(STATUS "Applying patch ${PATCH} done")
math(EXPR PATCHNUM "${PATCHNUM}+1")
endforeach()
endfunction()