2020-12-01 13:37:26 -08:00
|
|
|
#[===[.md
|
|
|
|
# vcpkg_apply_patches
|
|
|
|
|
|
|
|
Apply a set of patches to a source tree. This function is deprecated in favor of the `PATCHES` argument to `vcpkg_from_github()` et al.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
```cmake
|
|
|
|
vcpkg_apply_patches(
|
|
|
|
SOURCE_PATH <${SOURCE_PATH}>
|
|
|
|
[QUIET]
|
|
|
|
PATCHES <patch1.patch>...
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|
## Parameters
|
|
|
|
### SOURCE_PATH
|
|
|
|
The source path in which apply the patches. By convention, this is usually set in the portfile as the variable `SOURCE_PATH`.
|
|
|
|
|
|
|
|
### PATCHES
|
|
|
|
A list of patches that are applied to the source tree.
|
|
|
|
|
|
|
|
Generally, these take the form of `${CMAKE_CURRENT_LIST_DIR}/some.patch` to select patches in the `port\<port>\` directory.
|
|
|
|
|
|
|
|
### QUIET
|
|
|
|
Disables the warning message upon failure.
|
|
|
|
|
|
|
|
This should only be used for edge cases, such as patches that are known to fail even on a clean source tree.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
* [libbson](https://github.com/Microsoft/vcpkg/blob/master/ports/libbson/portfile.cmake)
|
|
|
|
* [gdal](https://github.com/Microsoft/vcpkg/blob/master/ports/gdal/portfile.cmake)
|
|
|
|
#]===]
|
2020-09-09 19:36:58 +02:00
|
|
|
|
|
|
|
include(vcpkg_execute_in_download_mode)
|
|
|
|
|
2016-09-18 20:50:08 -07:00
|
|
|
function(vcpkg_apply_patches)
|
2020-10-27 03:30:27 +01:00
|
|
|
# parse parameters such that semicolons in options arguments to COMMAND don't get erased
|
|
|
|
cmake_parse_arguments(PARSE_ARGV 0 _ap "QUIET" "SOURCE_PATH" "PATCHES")
|
2016-09-18 20:50:08 -07:00
|
|
|
|
2017-02-21 08:24:14 +03:00
|
|
|
find_program(GIT NAMES git git.cmd)
|
2020-11-30 09:50:42 -08:00
|
|
|
if(DEFINED ENV{GIT_CONFIG_NOSYSTEM})
|
|
|
|
set(GIT_CONFIG_NOSYSTEM_BACKUP "$ENV{GIT_CONFIG_NOSYSTEM}")
|
|
|
|
else()
|
|
|
|
unset(GIT_CONFIG_NOSYSTEM_BACKUP)
|
|
|
|
endif()
|
|
|
|
set(ENV{GIT_CONFIG_NOSYSTEM} 1)
|
2016-09-18 20:50:08 -07:00
|
|
|
set(PATCHNUM 0)
|
|
|
|
foreach(PATCH ${_ap_PATCHES})
|
2018-08-08 13:15:13 +02:00
|
|
|
get_filename_component(ABSOLUTE_PATCH "${PATCH}" ABSOLUTE BASE_DIR "${CURRENT_PORT_DIR}")
|
2016-09-18 20:50:08 -07:00
|
|
|
message(STATUS "Applying patch ${PATCH}")
|
|
|
|
set(LOGNAME patch-${TARGET_TRIPLET}-${PATCHNUM})
|
2020-09-09 19:36:58 +02:00
|
|
|
vcpkg_execute_in_download_mode(
|
2021-01-14 23:51:36 +01:00
|
|
|
COMMAND ${GIT} -c core.longpaths=true -c core.autocrlf=false --work-tree=. --git-dir=.git apply "${ABSOLUTE_PATCH}" --ignore-whitespace --whitespace=nowarn --verbose
|
2016-09-18 20:50:08 -07:00
|
|
|
OUTPUT_FILE ${CURRENT_BUILDTREES_DIR}/${LOGNAME}-out.log
|
2020-02-28 00:22:16 +02:00
|
|
|
ERROR_VARIABLE error
|
2016-09-18 20:50:08 -07:00
|
|
|
WORKING_DIRECTORY ${_ap_SOURCE_PATH}
|
|
|
|
RESULT_VARIABLE error_code
|
|
|
|
)
|
2020-02-28 00:22:16 +02:00
|
|
|
file(WRITE "${CURRENT_BUILDTREES_DIR}/${LOGNAME}-err.log" "${error}")
|
2016-11-02 16:49:15 -07:00
|
|
|
|
2018-01-24 15:22:41 -08:00
|
|
|
if(error_code AND NOT _ap_QUIET)
|
2020-02-28 00:22:16 +02:00
|
|
|
message(FATAL_ERROR "Applying patch failed. ${error}")
|
2016-10-18 16:17:47 -07:00
|
|
|
endif()
|
|
|
|
|
2016-09-18 20:50:08 -07:00
|
|
|
math(EXPR PATCHNUM "${PATCHNUM}+1")
|
|
|
|
endforeach()
|
2020-11-30 09:50:42 -08:00
|
|
|
if(DEFINED GIT_CONFIG_NOSYSTEM_BACKUP)
|
|
|
|
set(ENV{GIT_CONFIG_NOSYSTEM} "${GIT_CONFIG_NOSYSTEM_BACKUP}")
|
|
|
|
else()
|
|
|
|
unset(ENV{GIT_CONFIG_NOSYSTEM})
|
|
|
|
endif()
|
2016-09-18 20:50:08 -07:00
|
|
|
endfunction()
|