[CMake] Link Time Code Generation (LTGC) by default, for Release configurations of Visual Studio projects?

Mueller-Roemer, Johannes Sebastian Johannes.Sebastian.Mueller-Roemer at igd.fraunhofer.de
Thu Jan 25 08:54:14 EST 2018


This would be a great feature! Currently I override my release flags by setting CMAKE_<LANG>_FLAGS_RELEASE_INIT and CMAKE_<TYPE>_LINKER_FLAGS_RELEASE_INIT in a CMAKE_USER_MAKE_RULES_OVERRIDE script. Direct support for /GL and /LTCG in CMake would be great. Fewer target specifics to worry about…

Fraunhofer-Institut für Graphische Datenverarbeitung IGD
Fraunhoferstr. 5  |  64283 Darmstadt  |  Germany
Tel +49 6151 155-606  |  Fax +49 6151 155-139
johannes.mueller-roemer at igd.fraunhofer.de<mailto:johannes.mueller-roemer at igd.fraunhofer.de> | www.igd.fraunhofer.de<http://www.igd.fraunhofer.de>

From: CMake [mailto:cmake-bounces at cmake.org] On Behalf Of Cristian Adam
Sent: Wednesday, January 24, 2018 21:42
To: Niels Dekker <niels_dekker_address_until_2024 at xs4all.nl>
Cc: cmake <cmake at cmake.org>
Subject: Re: [CMake] Link Time Code Generation (LTGC) by default, for Release configurations of Visual Studio projects?

Hi,

I had a quick check to see if CMake 3.10 for which compilers it has support for Interprocedural Optimization<https://cmake.org/cmake/help/v3.10/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.html#prop_tgt:INTERPROCEDURAL_OPTIMIZATION> (IPO, or LTCG as known on Visual C++).

Modules/Compiler had only for GNU, Clang and PGI the following:
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)

QNX with QCC didn't have it set to YES even though nowdays QNX comes with GCC 5.4.0 on QNX 7.0, which should be just fine.

It would be nice if CMake would have support for IPO on Visual C++.

The steps would be to set the right variables into Modules/Compiler/MSVC-CXX.cmake, change the CheckIPOSupported<https://cmake.org/cmake/help/v3.10/module/CheckIPOSupported.html?#module:CheckIPOSupported> module, change some flags in some places,update tests, documentation, and so on.

Shouldn't be hard to add this feature.

Cheers,
Cristian.



On Wed, Jan 24, 2018 at 9:06 PM, Niels Dekker <niels_dekker_address_until_2024 at xs4all.nl<mailto:niels_dekker_address_until_2024 at xs4all.nl>> wrote:
When a Visual C++ project is created within Visual Studio (by File menu, New, Project...), it has Link Time Code Generation (LTGC) by default, for its Release configurations: Compiler option /GL and linker option /LTCG. However, when the Visual C++ project is generated by CMake, it does not have LTGC, by default. LTCG looks like a very useful feature to me. I think it's worth enabling the feature by default, for Release configurations. What do you think?


Some details:

I created a "dummy" Visual C++ project in Visual Studio 2017 (Version 15.5.4), by File menu, New, Project..., and I also generated one by CMake (version 3.10.2), using a very minimal CMakeLists.txt

The Visual C++ project created by Visual Studio 2017 has the following compile options, by default, for Release (x64):

/permissive- /GS /GL /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"x64\Release\vc141.pdb" /Zc:inline /fp:precise /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /Fp"x64\Release\MyVS2015Project.pch" /diagnostics:classic

And the following linker options:

/OUT:"F:\X\Src\MyProject\MyVS2015Project\x64\Release\MyVS2015Project.exe" /MANIFEST /LTCG:incremental /NXCOMPAT /PDB:"F:\X\Src\MyProject\MyVS2015Project\x64\Release\MyVS2015Project.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG:FULL /MACHINE:X64 /OPT:REF /PGD:"F:\X\Src\MyProject\MyVS2015Project\x64\Release\MyVS2015Project.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Release\MyVS2015Project.exe.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /TLBID:1

The vcxproj file created by Visual Studio has "<WholeProgramOptimization>true</WholeProgramOptimization>" for its Release configurations.


The Visual C++ project generated by CMake (Generator: Visual Studio 15 2017 Win64) has the following compile options, for its Release configuration:

/GS /TP /W3 /Zc:wchar_t /Gm- /O2 /Ob2 /Fd"MyExecutable.dir\Release\vc141.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_WINDOWS" /D "NDEBUG" /D "CMAKE_INTDIR=\"Release\"" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /GR /Gd /MD /Fa"Release/" /EHsc /nologo /Fo"MyExecutable.dir\Release\" /Fp"MyExecutable.dir\Release\MyExecutable.pch" /diagnostics:classic

And the following linker options:

/OUT:"F:\X\Bin\vc141-64\MyProject\Release\MyExecutable.exe" /MANIFEST /NXCOMPAT /PDB:"F:/X/Bin/vc141-64/MyProject/Release/MyExecutable.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" /IMPLIB:"F:/X/Bin/vc141-64/MyProject/Release/MyExecutable.lib" /MACHINE:X64 /INCREMENTAL:NO /PGD:"F:\X\Bin\vc141-64\MyProject\Release\MyExecutable.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"MyExecutable.dir\Release\MyExecutable.exe.int<http://MyExecutable.exe.int>ermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1

The vcxproj file generated by CMake does not have a "<WholeProgramOptimization>" tag.


I hope you can consider adding LTCG to Release configurations of Visual C++ projects generated by CMake, by default.


Kind regards, Niels
--
Niels Dekker
Scientific programmer
LKEB, Leiden University Medical Center
--

Powered by www.kitware.com<http://www.kitware.com>

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180125/7362408b/attachment-0001.html>


More information about the CMake mailing list