Simon, I completely agree with your assessment.  The problem is entirely
in that the linker flag /LTCG is not being passed to the static library
linker command-line arguments.  For executable projects and shared
libraries (dlls), the /LTCG flag is passed to the linker correctly (it
appears in the "command-line" page "additional options" section).

The LTCG problem is also present evident with NMake builds:

[ 45%] Building CXX object
Util/CMakeFiles/Util-SL.dir/XMLUtil/XMLWriter.cpp.obj
XMLWriter.cpp
Linking CXX static library ..\build\MT-DLL\Util-SL.lib
XMLWriter.cpp.obj : warning LNK4218: non-native module found; restarting
link with /LTCG
[ 45%] Built target Util-SL

What is happening is if you compile with /GL this embeds LTCG info into
the object file, and then when you go to link, the linker recognizes
this LTCG info and immediately turns on the LTCG option automatically
(and issues the warning).  So this really is a harmless (although quite
annoying) warning.  It may slow down link times due to the extra
overhead involved in restarting the initial link process.

My guess as to why this problem may be occurring in CMake is that this
type of "whole program" optimization is special in that you actually
need to link static libraries in a different manner-- after all the code
generation and initial linking is complete, there is another
compiler/linker pass that does additional inlining and other similar
static library interface/boundary optimizations.  LTCG means "link-time
code generation", which unlike any other linker setting invokes a
post-process compiler/linker optimization phase.  Perhaps CMake just
doesn't pass linker flags to static libraries because it doesn't realize
this type of optimization exists?  Typically the linker phase does not
even occur until the very end of the whole process when finally string
together static libraries to create an executable or dll. 

Luke

-----Original Message-----
From: Simon Sasburg [mailto:[EMAIL PROTECTED] 
Sent: Saturday, October 11, 2008 7:20 PM
To: Luke Kucalaba
Cc: [email protected]
Subject: Re: [CMake] MSVC71 WholeProgramOptimization flag (/LTCG) fixed?

My findings, with visual studio 2008 express, are that you don't
really need to have WholeProgramOptimization=TRUE to fix this warning.
It suffices to add /LTCG to the link options of all executables and
modules.

Unfortunately I'm not able to get cmake to add the /LTCG flag to the
module link flags.
See also here:
http://www.cmake.org/pipermail/cmake/2008-October/024446.html

Also, it seems weird that this flag is reported not to work in VS8+,
as both VS8 Express, and VS9 Express show the whole program
optimization options in the IDE.

>From the error above "cl : Command line warning D9002 : ignoring
unknown option '/LTGC'" i could guess that the flags have slightly
changed:
It seems the compiler (cl.exe) now needs the /GL option to enable
whole program optimization,
and the linkers (lib.exe & link.exe) now need the /LTCG option to enable
it.

On Fri, Oct 10, 2008 at 19:44, Luke Kucalaba <[EMAIL PROTECTED]> wrote:
> I posted an issue on the mantis bug tracker a while ago regarding
supporting the /LTCG option for the MSVC71 generator.  The issue history
indicates this problem is fixed, but with CMake 2.6.2 the correct flags
are still not being generated for the MSVC71 project files and nmake
makefiles.  Fortunately, the MSVC compiler/linker is smart enough to
realize this and restarts the link using /LTCG.  The only bad thing
about this is it extends the time required to link because it has to
restart the link again.

>
> Some details are provided below.  Thanks in advance!
> Luke
>
> -----------------------
> NMake output:
> -----------------------
> Linking CXX static library ..\build\MT-DLL\Util-SL.lib
> XMLWriter.cpp.obj : warning LNK4218: non-native module found;
restarting link with /LTCG
>
> -----------------------
> MSVC71 output:
> -----------------------
> Timer.obj : warning LNK4218: non-native module found; restarting link
with /LTCG
>
> -----------------------------
> Here's the original issue:
> -----------------------------
>
> Summary 0006794: Visual Studio compiler 'WholeProgramOptimization'
(/LTCG)
>
> Description
>
> Hi,
>
> The cl.exe compiler option /LTCG (i.e. "WholeProgramOptimization")
does not seem to be generated correctly into the Visual Studio project
file. This error occurs in Visual Studio .NET 2003 (v7.1), and probably
occurs in later versions as well.
>
> The /LTCG is a whole configuration setting, which should be added to
the "Configuration" xml tag in the vcproj file as in the following
example:
>
>   <Configuration
>     Name="Release|Win32"
>     OutputDirectory="Release"
>     . . .
>     WholeProgramOptimization="TRUE">
>
> This should be an easy fix. Please feel free to contact me with any
questions you may have.
>
> Thanks!
> Luke
>
> (0013076)
> bill.hoffman (manager)
> 2008-08-19 15:09
> Committer: Bill Hoffman <[EMAIL PROTECTED]>
> /cvsroot/CMake/CMake/Source/cmGlobalVisualStudio7Generator.cxx,v <--
cmGlobalVisualStudio7Generator.cxx
> new revision: 1.101; previous revision: 1.100
>
> BTW, this flag is not supported in VS8 and greater:
> cl : Command line warning D9002 : ignoring unknown option '/LTGC'
>
> Issue History
> Date Modified Username Field Change
> 2008-04-11 15:49 lkucalaba New Issue
> 2008-08-19 15:09 bill.hoffman Status new => closed
> 2008-08-19 15:09 bill.hoffman Note Added: 0013076
> 2008-08-19 15:09 bill.hoffman Resolution open => fixed
>
> _______________________________________________
> CMake mailing list
> [email protected]
> http://www.cmake.org/mailman/listinfo/cmake
>
_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to