From 0d708a9aad8fa7f44e94f5bc9093a6c93d6140b1 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Tue, 22 Nov 2022 15:22:30 +0800 Subject: [PATCH] MSVC: Improve the LTCG build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we use MSVC to build static libraries, enabling LTCG will generate very large output, for example, Qt's bundled 3rd party libraries can be greater than 100MB per file (some of them even >200MB!). This is not good if we are building a shared version of Qt and enabling LTCG at the same time. On Windows Qt's bundled 3rd party dependencies will be built as static libraries and they will make the final Qt package way too large. From my side, if I only build a release version, the package size is usually around 500MB but when LTCG is enabled, it become over 2GB. The exe and dlls' size don't vary much, but there are many large static libraries. Fixes: QTBUG-108719 Change-Id: Ic521f500b9c24389524e96a8cdc2e7b3427b51a9 Reviewed-by: Alexandru Croitor Reviewed-by: Jörg Bornemann Reviewed-by: Amir Masoud Abdol --- cmake/Qt3rdPartyLibraryHelpers.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmake/Qt3rdPartyLibraryHelpers.cmake b/cmake/Qt3rdPartyLibraryHelpers.cmake index 1bec4db6b9f..220bcaf1575 100644 --- a/cmake/Qt3rdPartyLibraryHelpers.cmake +++ b/cmake/Qt3rdPartyLibraryHelpers.cmake @@ -310,6 +310,12 @@ function(qt_internal_add_3rdparty_library target) qt_enable_separate_debug_info(${target} "${debug_install_dir}") qt_internal_install_pdb_files(${target} "${INSTALL_LIBDIR}") endif() + + if(BUILD_SHARED_LIBS AND MSVC) + set_target_properties(${target} PROPERTIES + INTERPROCEDURAL_OPTIMIZATION OFF + ) + endif() endfunction() function(qt_install_3rdparty_library_wrap_config_extra_file target)