MantisBT - CMake
View Issue Details
0014933CMake(No Category)public2014-05-24 15:292014-11-03 08:38
Mathäus Mendel 
 
normalminoralways
closedno change required 
Visual Studio (NMake)WindowsAny
CMake 2.8.12.2 
 
0014933: CMake set wrong flags to RC compiler
The Microsoft Resource Compiler fails to compile any resource file that have an #include directive. Generating the following error:

fatal error RC1015: cannot open include file '<filename>.h'.

Where <filename> is any file you may include.
On the CMakeLists.txt, add the following instruction:

add_definitions(-WX) # treat warnings as errors.

And create a target with a .rc file on it's source list.
CMake is passing the CXX/C compiler flags to the Resource Compiler, which it should not.

On Modules/Platform/Windows-MSVC.cmake:59

# make sure to enable languages after setting configuration types
enable_language(RC)
set(CMAKE_COMPILE_RESOURCE "rc <FLAGS> /fo<OBJECT> <SOURCE>")

The MSVC compiler flag -WX will tell the Resource compiler to "ignore the INCLUDE env variable and warn on invalid code page", thus, breaking the build.

My recommendation is to remove the <FLAGS> from the directive, since all the compiler flags are meaningless to the Resource compiler, and/or create a new one that will directly reflect the user intention to change the RC compiler behavior, like <RC_FLAGS>.
No tags attached.
zip cmake-rc-bug.zip (771) 2014-05-24 15:29
https://public.kitware.com/Bug/file/5151/cmake-rc-bug.zip
Issue History
2014-05-24 15:29Mathäus MendelNew Issue
2014-05-24 15:29Mathäus MendelFile Added: cmake-rc-bug.zip
2014-05-24 15:46Mathäus MendelNote Added: 0035927
2014-05-27 10:06Brad KingNote Added: 0035942
2014-05-27 18:47Mathäus MendelNote Added: 0035950
2014-05-28 08:32Brad KingStatusnew => resolved
2014-05-28 08:32Brad KingResolutionopen => no change required
2014-11-03 08:38Robert MaynardNote Added: 0037144
2014-11-03 08:38Robert MaynardStatusresolved => closed

Notes
(0035927)
Mathäus Mendel   
2014-05-24 15:46   
The bug is also reproducible with CMake 3.0rc6.
(0035942)
Brad King   
2014-05-27 10:06   
We have a filter for flags added to rc invocations. See CMAKE_RC_FLAG_REGEX here:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/CMakeRCInformation.cmake;hb=v3.0.0-rc6#l36 [^]

However, it looks like the filter is not enforced for the add_definitions command, perhaps because that was intended for preprocessor definitions. The filter works on the COMPILE_FLAGS target property.

CMake 2.8.12 and above have a COMPILE_OPTIONS target property that also obeys the filter. One can use the add_compile_options command instead:

cmake_minimum_required(VERSION 2.8.12)
project(cmake-rc-bug)

add_compile_options(-WX)

add_executable(${PROJECT_NAME} main.cpp bug.rc)
(0035950)
Mathäus Mendel   
2014-05-27 18:47   
Well, it seems there is no easy way to avoid this issue when using add_definitions to pass flags directly to the compiler.

I think this issue can be closed. Thanks for helping. :)
(0037144)
Robert Maynard   
2014-11-03 08:38   
Closing resolved issues that have not been updated in more than 4 months.