MantisBT - CMake
View Issue Details
0005455CMakeCCMakepublic2007-08-07 15:322007-12-14 09:31
Philip Lowman 
Brad King 
normalmajoralways
closedfixed 
 
 
0005455: CMake 2.4.7 doesn't preserve LINK_FLAGS properly in VS8 projects
CMake 2.4.7 misparses the LINK_FLAGS option of SET_TARGET_PROPERTIES with the Visual Studio 8 generator and removes options. This problem does not exist on CMake 2.4.6

Example CMakeLists.txt:

PROJECT(FOO)
ADD_EXECUTABLE(foo foo.cc)
SET_TARGET_PROPERTIES(foo PROPERTIES
    LINK_FLAGS "
    /NODEFAULTLIB:\"libc.lib\"
    /NODEFAULTLIB:\"libcmt.lib\"
    /NODEFAULTLIB:\"msvcrt.lib\"
    /NODEFAULTLIB:\"libcd.lib\"
    /NODEFAULTLIB:\"libcmtd.lib\"
    ")

Screenshots of generated command lines are attached for both 2.4.6 and 2.4.7. Curiously, it appears that the only the last /NODEFAULTLIB (libcmtd.lib) gets moved out of the "Additional Options" into the "All Options". The other /NODEFAULTLIB libraries are excluded completely from the CMake generated 2.4.7 VCproj file.
No tags attached.
related to 0004239closed Bill Hoffman Linker parameters do not work as expected in VS2005 
png cmake-2.4.7.png (27,546) 2007-08-07 15:32
https://public.kitware.com/Bug/file/1092/cmake-2.4.7.png
png

png cmake_2.4.6.png (28,672) 2007-08-07 15:33
https://public.kitware.com/Bug/file/1093/cmake_2.4.6.png
png

patch vs_link_flags.patch (2,780) 2007-09-22 08:01
https://public.kitware.com/Bug/file/1156/vs_link_flags.patch
Issue History
2007-08-07 15:32Philip LowmanNew Issue
2007-08-07 15:32Philip LowmanFile Added: cmake-2.4.7.png
2007-08-07 15:33Philip LowmanFile Added: cmake_2.4.6.png
2007-08-24 09:46Philip LowmanNote Added: 0008644
2007-08-29 13:24Brad KingRelationship addedrelated to 0004239
2007-08-29 13:30Brad KingNote Added: 0008741
2007-08-29 13:36Brad KingNote Added: 0008743
2007-08-29 13:57Brad KingStatusnew => assigned
2007-08-29 13:57Brad KingAssigned To => Brad King
2007-08-29 13:57Brad KingStatusassigned => confirmed
2007-09-22 08:01Philip LowmanFile Added: vs_link_flags.patch
2007-09-22 08:05Philip LowmanNote Added: 0009231
2007-11-02 10:13Philip LowmanNote Edited: 0008644
2007-12-06 08:40Bill HoffmanNote Added: 0009840
2007-12-14 09:31Bill HoffmanStatusconfirmed => closed
2007-12-14 09:31Bill HoffmanResolutionopen => fixed
2007-12-14 09:31Bill HoffmanCategory => CCMake

Notes
(0008644)
Philip Lowman   
2007-08-24 09:46   
(edited on: 2007-11-02 10:13)
Here is a curious workaround for this problem. If the user specifies the LINK_FLAGS in the following form CMake 2.4.7 automatically creates multiple /NODEFAULTLIB flags and places them in the "All options" part of the Dialog.

Unfortunately this workaround only works for CMake 2.4.7 and not for CMake 2.4.6.

SET_TARGET_PROPERTIES(foo PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libc.lib;libcmt.lib;msvcrt.lib;libcd.lib;libcmtd.lib")

(0008741)
Brad King   
2007-08-29 13:30   
The reason this did not happen in 2.4.6 is because the flags parser did not support NODEFAULTLIB. The fix to bug 4239 introduced this problem.

Basically the flags parser expects only to see this flag once. Each time it sees the flags it overwrites the previous copy. The value is stored in the "Linker->Input->Ignore Specific Library" property of the target in VS. This is why setting them all at once works around the problem.
(0008743)
Brad King   
2007-08-29 13:36   
In cmLocalVisualStudio7Generator.cxx the method cmLocalVisualStudio7GeneratorOptions::CheckFlagTable contains the lines

          // Use the user-specified value.
          this->FlagMap[entry->IDEName] = flag+1+n;

This always overwrites the value. We need to extend this to support an option for appending to the value instead of overwriting, and specifying a separator to use (';' in the case of NODEFAULTLIB).
(0009231)
Philip Lowman   
2007-09-22 08:05   
Attached is a patch to fix the issue (against CVS).

Also, could the fix for this bug be backported to the 2.4 branch?
(0009840)
Bill Hoffman   
2007-12-06 08:40   
OK, looks like a good fix, but FYI, if you want this to work inside a makefile, you can not have the LINK_FLAGS contain newline characters. You have to have something like this:

SET_TARGET_PROPERTIES(COnly PROPERTIES
    LINK_FLAGS " /NODEFAULTLIB:\"libc.lib\" /NODEFAULTLIB:\"libcmt.lib\" /NODEFAULTLIB:\"msvcrt.lib\" /NODEFAULTLIB:\"libcd.lib\" /NODEFAULTLIB:\"libcmtd.lib\"")

$ cvs commit -m "BUG: fix for bug 5455, handle nodefaultlib with more than one lib" Source/cmLocalVisualStudio7Generator.cxx Source/cmLocalVisualStudio7Generator.h Tests/COnly/CMakeLists.txt
/cvsroot/CMake/CMake/Source/cmLocalVisualStudio7Generator.cxx,v <-- cmLocalVisualStudio7Generator.cxx
new revision: 1.207; previous revision: 1.206
/cvsroot/CMake/CMake/Source/cmLocalVisualStudio7Generator.h,v <-- cmLocalVisualStudio7Generator.h
new revision: 1.45; previous revision: 1.44
/cvsroot/CMake/CMake/Tests/COnly/CMakeLists.txt,v <-- CMakeLists.txt
new revision: 1.11; previous revision: 1.10