gentoo/dev-libs/libmongocrypt/files/inteldfp.patch

134 lines
4.6 KiB
Diff

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4285f3d39..fe09b8857 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,6 +7,10 @@ elseif (DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
message (WARNING "The CMAKE_MSVC_RUNTIME_LIBRARY variable is set, but CMake is too old to understand it")
endif ()
+if (POLICY CMP0135)
+ cmake_policy (SET CMP0135 NEW)
+endif ()
+
project (mongocrypt C)
# Used for the csfle-markup util:
diff --git a/cmake/IntelDFP.cmake b/cmake/IntelDFP.cmake
index da0cdc2fd..cb6bb48d4 100644
--- a/cmake/IntelDFP.cmake
+++ b/cmake/IntelDFP.cmake
@@ -1,7 +1,5 @@
include (FetchContent)
-find_program (GIT_EXECUTABLE git)
-find_program (PATCH_EXECUTABLE patch)
# When updating the version of IntelDFP, also update the version in etc/purls.txt
set (_default_url "${PROJECT_SOURCE_DIR}/third-party/IntelRDFPMathLib20U2.tar.xz")
@@ -19,18 +17,22 @@ if (NOT INTEL_DFP_LIBRARY_URL_SHA256 STREQUAL "no-verify")
set (_hash_arg URL_HASH "${INTEL_DFP_LIBRARY_URL_HASH}")
endif ()
-# Make the PATCH_COMMAND a no-op if it was disabled
-set (patch_command)
-set (patch_input_opt)
if (NOT INTEL_DFP_LIBRARY_PATCH_ENABLED)
- set (patch_command "${CMAKE_COMMAND}" -E true)
-elseif (GIT_EXECUTABLE)
- set (patch_command "${GIT_EXECUTABLE}" --work-tree=<SOURCE_DIR> apply)
-else ()
- set (patch_command "${PATCH_EXECUTABLE}" --dir=<SOURCE_DIR>)
- set (patch_input_opt -i)
+ set (patch_disabled ON)
endif ()
+include (Patch)
+make_patch_command (patch_command
+ STRIP_COMPONENTS 4
+ DIRECTORY "<SOURCE_DIR>"
+ DISABLED "${patch_disabled}"
+ PATCHES
+ "${PROJECT_SOURCE_DIR}/etc/mongo-inteldfp-s390x.patch"
+ "${PROJECT_SOURCE_DIR}/etc/mongo-inteldfp-MONGOCRYPT-571.patch"
+ "${PROJECT_SOURCE_DIR}/etc/mongo-inteldfp-libmongocrypt-pr-625.patch"
+ "${PROJECT_SOURCE_DIR}/etc/mongo-inteldfp-alpine-arm-fix.patch"
+ )
+
# NOTE: The applying of the patch expects the correct input directly from the
# expanded archive. If the patch needs to be reapplied, you may see errors
# about trying to update the intel_dfp component. If you are seeing such
@@ -40,14 +42,7 @@ FetchContent_Declare (
intel_dfp
URL "${_default_url}"
${_hash_arg}
- PATCH_COMMAND
- ${patch_command}
- -p 4 # Strip four path components
- ${patch_input_opt} "${PROJECT_SOURCE_DIR}/etc/mongo-inteldfp-s390x.patch"
- ${patch_input_opt} "${PROJECT_SOURCE_DIR}/etc/mongo-inteldfp-MONGOCRYPT-571.patch"
- ${patch_input_opt} "${PROJECT_SOURCE_DIR}/etc/mongo-inteldfp-libmongocrypt-pr-625.patch"
- ${patch_input_opt} "${PROJECT_SOURCE_DIR}/etc/mongo-inteldfp-alpine-arm-fix.patch"
- --verbose
+ PATCH_COMMAND ${patch_command} --verbose
)
FetchContent_GetProperties (intel_dfp)
diff --git a/cmake/Patch.cmake b/cmake/Patch.cmake
new file mode 100644
index 000000000..057e91a48
--- /dev/null
+++ b/cmake/Patch.cmake
@@ -0,0 +1,52 @@
+find_program(GIT_EXECUTABLE git)
+find_program(PATCH_EXECUTABLE patch)
+
+#[[
+ Form a new Patch-applying command for the given inputs
+
+ make_patch_command(
+ <outvar>
+ [DISABLED <bool>]
+ [DIRECTORY <dir>]
+ [STRIP_COMPONENTS <N>]
+ PATCHES [<file> ...]
+ )
+]]
+function(make_patch_command out)
+ cmake_parse_arguments(PARSE_ARGV 1 patch "" "DIRECTORY;STRIP_COMPONENTS;DISABLED" "PATCHES")
+ if(patch_DISABLED)
+ # Use a placeholder "no-op" patch command.
+ set(cmd "${CMAKE_COMMAND}" "-E" "true")
+ elseif(GIT_EXECUTABLE)
+ # git ...
+ set(cmd ${GIT_EXECUTABLE})
+
+ if(patch_DIRECTORY)
+ # git --work-tree=...
+ list(APPEND cmd --work-tree=${patch_DIRECTORY})
+ endif()
+ # git ... apply ...
+ list(APPEND cmd apply)
+ # git ... apply -pN ...
+ if(patch_STRIP_COMPONENTS)
+ list(APPEND cmd -p${patch_STRIP_COMPONENTS})
+ endif()
+ # git accepts patch filepaths as positional arguments
+ list(APPEND cmd ${patch_PATCHES})
+ else()
+ # patch ...
+ set(cmd ${PATCH_EXECUTABLE})
+ if(patch_DIRECTORY)
+ # patch --dir=...
+ list(APPEND cmd --dir=${patch_DIRECTORY})
+ endif()
+ # patch ... -pN ...
+ if(patch_STRIP_COMPONENTS)
+ list(APPEND cmd -p${patch_STRIP_COMPONENTS})
+ endif()
+ # Prepend "--input=" to each patch filepath and add them to the argv
+ list(TRANSFORM patch_PATCHES PREPEND "--input=")
+ list(APPEND cmd ${patch_PATCHES})
+ endif()
+ set("${out}" "${cmd}" PARENT_SCOPE)
+endfunction()