aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/cmake/Macros/PySideModules.cmake
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2022-03-23 09:33:22 +0100
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2022-04-11 10:50:27 +0200
commita88f7b21c61e4aa9efcfb81d7939e44b06df3a0d (patch)
treee0b9f6fd7b6f4cca40aab7f241d9ae4a16d2cca4 /sources/pyside6/cmake/Macros/PySideModules.cmake
parent1049b1ed57e3ec591ddb5ebda1b501a102f95019 (diff)
PySide6: Optimize for Size
build: use the following flag with setup.py to turn off size optimization --no-size-optimization Added the following compiler optimization flags and their corresponding flags on other platforms GCC - -ffunction-sections -fdata-section which segretates data and function section and linker flag --gc-section which removes unused code. - -fno-exceptions to disable exception handling - -Os - Optimize for size. Basically same as -O2 but removes some flags that cause increase in size. (Ran a couple of example and did not see difference in execution time) MSVC - /Gy /Gw /OPT:REF - same as -ffunction-sections, -fdata-section, -Wl, --gc-section - /EHsc same as -fno-exceptions - /O1 instead of /Os because for MSVC /O1 gave the best results. Clang - Same as GCC except for using -Oz instead of -Os. Experiments: Built a wheel with QtCore and noticed a 300kb reduction in size on both Windows and Linux. Built a complete wheel(except QTest) and it gives me a 4 mb size reduction with unaffected performance. Task-number: PYSIDE-1860 Change-Id: Ia5dfa2c4bfde92994c939b5fac0d0831fa3a73ab Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/cmake/Macros/PySideModules.cmake')
-rw-r--r--sources/pyside6/cmake/Macros/PySideModules.cmake16
1 files changed, 16 insertions, 0 deletions
diff --git a/sources/pyside6/cmake/Macros/PySideModules.cmake b/sources/pyside6/cmake/Macros/PySideModules.cmake
index c5bee643c..d722b4650 100644
--- a/sources/pyside6/cmake/Macros/PySideModules.cmake
+++ b/sources/pyside6/cmake/Macros/PySideModules.cmake
@@ -18,6 +18,19 @@ macro(unmake_path varname)
string(REPLACE "${PATH_SEP}" ";" ${varname} "${ARGN}")
endmacro()
+# set size optimization flags for pyside6
+macro(append_size_optimization_flags _module_name)
+ if(NOT QFP_NO_OVERRIDE_OPTIMIZATION_FLAGS)
+ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
+ target_compile_options(${_module_name} PRIVATE /Gy /Gw /EHsc)
+ target_link_options(${_module_name} PRIVATE LINKER:/OPT:REF)
+ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|CLANG")
+ target_compile_options(${_module_name} PRIVATE -ffunction-sections -fdata-sections -fno-exceptions)
+ target_link_options(${_module_name} PRIVATE LINKER:--gc-sections)
+ endif()
+ endif()
+endmacro()
+
# Sample usage
# create_pyside_module(NAME QtGui
# INCLUDE_DIRS QtGui_include_dirs
@@ -146,6 +159,9 @@ macro(create_pyside_module)
include_directories(${module_NAME} ${${module_INCLUDE_DIRS}} ${pyside6_SOURCE_DIR})
add_library(${module_NAME} MODULE ${${module_SOURCES}}
${${module_STATIC_SOURCES}})
+
+ append_size_optimization_flags(${module_NAME})
+
set_target_properties(${module_NAME} PROPERTIES
PREFIX ""
OUTPUT_NAME "${module_NAME}${SHIBOKEN_PYTHON_EXTENSION_SUFFIX}"