string(REGEX REPLACE "(.*)/(.*)/(.*)" "\\1" PROJECT_INIT_PATH ${PROJECT_SOURCE_DIR})
message("上层目录=" $(PROJECT_INIT_PATH))
举例:
PROJECT_SOURCE_DIR=/home/1/2/3/4
用正则表达式对目录进行匹配,最后一次匹配结果:
(/home/1/2)/(3)/(4)
string(REGEX REPLACE "(.*)/(.*)/(.*)" "\\1" PROJECT_INIT_PATH ${PROJECT_SOURCE_DIR}) 结果:/home/1/2
string(REGEX REPLACE "(.*)/(.*)/(.*)" "\\
2" PROJECT_INIT_PATH ${PROJECT_SOURCE_DIR}) 结果:3
string(REGEX REPLACE "(.*)/(.*)/(.*)" "\\
3" PROJECT_INIT_PATH ${PROJECT_SOURCE_DIR}) 结果:4
posted on 2020-05-06 17:09
长戟十三千 阅读(1679)
评论(0) 编辑 收藏 引用 所属分类:
编程技巧随笔