diff options
author | fuzzard <fuzzard@kodi.tv> | 2022-05-23 07:54:40 +1000 |
---|---|---|
committer | fuzzard <fuzzard@kodi.tv> | 2022-05-24 09:26:52 +1000 |
commit | 5e52c0849de60e27948e5f6e012d30e48d67c72a (patch) | |
tree | ed8ae44c08f0213fb3961b6abefa23ffed4006a1 /cmake | |
parent | a80c417ea9f411228817fec9e5c46856e83d1520 (diff) |
[cmake] Flesh out FindPatch module for windows use
Windows we want to preference git patch, so adapt find module to check specifically
for it. Update other find modules importing FindPatch.cmake to actual find_package calls
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/modules/FindCrossGUID.cmake | 4 | ||||
-rw-r--r-- | cmake/modules/FindFmt.cmake | 2 | ||||
-rw-r--r-- | cmake/modules/FindPatch.cmake | 115 | ||||
-rw-r--r-- | cmake/modules/FindRapidJSON.cmake | 4 | ||||
-rw-r--r-- | cmake/modules/FindSpdlog.cmake | 2 | ||||
-rw-r--r-- | cmake/scripts/common/ModuleHelpers.cmake | 2 |
6 files changed, 74 insertions, 55 deletions
diff --git a/cmake/modules/FindCrossGUID.cmake b/cmake/modules/FindCrossGUID.cmake index 4783128765..f13c31361e 100644 --- a/cmake/modules/FindCrossGUID.cmake +++ b/cmake/modules/FindCrossGUID.cmake @@ -33,8 +33,8 @@ if(ENABLE_INTERNAL_CROSSGUID) list(APPEND CROSSGUID_DEFINITIONS -DGUID_ANDROID) endif() - # Use custom findpatch to handle windows patch binary if not available - include(cmake/modules/FindPatch.cmake) + # find the path to the patch executable + find_package(Patch MODULE REQUIRED) set(PATCH_COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/001-fix-unused-function.patch COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/002-disable-Wall-error.patch) diff --git a/cmake/modules/FindFmt.cmake b/cmake/modules/FindFmt.cmake index 096f927ad6..30ce155f32 100644 --- a/cmake/modules/FindFmt.cmake +++ b/cmake/modules/FindFmt.cmake @@ -27,7 +27,7 @@ if(ENABLE_INTERNAL_FMT) if(WIN32 OR WINDOWS_STORE) # find the path to the patch executable - find_program(PATCH_EXECUTABLE NAMES patch patch.exe REQUIRED) + find_package(Patch MODULE REQUIRED) set(patch ${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-windows-pdb-symbol-gen.patch) PATCH_LF_CHECK(${patch}) diff --git a/cmake/modules/FindPatch.cmake b/cmake/modules/FindPatch.cmake index 3f6afd7c1b..4fbf5a6dbd 100644 --- a/cmake/modules/FindPatch.cmake +++ b/cmake/modules/FindPatch.cmake @@ -8,53 +8,72 @@ # # PATCH_EXECUTABLE - patch executable -find_program(PATCH_EXECUTABLE NAMES patch patch.exe) -if(NOT PATCH_EXECUTABLE) - if(WIN32 OR WINDOWSSTORE) - # Set mirror for potential patch binary download - if(NOT KODI_MIRROR) - set(KODI_MIRROR "http://mirrors.kodi.tv") - endif() - - set(PATCH_ARCHIVE_NAME "patch-2.7.6-bin") - set(PATCH_ARCHIVE "${PATCH_ARCHIVE_NAME}.zip") - set(PATCH_URL "${KODI_MIRROR}/build-deps/win32/${PATCH_ARCHIVE}") - set(PATCH_DOWNLOAD ${TARBALL_DIR}/${PATCH_ARCHIVE}) - - # download the archive containing patch.exe - message(STATUS "Downloading patch utility from ${PATCH_URL}...") - file(DOWNLOAD "${PATCH_URL}" "${PATCH_DOWNLOAD}" STATUS PATCH_DL_STATUS LOG PATCH_LOG SHOW_PROGRESS) - list(GET PATCH_DL_STATUS 0 PATCH_RETCODE) - if(NOT PATCH_RETCODE EQUAL 0) - message(FATAL_ERROR "ERROR downloading ${PATCH_URL} - status: ${PATCH_DL_STATUS} log: ${PATCH_LOG}") - endif() - - # CORE_BUILD_DIR may not exist as yet, so create just in case - if(NOT EXISTS ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}) - file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}) - endif() - - # extract the archive containing patch.exe - execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzvf ${PATCH_DOWNLOAD} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}) - - # make sure the extraction worked and that patch.exe is there - set(PATCH_PATH ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${PATCH_ARCHIVE_NAME}) - if(NOT EXISTS "${PATCH_PATH}/bin/patch.exe") - message(FATAL_ERROR "ERROR extracting patch utility from ${PATCH_PATH}") - endif() - - # copy patch.exe into the output directory - file(INSTALL "${PATCH_PATH}/bin/patch.exe" DESTINATION ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/bin) - # copy patch depends - file(GLOB PATCH_BINARIES ${PATCH_PATH}/bin/*.dll) - if(NOT "${PATCH_BINARIES}" STREQUAL "") - file(INSTALL ${PATCH_BINARIES} DESTINATION ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/bin) - endif() - - # make sure that cmake can find the copied patch.exe - find_program(PATCH_EXECUTABLE NAMES patch.exe HINTS ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/bin REQUIRED) - else() - message(FATAL_ERROR "ERROR - No patch executable found") +if(CMAKE_HOST_WIN32) + + find_package(Git) + if(Git_FOUND) + get_filename_component(GIT_DIR ${GIT_EXECUTABLE} DIRECTORY) + endif() + + find_program(PATCH_EXE NAMES patch.exe HINTS "${GIT_DIR}/.." PATH_SUFFIXES usr/bin) +else() + # Freebsd patch is insufficient (too old) look for gnu patch first + find_program(PATCH_EXE NAMES gpatch patch) +endif() + +if(CMAKE_HOST_WIN32 AND NOT PATCH_EXE) + # Set mirror for potential patch binary download + if(NOT KODI_MIRROR) + set(KODI_MIRROR "http://mirrors.kodi.tv") + endif() + + set(PATCH_ARCHIVE_NAME "patch-2.7.6-bin") + set(PATCH_ARCHIVE "${PATCH_ARCHIVE_NAME}.zip") + set(PATCH_URL "${KODI_MIRROR}/build-deps/win32/${PATCH_ARCHIVE}") + set(PATCH_DOWNLOAD ${TARBALL_DIR}/${PATCH_ARCHIVE}) + + # download the archive containing patch.exe + message(STATUS "Downloading patch utility from ${PATCH_URL}...") + file(DOWNLOAD "${PATCH_URL}" "${PATCH_DOWNLOAD}" STATUS PATCH_DL_STATUS LOG PATCH_LOG SHOW_PROGRESS) + list(GET PATCH_DL_STATUS 0 PATCH_RETCODE) + if(NOT PATCH_RETCODE EQUAL 0) + message(FATAL_ERROR "ERROR downloading ${PATCH_URL} - status: ${PATCH_DL_STATUS} log: ${PATCH_LOG}") + endif() + + # CORE_BUILD_DIR may not exist as yet, so create just in case + if(NOT EXISTS ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}) + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}) endif() + + # extract the archive containing patch.exe + execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzvf ${PATCH_DOWNLOAD} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}) + + # make sure the extraction worked and that patch.exe is there + set(PATCH_PATH ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${PATCH_ARCHIVE_NAME}) + if(NOT EXISTS "${PATCH_PATH}/bin/patch.exe") + message(FATAL_ERROR "ERROR extracting patch utility from ${PATCH_PATH}") + endif() + + # copy patch.exe into the output directory + file(INSTALL "${PATCH_PATH}/bin/patch.exe" DESTINATION ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/bin) + # copy patch depends + file(GLOB PATCH_BINARIES ${PATCH_PATH}/bin/*.dll) + if(NOT "${PATCH_BINARIES}" STREQUAL "") + file(INSTALL ${PATCH_BINARIES} DESTINATION ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/bin) + endif() + + # make sure that cmake can find the copied patch.exe + find_program(PATCH_EXE NAMES patch.exe HINTS ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/bin REQUIRED) +endif() + +include(FindPackageHandleStandardArgs) + +set(FPHSA_NAME_MISMATCHED 1) # Suppress warnings, see https://cmake.org/cmake/help/v3.17/module/FindPackageHandleStandardArgs.html +find_package_handle_standard_args(PATCH REQUIRED_VARS PATCH_EXE) +unset(FPHSA_NAME_MISMATCHED) + +if(PATCH_FOUND) + set(PATCH_EXECUTABLE "${PATCH_EXE}") + mark_as_advanced(PATCH_EXE) endif() diff --git a/cmake/modules/FindRapidJSON.cmake b/cmake/modules/FindRapidJSON.cmake index be00f123f8..ba222f5b11 100644 --- a/cmake/modules/FindRapidJSON.cmake +++ b/cmake/modules/FindRapidJSON.cmake @@ -18,8 +18,8 @@ if(ENABLE_INTERNAL_RapidJSON) set(RapidJSON_INCLUDE_DIR ${${MODULE}_INCLUDE_DIR}) set(RapidJSON_VERSION ${${MODULE}_VER}) - # Use custom findpatch to handle windows patch binary if not available - include(cmake/modules/FindPatch.cmake) + # find the path to the patch executable + find_package(Patch MODULE REQUIRED) set(PATCH_COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CORE_SOURCE_DIR}/tools/depends/target/rapidjson/001-remove_custom_cxx_flags.patch COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CORE_SOURCE_DIR}/tools/depends/target/rapidjson/002-cmake-removedocs-examples.patch diff --git a/cmake/modules/FindSpdlog.cmake b/cmake/modules/FindSpdlog.cmake index ae5c68aedb..3ba80b1b30 100644 --- a/cmake/modules/FindSpdlog.cmake +++ b/cmake/modules/FindSpdlog.cmake @@ -26,7 +26,7 @@ if(ENABLE_INTERNAL_SPDLOG) if(WIN32 OR WINDOWS_STORE) # find the path to the patch executable - find_program(PATCH_EXECUTABLE NAMES patch patch.exe REQUIRED) + find_package(Patch MODULE REQUIRED) set(patch ${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-windows-pdb-symbol-gen.patch) PATCH_LF_CHECK(${patch}) diff --git a/cmake/scripts/common/ModuleHelpers.cmake b/cmake/scripts/common/ModuleHelpers.cmake index a31286c0bb..6eacdcc84b 100644 --- a/cmake/scripts/common/ModuleHelpers.cmake +++ b/cmake/scripts/common/ModuleHelpers.cmake @@ -217,7 +217,7 @@ endmacro() # Macro to test format of line endings of a patch # Windows Specific macro(PATCH_LF_CHECK patch) - if(WIN32 OR WINDOWS_STORE) + if(CMAKE_HOST_WIN32) # 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 |