My CMakeLists.txt
contiene questa riga:
file(GLOB lib_srcs Half/half.cpp Iex/*.cpp IlmThread/*.cpp Imath/*.cpp IlmImf/*.cpp)
e la IlmImf
cartella contiene b44ExpLogTable.cpp
, che devo escludere dalla build.
Come ottenerlo?
Risposte:
È possibile utilizzare la list
funzione per manipolare l'elenco, ad esempio:
list(REMOVE_ITEM <list> <value> [<value> ...])
Nel tuo caso, forse qualcosa del genere funzionerà:
list(REMOVE_ITEM lib_srcs "IlmImf/b44ExpLogTable.cpp")
CONFIGURE_DEPENDS
e devi escludere un file prodotto dalla build. Un filtro nell'elenco dopo la file
chiamata attiva ancora una ricostruzione che, nel mio caso, sto cercando di evitare.
list(FILTER
list(FILTER <list> <INCLUDE|EXCLUDE> REGEX <regular_expression>)
funziona bene per me.
FILTER è un'altra opzione che potrebbe essere più conveniente in alcuni casi:
list(FILTER <list> <INCLUDE|EXCLUDE> REGEX <regular_expression>)
Questa riga esclude ogni elemento che termina con il nome file richiesto:
list(FILTER lib_srcs EXCLUDE REGEX ".*b44ExpLogTable.cpp$")
Ecco la specifica Regex per cmake:
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 ...)
è stato introdotto nel cmake v3.6: stackoverflow.com/a/42167646/3476780
.*test/.*
potrebbe escludere tutto se il progetto si trova all'interno di un albero di directory in cui una delle directory principali è chiamata qualcosa di simile mytest
.
prova questo : 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