mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-01 01:41:48 +08:00
6db51d86a9
If a call to `vcpkg_replace_string` makes no changes i.e doesn't effectively replace a string, A warning is logged. This should also help identify ports that no longer need these calls to fix things in `.pc` files etc.
21 lines
812 B
CMake
21 lines
812 B
CMake
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()
|