aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhangskz <sandyzhang@google.com>2024-02-14 15:31:23 -0500
committerGitHub <noreply@github.com>2024-02-14 15:31:23 -0500
commitf6b108af4d4074c136285d5621d078d70fbd1d36 (patch)
treeb030720ff55e1d0152d8e418c21bcfc86bb1f969
parentc2773b4dc29568844ed48df7f7a9115f91802cdc (diff)
parent3ad69cf8b07ebcd54e76ee5360586a41b4f9d627 (diff)
downloadprotobuf-f6b108af4d4074c136285d5621d078d70fbd1d36.tar.gz
Merge pull request #15843 from protocolbuffers/cp-cmake
Cherry-pick fixes to install.cmake to escape regex special characters
-rw-r--r--cmake/install.cmake4
1 files changed, 3 insertions, 1 deletions
diff --git a/cmake/install.cmake b/cmake/install.cmake
index 9679d5b26..52914a8ea 100644
--- a/cmake/install.cmake
+++ b/cmake/install.cmake
@@ -78,10 +78,12 @@ foreach(_header ${protobuf_HEADERS})
elseif (_find_nosrc GREATER -1)
set(_from_dir "${protobuf_SOURCE_DIR}")
endif()
+ # Escape _from_dir for regex special characters in the directory name.
+ string(REGEX REPLACE "([$^.[|*+?()]|])" "\\\\\\1" _from_dir_regexp "${_from_dir}")
# On some platforms `_form_dir` ends up being just "protobuf", which can
# easily match multiple times in our paths. We force it to only replace
# prefixes to avoid this case.
- string(REGEX REPLACE "^${_from_dir}" "" _header ${_header})
+ string(REGEX REPLACE "^${_from_dir_regexp}" "" _header ${_header})
get_filename_component(_extract_from "${_from_dir}/${_header}" ABSOLUTE)
get_filename_component(_extract_name ${_header} NAME)
get_filename_component(_extract_to "${CMAKE_INSTALL_INCLUDEDIR}/${_header}" DIRECTORY)