mirror of
https://gitee.com/zyjblog/oatpp.git
synced 2024-12-22 22:16:37 +08:00
Create file lists without using regular expression
Using the path prefix as part of a regular expression can lead to a regular expression injection, the path might contain regular expression meta characters that get interpreted. Use cmake_path() instead to filter path prefixes.
This commit is contained in:
parent
7e520ec646
commit
7467f14193
@ -62,10 +62,17 @@ function(set_target_source_groups arg_TARGET)
|
|||||||
# Normally, the build tree is a subdirectory of the source tree. For the root directory the prefix match
|
# Normally, the build tree is a subdirectory of the source tree. For the root directory the prefix match
|
||||||
# will also match the binary tree, so create separate file lists by filtering the binary prefix explicit.
|
# will also match the binary tree, so create separate file lists by filtering the binary prefix explicit.
|
||||||
# This will fail when doing an in-tree build, in that case everything will be classified as binary.
|
# This will fail when doing an in-tree build, in that case everything will be classified as binary.
|
||||||
set(sourceFiles ${fileSources})
|
set(sourceFiles "")
|
||||||
list(FILTER sourceFiles EXCLUDE REGEX "^${binaryDir}/")
|
set(binaryFiles "")
|
||||||
set(binaryFiles ${fileSources})
|
foreach(file IN LISTS fileSources)
|
||||||
list(FILTER binaryFiles INCLUDE REGEX "^${binaryDir}/")
|
cmake_path(IS_PREFIX sourceDir "${file}" isSourceFile)
|
||||||
|
cmake_path(IS_PREFIX binaryDir "${file}" isBinaryFile)
|
||||||
|
if(isBinaryFile)
|
||||||
|
list(APPEND binaryFiles "${file}")
|
||||||
|
elseif(isSourceFile)
|
||||||
|
list(APPEND sourceFiles "${file}")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
set(filterSources ${sourceFiles})
|
set(filterSources ${sourceFiles})
|
||||||
list(FILTER filterSources INCLUDE REGEX "^${sourceDir}/.+\\.h(h|pp)?$")
|
list(FILTER filterSources INCLUDE REGEX "^${sourceDir}/.+\\.h(h|pp)?$")
|
||||||
@ -106,9 +113,16 @@ function(set_target_source_groups arg_TARGET)
|
|||||||
if(DEFINED arg_EXTRA_BINARY_DIRECTORY)
|
if(DEFINED arg_EXTRA_BINARY_DIRECTORY)
|
||||||
# If the specified directory contains the binary dir of the target, the files will get added
|
# If the specified directory contains the binary dir of the target, the files will get added
|
||||||
# twice with a different path, so exclude that directory.
|
# twice with a different path, so exclude that directory.
|
||||||
set(filterSources ${fileSources})
|
set(filterSources "")
|
||||||
list(FILTER filterSources INCLUDE REGEX "^${arg_EXTRA_BINARY_DIRECTORY}/")
|
foreach(file IN LISTS fileSources)
|
||||||
list(FILTER filterSources EXCLUDE REGEX "^${binaryDir}/")
|
cmake_path(IS_PREFIX arg_EXTRA_BINARY_DIRECTORY "${file}" isExtraBinaryFile)
|
||||||
|
if(isExtraBinaryFile)
|
||||||
|
cmake_path(IS_PREFIX binaryDir "${file}" isBinaryFile)
|
||||||
|
if(NOT isBinaryFile)
|
||||||
|
list(APPEND filterSources "${file}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
source_group(
|
source_group(
|
||||||
TREE "${arg_EXTRA_BINARY_DIRECTORY}"
|
TREE "${arg_EXTRA_BINARY_DIRECTORY}"
|
||||||
PREFIX "Generated Files"
|
PREFIX "Generated Files"
|
||||||
|
Loading…
Reference in New Issue
Block a user