Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Build 如何从cmake中的列表中删除令牌?_Build_Makefile_Cmake - Fatal编程技术网

Build 如何从cmake中的列表中删除令牌?

Build 如何从cmake中的列表中删除令牌?,build,makefile,cmake,Build,Makefile,Cmake,当不在Windows中时,我想从生成中排除一些源文件。 以下CMakeLists.txt cmake文件中有什么错误 aux_source_directory(. SRC_LIST) # Remove Microsoft specific files message(${SRC_LIST}) list(REMOVE_ITEM SRC_LIST stdafx.h stdafx.cpp) message("------------------") message(${SRC_LIST}) 尝

当不在Windows中时,我想从生成中排除一些源文件。
以下CMakeLists.txt cmake文件中有什么错误

aux_source_directory(. SRC_LIST)

# Remove Microsoft specific files
message(${SRC_LIST})

list(REMOVE_ITEM SRC_LIST stdafx.h stdafx.cpp)

message("------------------")
message(${SRC_LIST})
尝试删除这两个文件前后的消息内容完全相同

怎么了?

您必须指定要删除的元素的确切名称

在您的情况下,
aux\u source\u目录
在每个条目前面加上一个
/
,因此必须使用正确的命令

list(REMOVE_ITEM SRC_LIST ./stdafx.h ./stdafx.cpp)
此外,请确保您了解使用手动调用
aux\u source\u目录
来维护源文件列表的含义:

使用此命令可以避免写入源代码列表 库或可执行目标的文件。虽然这似乎有效, CMake无法生成知道 已添加新的源文件。通常生成的构建系统 知道何时需要重新运行CMake,因为CMakeLists.txt文件 已修改以添加新源。当源刚刚添加到 目录,而不修改此文件,则必须手动 重新运行CMake以生成包含新文件的生成系统


引用。

到目前为止,这看起来是正确的。问题可能出在
SRC\u LIST
的内容上。确保它确实是一个列表(即,一个值用分号分隔的字符串),并且它包含
stdafx.h
stdafx.cpp
作为单数(!)元素。我得到了一个未分隔文件的列表:./file1.cpp./file2.cpp./file3.cpp-如何添加分号分隔符?看起来没问题<代码>消息对列表有一种特殊的格式,所以它们看起来一点也不分开。只有当您将空间视为分隔符时才应该担心。