CMake 和 Visual Studio 资源文件

发布于 2024-12-17 05:37:41 字数 492 浏览 2 评论 0原文

我正在将使用 Visual Studio 2005 创建的 C++ 项目转换为 CMake,并且偶然发现项目中包含的资源文件存在一些问题。

该项目包括一个 .rc 文件、一堆 .ico 文件和一个 .rc2 文件。

常规的 .rc 文件在生成的项目中工作正常并使用资源编译器。然而,.ico.rc2 文件在刚刚包含时会引起问题,因为在生成的项目中,Visual Studio 尝试使用 C/C++ 编译器来编译它们。

我假设这些文件包含在 .rc 文件中,因此不将它们包含在 CMakeLists.txt 文件中可能会起作用,但因为显然可以将它们列出在项目中(它们在原始项目中可见)我想这样做,以便生成项目的用户可以看到这些文件正在被使用。

在 CMake 中处理这些额外的 VS 资源文件的正确方法是什么?

I am converting a C++ project created using Visual Studio 2005 to CMake and have stumbled upon a bit of a problem with resource files that are included in the project.

The project includes a .rc file, a bunch of .ico files and a .rc2 file.

The regular .rc file works fine in the generated project and uses the resource compiler. The .ico and .rc2 files however are causing problems when they are just being included, because in the generated project Visual Studio attempts to compile them using the C/C++ compiler.

I assume that these files are included by the .rc file, so it would probably work to just not include them in the CMakeLists.txt file, but since it is obviously possible to list them in the project (they are visible in the original project) I would like to do so, so that the user of the generated project can see that these files are being used.

What is the correct way to handle these extra VS resource files in CMake?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

勿忘初心 2024-12-24 05:37:41

尝试set_source_files_properties(your.ico your.rc2 PROPERTIES LANGUAGE RC)

Try to set_source_files_properties(your.ico your.rc2 PROPERTIES LANGUAGE RC).

忘东忘西忘不掉你 2024-12-24 05:37:41

默认情况下,它不应该对这些文件执行任何操作。源文件属性 LANGUAGE 应为空,因此应按文件类型检查文件的操作。这不应该是什么,因为它不应该编译。

检查您的 CMakeLists.txt 是否不包含会干扰该属性的 set_source_files_properties 命令。

如果您想对这些文件执行某些操作,可以使用以下两种方法:

使用 add_custom_target,您可以添加它们并在构建项目时为它们运行自定义命令。假设文件已更改。

如果需要,使用configure_file,您可以轻松地将它们复制到构建目录。带有 COPYONLY 标志。

By default it shouldn't do anything with those files. The source file property LANGUAGE should be empty and thus the action for the file should be checked by the file type. Which shouldn't be anything since it's not something it should compile.

Check your CMakeLists.txt that is doesn't contain a set_source_files_properties command that would mess with that property.

If you want to do something with the files, here are two ways to do things:

With add_custom_target you can add them and run custom commands for them when you build the project. Granted that the files have changed.

With configure_file you can easily copy them to a build directory if needed. With the COPYONLY flag.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文