From 24138bf3e609596074155c316c076024677f3df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A4r=20Bj=C3=B6rklund?= Date: Sat, 11 Jan 2020 11:46:35 +0100 Subject: [PATCH] Improve patch finding On Windows we only want to find patch.exe included with git. All other patch.exe is broken in some way and will cause build failures --- cmake/scripts/common/HandleDepends.cmake | 12 ------ cmake/scripts/windows/tools/patch.cmake | 39 +++++++++++++++++++- cmake/scripts/windowsstore/tools/patch.cmake | 39 +++++++++++++++++++- 3 files changed, 74 insertions(+), 16 deletions(-) diff --git a/cmake/scripts/common/HandleDepends.cmake b/cmake/scripts/common/HandleDepends.cmake index 40e382b94c221..78a3742145ae7 100644 --- a/cmake/scripts/common/HandleDepends.cmake +++ b/cmake/scripts/common/HandleDepends.cmake @@ -111,18 +111,6 @@ function(add_addon_depends addon searchpath) endif() set(PATCH_PROGRAM ${PATCH_EXECUTABLE}) - - # On Windows "patch.exe" can only handle CR-LF line-endings. - # Our patches have LF-only line endings - except when they - # have been checked out as part of a dependency hosted on Git - # and core.autocrlf=true. - if(WIN32) - file(READ ${patch} patch_content_hex HEX) - # Force handle LF-only line endings - if(NOT patch_content_hex MATCHES "0d0a") - list(APPEND PATCH_PROGRAM --binary) - endif() - endif() endif() set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${patch}) diff --git a/cmake/scripts/windows/tools/patch.cmake b/cmake/scripts/windows/tools/patch.cmake index b955b4cdcfe3b..d75cb6ec5d715 100644 --- a/cmake/scripts/windows/tools/patch.cmake +++ b/cmake/scripts/windows/tools/patch.cmake @@ -1,6 +1,41 @@ -find_program(PATCH_FOUND NAMES patch patch.exe) +set(_doc "Patch command line executable") +set(_patch_path ) + +#cmake can't handle ENV{PROGRAMFILES(X86)} so +#use a hack where we append it ourselves +set(_patch_path + "$ENV{LOCALAPPDATA}/Programs/Git/bin" + "$ENV{LOCALAPPDATA}/Programs/Git/usr/bin" + "$ENV{APPDATA}/Programs/Git/bin" + "$ENV{APPDATA}/Programs/Git/usr/bin" + "$ENV{PROGRAMFILES}/Git/bin" + "$ENV{PROGRAMFILES}/Git/usr/bin" + "$ENV{PROGRAMFILES} (x86)/Git/bin" + "$ENV{PROGRAMFILES} (x86)/Git/usr/bin" + ) + +# First search the PATH +find_program(PATCH_EXECUTABLE + NAME patch + PATHS ${_patch_path} + DOC ${_doc} + NO_DEFAULT_PATH + ) + +if(PATCH_EXECUTABLE AND NOT TARGET Patch::patch AND NOT PATCH_EXECUTABLE MATCHES Strawberry) + add_executable(Patch::patch IMPORTED) + set_property(TARGET Patch::patch PROPERTY IMPORTED_LOCATION ${PATCH_EXECUTABLE}) +endif() + +unset(_patch_path) +unset(_doc) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Patch + REQUIRED_VARS PATCH_EXECUTABLE) + if(PATCH_FOUND) - message(STATUS "patch utility found at ${PATCH_FOUND}") + message(STATUS "patch utility found at ${PATCH_EXECUTABLE}") else() set(PATCH_ARCHIVE_NAME "patch-2.7.6-bin") set(PATCH_ARCHIVE "${PATCH_ARCHIVE_NAME}.zip") diff --git a/cmake/scripts/windowsstore/tools/patch.cmake b/cmake/scripts/windowsstore/tools/patch.cmake index b955b4cdcfe3b..d75cb6ec5d715 100644 --- a/cmake/scripts/windowsstore/tools/patch.cmake +++ b/cmake/scripts/windowsstore/tools/patch.cmake @@ -1,6 +1,41 @@ -find_program(PATCH_FOUND NAMES patch patch.exe) +set(_doc "Patch command line executable") +set(_patch_path ) + +#cmake can't handle ENV{PROGRAMFILES(X86)} so +#use a hack where we append it ourselves +set(_patch_path + "$ENV{LOCALAPPDATA}/Programs/Git/bin" + "$ENV{LOCALAPPDATA}/Programs/Git/usr/bin" + "$ENV{APPDATA}/Programs/Git/bin" + "$ENV{APPDATA}/Programs/Git/usr/bin" + "$ENV{PROGRAMFILES}/Git/bin" + "$ENV{PROGRAMFILES}/Git/usr/bin" + "$ENV{PROGRAMFILES} (x86)/Git/bin" + "$ENV{PROGRAMFILES} (x86)/Git/usr/bin" + ) + +# First search the PATH +find_program(PATCH_EXECUTABLE + NAME patch + PATHS ${_patch_path} + DOC ${_doc} + NO_DEFAULT_PATH + ) + +if(PATCH_EXECUTABLE AND NOT TARGET Patch::patch AND NOT PATCH_EXECUTABLE MATCHES Strawberry) + add_executable(Patch::patch IMPORTED) + set_property(TARGET Patch::patch PROPERTY IMPORTED_LOCATION ${PATCH_EXECUTABLE}) +endif() + +unset(_patch_path) +unset(_doc) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Patch + REQUIRED_VARS PATCH_EXECUTABLE) + if(PATCH_FOUND) - message(STATUS "patch utility found at ${PATCH_FOUND}") + message(STATUS "patch utility found at ${PATCH_EXECUTABLE}") else() set(PATCH_ARCHIVE_NAME "patch-2.7.6-bin") set(PATCH_ARCHIVE "${PATCH_ARCHIVE_NAME}.zip")