MantisBT - CMake
View Issue Details
0007476CMakeCMakepublic2008-08-09 22:152008-08-10 11:03
c0uch 
 
normalmajoralways
closedno change required 
CMake-2-6 
 
0007476: CMAKE_EXE_LINKER_FLAGS can produce bad solution configuration for VS2005 and 2008
Adding the following to a basic cmake project (cmakelist.txts attached) results in the following issues:

SET(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} " /NODEFAULTLIB:MSVCRT ")

1. If the value added (in this case " NODEFAULTLIB:MSVCRT ") does not have a blank space between the opening " and the text the linker additional commandline options entry is messed up:
 /STACK:10000000 /machine:I386";" /debug
(a mysterious ";")

2. If 2 modifications are made:
  SET(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} " /NODEFAULTLIB:MSVCRT ")
  SET(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} " /INCREMENTAL:NO ")
The second one appears to be ignored completely in the resulting sln file.

3. If you print out the value of CMAKE_EXE_LINKER_FLAGS they appear to be correct:
message("CMAKE_EXE_LINKER_FLAGS: " ${CMAKE_EXE_LINKER_FLAGS})
Produces:
CMAKE_EXE_LINKER_FLAGS: /MANIFEST /STACK:10000000 /machine:I386 /NODEFAULTLIB:MSVCRT /INCREMENTAL:NO
However, if you print it out again, in a separate cmakelists.txt file, the .sln is further modified (another ";" appears somewhere which I haven't yet been able to locate, but which causes linking to fail completely)
No tags attached.
zip example_linker_options_fail.zip (1,813) 2008-08-09 22:15
https://public.kitware.com/Bug/file/1660/*
Issue History
2008-08-09 22:15c0uchNew Issue
2008-08-09 22:15c0uchFile Added: example_linker_options_fail.zip
2008-08-09 22:24c0uchNote Added: 0012977
2008-08-10 11:03Bill HoffmanNote Added: 0012978
2008-08-10 11:03Bill HoffmanStatusnew => closed
2008-08-10 11:03Bill HoffmanResolutionopen => no change required

Notes
(0012977)
c0uch   
2008-08-09 22:24   
Looks like this may have just been a case of naivety on my part.

If I use
SET_TARGET_PROPERTIES(idkfa PROPERTIES LINK_FLAGS " /NODEFAULTLIB:MSVCRT /INCREMENTAL:NO")
instead then everything seems to work fine.

The method I was using (and what this ticket was about) is mentioned a few times in google searches for cmake link flags, so maybe there should be some note somewhere if one way is better than the other (in the reference documentation?)
(0012978)
Bill Hoffman   
2008-08-10 11:03   
Please see these:

http://www.cmake.org/HTML/syntax.html [^]
http://www.cmake.org/Wiki/CMake/Language_Syntax [^]

You want this:

SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:MSVCRT ")

The ; is the list separator for cmake, so set(a b c) would be a;b;c. If you put the whole expression in "" then it will work fine.