CMake和Visual Studio资源文件 [英] CMake and Visual Studio resource files
问题描述
我将使用Visual Studio 2005创建的C ++项目转换为CMake,并且偶尔遇到项目中包含的资源文件的一个问题。
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.
该项目包括 .rc
文件,一堆 .ico
文件和 .rc2
The project includes a .rc
file, a bunch of .ico
files and a .rc2
file.
正常的 .rc
文件在生成的项目中正常工作资源编译器。然而, .ico
和 .rc2
文件导致问题,当他们只是被包括在内,因为在生成的项目Visual Studio尝试使用C / C ++编译器来编译它们。
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.
我假设这些文件包含在 .rc
文件,所以它可能工作,只是不包括他们在CMakeLists.txt文件,但由于它显然可以列出他们在项目中(他们是可见的原始项目)我想这样做,
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.
在CMake中处理这些额外的VS资源文件的正确方法是什么?
推荐答案
默认情况下不应该对这些文件做任何事情。源文件属性LANGUAGE应为空,因此应通过文件类型检查文件的操作。它不应该是任何东西,因为它不是应该编译的东西。
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.
检查您的CMakeLists.txt,它不包含set_source_files_properties命令,会混乱的属性。
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:
使用add_custom_target您可以添加它们并在构建项目时为它们运行自定义命令。授予文件已更改。
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.
使用configure_file,您可以根据需要轻松地将它们复制到构建目录。使用COPYONLY标志。
With configure_file you can easily copy them to a build directory if needed. With the COPYONLY flag.
这篇关于CMake和Visual Studio资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!