简体   繁体   English

CMake和Visual Studio资源文件

[英]CMake and Visual Studio resource files

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. 我正在将使用Visual Studio 2005创建的C ++项目转换为CMake,并且偶然发现了项目中包含的资源文件的一些问题。

The project includes a .rc file, a bunch of .ico files and a .rc2 file. 该项目包括.rc文件,一堆.ico文件和.rc2文件。

The regular .rc file works fine in the generated project and uses the resource compiler. 常规.rc文件在生成的项目中正常工作并使用资源编译器。 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. 然而, .ico.rc2文件在被包含时会引起问题,因为在生成的项目中,Visual Studio尝试使用C / C ++编译器编译它们。

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. 我假设这些文件包含在.rc文件中,因此可能只是不将它们包含在CMakeLists.txt文件中,但是因为显然可以在项目中列出它们(它们在原始项目中可见) )我想这样做,以便生成的项目的用户可以看到正在使用这些文件。

What is the correct way to handle these extra VS resource files in CMake? 在CMake中处理这些额外VS资源文件的正确方法是什么?

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

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. 源文件属性LANGUAGE应为空,因此应通过文件类型检查文件的操作。 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. 检查您的CMakeLists.txt,它不包含会破坏该属性的set_source_files_properties命令。

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. 使用add_custom_target,您可以在构建项目时添加它们并为它们运行自定义命令。 Granted that the files have changed. 假设文件已更改。

With configure_file you can easily copy them to a build directory if needed. 使用configure_file,您可以根据需要轻松将它们复制到构建目录。 With the COPYONLY flag. 带有COPYONLY标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM