10

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?

villintehaspam
  • 8,540
  • 6
  • 45
  • 76
  • I don't know CMake, but you are right about how the resource files are used. If you want to have them in the CMakeLists.txt file, you have to put them in some target that will not be built, should be something in the documentation. – Some programmer dude Nov 18 '11 at 13:35
  • @JoachimPileborg: Thanks for the info. Yep, the problem is that I don't know CMake either and I haven't found anything in the docs that seem related... :) – villintehaspam Nov 18 '11 at 14:01
  • Found this in some bug reports about MinGW, though looks like it should work? "As someone on IRC hinted I added the resource.h/resource.rc files to the project add_executable() source list." – Tom Kerr Nov 18 '11 at 15:40

2 Answers2

4

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

arrowd
  • 33,231
  • 8
  • 79
  • 110
1

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.

0xbaadf00d
  • 2,535
  • 2
  • 24
  • 46