From d2a0202cdab5827d3e6e25c4d1fcb30afbb12e16 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Fri, 19 Nov 2021 11:05:10 +0800 Subject: [PATCH] MSVC: Optimize global data to reduce binary size Package global data in COMDAT sections for optimization. According to the docs, this can significantly reduce the size of the resulting binary executable. I've tested build Qt with /Gw locally with and without LTCG, the result shows /Gw can reduce the binary size indeed, but not "significantly". The result also reveals that exes can benefit much more from /Gw than dlls. The result can be seen from the QTBUG-98894 bug report. Microsoft Docs: https://docs.microsoft.com/en-us/cpp/build/reference/gw-optimize-global-data?view=msvc-170 Task-number: QTBUG-98894 Change-Id: Ibce34c98e791e519d669a5fe39c0027d1459c382 Reviewed-by: Thiago Macieira Reviewed-by: Kai Koehne --- cmake/QtInternalTargets.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index aee33c5dde..fc98e6215d 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -199,7 +199,7 @@ if (MSVC) target_compile_options(PlatformCommonInternal INTERFACE -Zc:wchar_t) target_compile_options(PlatformCommonInternal INTERFACE - $<$>:-guard:cf> + $<$>:-guard:cf -Gw> ) target_link_options(PlatformCommonInternal INTERFACE