`if( ... MATCHES ...)` should first preprocess the path contains special characters
Hi, see you again.
We received an issue about the MATCHES
expression in https://github.com/microsoft/vcpkg/issues/21154.
The user installed vcpkg in the path containing the special characters +
used in regular expressions and got the error message:
CMake Error at cmake/OpenCVUtils.cmake:90 (if):
if given arguments:
"C:/C++/vcpkg/buildtrees/opencv2/x64-windows-dbg" "MATCHES" "^C:/C++/vcpkg/buildtrees/opencv2/src/2.4.13.7-64eb3208d2.clean" "OR" "C:/C++/vcpkg/buildtrees/opencv2/x64-windows-dbg" "MATCHES" "^C:/C++/vcpkg/buildtrees/opencv2/x64-windows-dbg"
Regular expression
"^C:/C++/vcpkg/buildtrees/opencv2/src/2.4.13.7-64eb3208d2.clean" cannot
compile
Call Stack (most recent call first):
CMakeLists.txt:351 (ocv_include_directories)
The origin code is:
if("${__abs_dir}" MATCHES "^${OpenCV_SOURCE_DIR}" OR "${__abs_dir}" MATCHES "^${OpenCV_BINARY_DIR}")
Since the system allows this directory to be generated, and the left and right directories of the expression are enclosed in double quotes "
, I think this should be a cmake bug.
We can use the following code to reproduce this issue:
set(__abs_dir "C:/C++/vcpkg/buildtrees/opencv2/x64-windows-dbg")
set(OpenCV_SOURCE_DIR "^C:/C++/vcpkg/buildtrees/opencv2/src/2.4.13.7-64eb3208d2.clean")
set(OpenCV_BINARY_DIR "^C:/C++/vcpkg/buildtrees/opencv2/x64-windows-dbg")
if("${__abs_dir}" MATCHES "^${OpenCV_SOURCE_DIR}" OR "${__abs_dir}" MATCHES "^${OpenCV_BINARY_DIR}")
endif()
In my opinion, if the left and right content of MATCHES
contains these special characters, it must be preprocessed to add \
in front of them.
Any ideas?
Thanks.
Edited by Jack·Boos·Yu