MantisBT - CMake
View Issue Details
0006834CMakeCMakepublic2008-04-17 04:282008-04-22 11:11
Gerhard Grimm 
Bill Hoffman 
normalmajoralways
closedfixed 
CMake-2-6 
 
0006834: NMake Makefiles generator passes all compile flags of a target to the resource compiler, causing rc or link errors
The attached example builds a shared and a static library from the same source, using the shared and static versions of the MSVC runtime. To accomplish this, the COMPILE_FLAGS properties of the targets are set to /MDd resp. /MTd.
The shared library includes a version resource, too. Building this example with Visual Studio .NET 2003 using project files (use config_mvs7.bat in the "build" directory) succeeds as expected.
However, when using NMake Makefiles (use config_nmake.bat), a linker error occurs when linking the shared library. The linker chokes on an invalid .RES file created by the resource compiler, because the /MDd option intended for the C compiler was passed to it as well.
Only /I and /D flags should be passed to the resource compiler, just as the Visual Studio generator does it.
Setting the /MDd resp. /MTd flag in the source file's COMPILE_FLAGS property won't help, since it's the same source file for both targets - they would be compiled with the same flag setting, causing one of them to be incorrectly built.
No tags attached.
zip CMakeBug.zip (3,819) 2008-04-17 04:28
https://public.kitware.com/Bug/file/1410/CMakeBug.zip
Issue History
2008-04-17 04:28Gerhard GrimmNew Issue
2008-04-17 04:28Gerhard GrimmFile Added: CMakeBug.zip
2008-04-21 18:05Bill HoffmanStatusnew => assigned
2008-04-21 18:05Bill HoffmanAssigned To => Bill Hoffman
2008-04-21 18:09Bill HoffmanNote Added: 0011466
2008-04-22 03:23Gerhard GrimmNote Added: 0011472
2008-04-22 11:11Bill HoffmanNote Added: 0011477
2008-04-22 11:11Bill HoffmanStatusassigned => closed
2008-04-22 11:11Bill HoffmanNote Added: 0011478
2008-04-22 11:11Bill HoffmanResolutionopen => fixed

Notes
(0011466)
Bill Hoffman   
2008-04-21 18:09   
As a work around, can you use set_source_files_properties instead of set_target_properties and not set those flags on the .rc file?
(0011472)
Gerhard Grimm   
2008-04-22 03:23   
Hi Bill, as I outlined in "Additional Information" above, doing so would cause one of the two libraries to be built incorrectly, i.e. with the wrong runtime flag in effect, since they are using the same source file (which has only a single COMPILE_FLAGS property that can't be set to different values per target - the setting defined last "wins" and is used for both targets).
(0011477)
Bill Hoffman   
2008-04-22 11:11   
OK, I came up with something that works, and allow for RC to exclude flags it does not want in the makefiles.

$ cvs commit -m "BUG: fix for bug 6834 RC should not get all COMPILE_FLAGS from a target and should work the same way as it does in the vs ide" Modules/CMakeRCInformation.cmake Source/cmMakefileTargetGenerator.cxx
/cvsroot/CMake/CMake/Modules/CMakeRCInformation.cmake,v <-- Modules/CMakeRCInformation.cmake
new revision: 1.6; previous revision: 1.5
/cvsroot/CMake/CMake/Source/cmMakefileTargetGenerator.cxx,v <-- Source/cmMakefileTargetGenerator.cxx
new revision: 1.98; previous revision: 1.97
(0011478)
Bill Hoffman   
2008-04-22 11:11   
Should be fixed now in CVS.