I want to check if the CMAKE_SOURCE_DIR
variable ends with a specific name. I need to use MATCHES
for it, but it does not seems to work.
I've written:
IF(CMAKE_SOURCE_DIR MATCHES "*MyFolderName")
# code
ENDIF(CMAKE_SOURCE_DIR MATCHES "*MyFolderName")
But it does not work. I obtain the following error:
RegularExpression::compile(): ?+* follows nothing.
RegularExpression::compile(): Error in compile
Want can I do in order to fix the match?
Usually, in regular expressions "*" means "repeat preceding zero or more times". CMake is not exception. For match at the end of string, use $
:
CMAKE_SOURCE_DIR MATCHES "MyFolderName$"
CMake regular expressions are described here.
MATCH
require a regular expression, not a "file glob" (wildcard).
if(CMAKE_SOURCE_DIR MATCHES ".*MyFolderName")
# ...
endif()
or even try this: .*/MyFolderName
. But it also would match /some/MyFolderName/path
... Use .*/MyFolderName$
to match the last path name component.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With