gpt4 book ai didi

build - 如何从 cmake 中的列表中删除标记?

转载 作者:行者123 更新时间:2023-12-02 07:45:17 25 4
gpt4 key购买 nike

我想在不在 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_source_directory 在每个条目前面加上 ./,因此正确的命令必须是

list(REMOVE_ITEM SRC_LIST ./stdafx.h ./stdafx.cpp)

此外,请确保您了解使用手动调用 aux_source_directory 来维护源文件列表的含义:

It is tempting to use this command to avoid writing the list of source files for a library or executable target. While this seems to work, there is no way for CMake to generate a build system that knows when a new source file has been added. Normally the generated build system knows when it needs to rerun CMake because the CMakeLists.txt file is modified to add a new source. When the source is just added to the directory without modifying this file, one would have to manually rerun CMake to generate a build system incorporating the new file.

引用the documentation for aux_source_directory .

关于build - 如何从 cmake 中的列表中删除标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25364961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com