105

CMakeLists.txtには次の行が含まれています:

file(GLOB lib_srcs Half/half.cpp Iex/*.cpp IlmThread/*.cpp Imath/*.cpp IlmImf/*.cpp)

IlmImfフォルダーにはb44ExpLogTable.cpp、ビルドから除外する必要のあるが含まれています。

それを達成する方法は?

4

4 に答える 4

122

この関数を使用してlist、リストを操作できます。次に例を示します。

list(REMOVE_ITEM <list> <value> [<value> ...])

あなたの場合、多分このようなものがうまくいくでしょう:

list(REMOVE_ITEM lib_srcs "IlmImf/b44ExpLogTable.cpp")
于 2013-03-21T15:12:22.117 に答える
60

FILTERは、場合によってはより便利な別のオプションです。

list(FILTER <list> <INCLUDE|EXCLUDE> REGEX <regular_expression>)

この行は、必要なファイル名で終わるすべてのアイテムを除外します。

list(FILTER lib_srcs EXCLUDE REGEX ".*b44ExpLogTable\\.cpp$")

cmakeの正規表現仕様は次のとおりです。

The following characters have special meaning in regular expressions:

^         Matches at the beginning of input
$         Matches at the 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).
于 2018-03-20T05:57:13.697 に答える
3

これを試して :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
于 2020-01-30T12:22:53.087 に答える
0

注目に値する別の解決策があります。ソースをヘッダーファイルとしてマークします。このように、ビルドプロセスの一部ではありませんが、IDEで表示されます(Visual StudioおよびXcodeで確認済み)。

set_source_files_properties(b44ExpLogTable.cpp,
                            PROPERTIES HEADER_FILE_ONLY TRUE)

一部のソースファイルがプラットフォーム固有である場合にこれを使用します。いくつかのシンボルを多くの場所で変更し、1つのプラットフォームで作業する必要がある場合、他のプラットフォーム固有のソースが表示され、更新することもできるので、これは素晴らしいことです。

そのために、現在のプロジェクトでうまく機能するヘルパー関数を作成しました。

私はまだファイルGLOBでこのメソッドを使用していません。

于 2022-02-23T13:21:59.167 に答える