aboutsummaryrefslogtreecommitdiff
path: root/vcpkg/scripts/cmake/vcpkg_replace_string.cmake
diff options
context:
space:
mode:
authorEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
committerEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
commit54409423f767d8b1cf30cb7d0efca6b4ca138823 (patch)
treed915ac7828703ce4b963efdd9728a1777ba18c1e /vcpkg/scripts/cmake/vcpkg_replace_string.cmake
move to own git serverHEADmaster
Diffstat (limited to 'vcpkg/scripts/cmake/vcpkg_replace_string.cmake')
-rw-r--r--vcpkg/scripts/cmake/vcpkg_replace_string.cmake20
1 files changed, 20 insertions, 0 deletions
diff --git a/vcpkg/scripts/cmake/vcpkg_replace_string.cmake b/vcpkg/scripts/cmake/vcpkg_replace_string.cmake
new file mode 100644
index 0000000..1778f6e
--- /dev/null
+++ b/vcpkg/scripts/cmake/vcpkg_replace_string.cmake
@@ -0,0 +1,20 @@
+function(vcpkg_replace_string filename match replace)
+ cmake_parse_arguments(PARSE_ARGV 3 "arg" "REGEX;IGNORE_UNCHANGED" "" "")
+ if(arg_REGEX)
+ set(arg_REGEX "REGEX")
+ else()
+ if("${match}" STREQUAL "${replace}")
+ return() # Avoid reading the file or triggering warnings
+ endif()
+
+ set(arg_REGEX "")
+ endif ()
+ file(READ "${filename}" contents)
+ string(SHA512 before_hash "${contents}")
+ string(${arg_REGEX} REPLACE "${match}" "${replace}" contents "${contents}")
+ string(SHA512 after_hash "${contents}")
+ if(NOT arg_IGNORE_UNCHANGED AND "${before_hash}" STREQUAL "${after_hash}")
+ message("${Z_VCPKG_BACKCOMPAT_MESSAGE_LEVEL}" "vcpkg_replace_string made no changes.")
+ endif()
+ file(WRITE "${filename}" "${contents}")
+endfunction()