我CMakeLists.txt
包含以下行:
file(GLOB lib_srcs Half/half.cpp Iex/*.cpp IlmThread/*.cpp Imath/*.cpp IlmImf/*.cpp)
并且该IlmImf
文件夹包含b44ExpLogTable.cpp
,我需要从构建中排除该文件夹。
如何实现呢?
Answers:
您可以使用该list
函数来操作列表,例如:
list(REMOVE_ITEM <list> <value> [<value> ...])
在您的情况下,也许这样的事情会起作用:
list(REMOVE_ITEM lib_srcs "IlmImf/b44ExpLogTable.cpp")
CONFIGURE_DEPENDS
并且需要排除由构建生成的文件,这将无济于事。file
调用后列表上的过滤器仍会触发重新生成,对于我而言,我试图避免这种重新生成。
list(FILTER
list(FILTER <list> <INCLUDE|EXCLUDE> REGEX <regular_expression>)
对我来说很好。
FILTER是另一种选择,在某些情况下可能更方便:
list(FILTER <list> <INCLUDE|EXCLUDE> REGEX <regular_expression>)
此行不包括以所需文件名结尾的所有项目:
list(FILTER lib_srcs EXCLUDE REGEX ".*b44ExpLogTable.cpp$")
这是cmake的Regex规范:
The following characters have special meaning in regular expressions:
^ Matches at beginning of input
$ Matches at end of input
. Matches any single character
[ ] Matches any character(s) inside the brackets
[^ ] Matches any character(s) not inside the brackets
- Inside brackets, specifies an inclusive range between
characters on either side e.g. [a-f] is [abcdef]
To match a literal - using brackets, make it the first
or the last character e.g. [+*/-] matches basic
mathematical operators.
* Matches preceding pattern zero or more times
+ Matches preceding pattern one or more times
? Matches preceding pattern zero or once only
| Matches a pattern on either side of the |
() Saves a matched subexpression, which can be referenced
in the REGEX REPLACE operation. Additionally it is saved
by all regular expression-related commands, including
e.g. if( MATCHES ), in the variables CMAKE_MATCH_(0..9).
list(REMOVE_ITEM
list(FILTER ...)
是在cmake v3.6中引入的:stackoverflow.com/a/42167646/3476780
.*test/.*
如果您的项目在目录树中,其中一个父目录称为,则尝试排除可能会排除所有内容mytest
。
试试这个 : CMakeLists.txt
install(DIRECTORY ${CMAKE_SOURCE_DIR}/
DESTINATION ${CMAKE_INSTALL_PREFIX}
COMPONENT copy-files
PATTERN ".git*" EXCLUDE
PATTERN "*.in" EXCLUDE
PATTERN "*/build" EXCLUDE)
add_custom_target(copy-files
COMMAND ${CMAKE_COMMAND} -D COMPONENT=copy-files
-P cmake_install.cmake)
$cmake <src_path> -DCMAKE_INSTALL_PREFIX=<install_path>
$cmake --build . --target copy-files