我的CMakeLists.txt
包含以下行:
file(GLOB lib_srcs Half/half.cpp Iex/*.cpp IlmThread/*.cpp Imath/*.cpp IlmImf/*.cpp)
并且IlmImf
文件夹包含b44ExpLogTable.cpp
,我需要从构建中排除。
如何实现?
答案 0 :(得分:82)
您可以使用list
功能来操作列表,例如:
list(REMOVE_ITEM <list> <value> [<value> ...])
在你的情况下,也许这样的事情会起作用:
list(REMOVE_ITEM lib_srcs "IlmImf/b44ExpLogTable.cpp")
答案 1 :(得分:22)
FILTER是另一种选择,在某些情况下可能更方便:
list(FILTER lib_srcs EXCLUDE REGEX ".*b44ExpLogTable.cpp$")
此行不包括以所需文件名结尾的所有项目:
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).
这是cmake的Regex Specification:
X=900
Y=200
Q=X/Y = 4.50 // I want to get 100 from results
答案 2 :(得分:1)
尝试: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