aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/cmake/Macros/PySideModules.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/cmake/Macros/PySideModules.cmake')
-rw-r--r--sources/pyside6/cmake/Macros/PySideModules.cmake135
1 files changed, 118 insertions, 17 deletions
diff --git a/sources/pyside6/cmake/Macros/PySideModules.cmake b/sources/pyside6/cmake/Macros/PySideModules.cmake
index 462c47441..1e434f9f6 100644
--- a/sources/pyside6/cmake/Macros/PySideModules.cmake
+++ b/sources/pyside6/cmake/Macros/PySideModules.cmake
@@ -1,3 +1,6 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
include(CMakeParseArguments)
# A version of cmake_parse_arguments that makes sure all arguments are processed and errors out
@@ -18,6 +21,34 @@ macro(unmake_path varname)
string(REPLACE "${PATH_SEP}" ";" ${varname} "${ARGN}")
endmacro()
+# Check for presence of QtOpenGL and modify module variables
+# accordingly
+macro(check_qt_opengl module include_var deps_var dropped_entries_var)
+ if (Qt${QT_MAJOR_VERSION}OpenGL_FOUND)
+ message(STATUS "Qt${QT_MAJOR_VERSION}${module}: Building with OpenGL")
+ list(APPEND ${include_var} ${Qt${QT_MAJOR_VERSION}OpenGL_INCLUDE_DIRS}
+ ${QtOpenGL_GEN_DIR})
+ list(APPEND ${deps_var} QtOpenGL)
+ else()
+ message(STATUS "Qt${QT_MAJOR_VERSION}${module}: Dropping OpenGL")
+ # This is a dummy entry creating a conditional typesystem keyword
+ list(APPEND ${dropped_entries_var} "QtOpenGL")
+ endif()
+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
@@ -35,7 +66,7 @@ macro(create_pyside_module)
"create_pyside_module" # Macro name
"" # Flags
"NAME;TYPESYSTEM_PATH;TYPESYSTEM_NAME" # Single value
- "INCLUDE_DIRS;LIBRARIES;DEPS;SOURCES;STATIC_SOURCES;DROPPED_ENTRIES;GLUE_SOURCES" # Multival
+ "INCLUDE_DIRS;LIBRARIES;DEPS;SOURCES;STATIC_SOURCES;DROPPED_ENTRIES;GLUE_SOURCES;ADDITIONAL_INCLUDE_DIRS" # Multival
${ARGN} # Number of arguments given when the macros is called
)
@@ -92,10 +123,46 @@ macro(create_pyside_module)
INTERFACE_INCLUDE_DIRECTORIES)
set(shiboken_include_dir_list ${pyside6_SOURCE_DIR} ${qt_platform_includes}
${qt_core_includes})
+ if(module_ADDITIONAL_INCLUDE_DIRS)
+ list(APPEND shiboken_include_dir_list ${${module_ADDITIONAL_INCLUDE_DIRS}})
+ endif()
# Transform the path separators into something shiboken understands.
make_path(shiboken_include_dirs ${shiboken_include_dir_list})
+ set(force_process_system_include_paths_list "")
+ # When building against system Qt (as it happens with yocto / Boot2Qt), the Qt headers are
+ # considered system headers by clang_Location_isInSystemHeader, and thus shiboken will not
+ # process them.
+ #
+ # We do want to process them.
+ #
+ # Tell shiboken to consider them as special typesystem system include paths, which ensures
+ # the types are processed and extracted.
+ #
+ # This option is opt-in because it might cause problems if there are other system headers
+ # installed in the same location as the Qt ones, resulting in processing more non-Qt system
+ # types that might not be supported by shiboken.
+ if(PYSIDE_TREAT_QT_INCLUDE_DIRS_AS_NON_SYSTEM)
+ list(APPEND force_process_system_include_paths_list
+ ${qt_platform_includes}
+ ${qt_core_includes})
+ endif()
+
+ # Allow passing extra non system inlcude dirs.
+ if(SHIBOKEN_FORCE_PROCESS_SYSTEM_INCLUDE_PATHS)
+ list(APPEND force_process_system_include_paths_list
+ ${SHIBOKEN_FORCE_PROCESS_SYSTEM_INCLUDE_PATHS})
+ endif()
+
+ # Transform the path separators into something shiboken understands.
+ make_path(force_process_system_include_paths ${force_process_system_include_paths_list})
+
+ if(force_process_system_include_paths)
+ set(force_process_system_include_paths
+ "--force-process-system-include-paths=${force_process_system_include_paths}")
+ endif()
+
get_filename_component(pyside_binary_dir ${CMAKE_CURRENT_BINARY_DIR} DIRECTORY)
# Install module glue files.
@@ -113,11 +180,18 @@ macro(create_pyside_module)
install(FILES ${module_GLUE_SOURCES} DESTINATION share/PySide6${pyside6_SUFFIX}/typesystems/glue)
endif()
- set(shiboken_command Shiboken6::shiboken6 ${GENERATOR_EXTRA_FLAGS}
+ shiboken_get_tool_shell_wrapper(shiboken tool_wrapper)
+
+ set(shiboken_command
+ ${tool_wrapper}
+ $<TARGET_FILE:Shiboken6::shiboken6>
+ ${GENERATOR_EXTRA_FLAGS}
"--include-paths=${shiboken_include_dirs}"
+ "${force_process_system_include_paths}"
"--typesystem-paths=${pyside_binary_dir}${PATH_SEP}${pyside6_SOURCE_DIR}${PATH_SEP}${${module_TYPESYSTEM_PATH}}"
--output-directory=${CMAKE_CURRENT_BINARY_DIR}
--license-file=${CMAKE_CURRENT_SOURCE_DIR}/../licensecomment.txt
+ --lean-headers
--api-version=${SUPPORTED_QT_VERSION})
if(CMAKE_HOST_APPLE)
@@ -146,6 +220,11 @@ 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})
+
+ target_compile_definitions(${module_NAME} PRIVATE -DQT_LEAN_HEADERS=1)
+
set_target_properties(${module_NAME} PROPERTIES
PREFIX ""
OUTPUT_NAME "${module_NAME}${SHIBOKEN_PYTHON_EXTENSION_SUFFIX}"
@@ -174,7 +253,17 @@ macro(create_pyside_module)
else()
set(ld_prefix_var_name "LD_LIBRARY_PATH")
endif()
- set(ld_prefix "${ld_prefix_var_name}=${pysidebindings_BINARY_DIR}/libpyside${PATH_SEP}${SHIBOKEN_SHARED_LIBRARY_DIR}")
+
+ set(ld_prefix_list "")
+ list(APPEND ld_prefix_list "${pysidebindings_BINARY_DIR}/libpyside")
+ list(APPEND ld_prefix_list "${pysidebindings_BINARY_DIR}/libpysideqml")
+ list(APPEND ld_prefix_list "${SHIBOKEN_SHARED_LIBRARY_DIR}")
+ if(WIN32)
+ list(APPEND ld_prefix_list "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_BINS}")
+ endif()
+
+ list(JOIN ld_prefix_list "${PATH_SEP}" ld_prefix_values_string)
+ set(ld_prefix "${ld_prefix_var_name}=${ld_prefix_values_string}")
# Append any existing ld_prefix values, so existing PATH, LD_LIBRARY_PATH, etc.
# On Windows it is needed because pyside modules import Qt,
@@ -199,26 +288,38 @@ macro(create_pyside_module)
string(APPEND ld_prefix ":${env_value}")
endif()
endif()
- set(generate_pyi_options ${module_NAME} --sys-path
- "${pysidebindings_BINARY_DIR}"
- "${SHIBOKEN_PYTHON_MODULE_DIR}/..") # use the layer above shiboken6
- if (QUIET_BUILD)
- list(APPEND generate_pyi_options "--quiet")
- endif()
+
+ qfp_strip_library("${module_NAME}")
# Add target to generate pyi file, which depends on the module target.
- add_custom_target("${module_NAME}_pyi" ALL
- COMMAND ${CMAKE_COMMAND} -E env ${ld_prefix}
- "${SHIBOKEN_PYTHON_INTERPRETER}"
- "${CMAKE_CURRENT_SOURCE_DIR}/../support/generate_pyi.py" ${generate_pyi_options})
- add_dependencies("${module_NAME}_pyi" ${module_NAME})
+ # Don't generate the files when cross-building because the target python can not be executed
+ # on the host machine (usually, unless you use some userspace qemu based mechanism).
+ # TODO: Can we do something better here to still get pyi files?
+ if(NOT (PYSIDE_IS_CROSS_BUILD OR DISABLE_PYI))
+ set(generate_pyi_options ${module_NAME} --sys-path
+ "${pysidebindings_BINARY_DIR}"
+ "${SHIBOKEN_PYTHON_MODULE_DIR}/..") # use the layer above shiboken6
+ if (QUIET_BUILD)
+ list(APPEND generate_pyi_options "--quiet")
+ endif()
+
+ add_custom_target("${module_NAME}_pyi" ALL
+ COMMAND
+ ${CMAKE_COMMAND} -E env ${ld_prefix}
+ "${SHIBOKEN_PYTHON_INTERPRETER}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../support/generate_pyi.py"
+ ${generate_pyi_options})
+ add_dependencies("${module_NAME}_pyi" ${module_NAME})
+
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/../${module_NAME}.pyi"
+ DESTINATION "${PYTHON_SITE_PACKAGES}/PySide6")
+ endif()
+
# install
install(TARGETS ${module_NAME} LIBRARY DESTINATION "${PYTHON_SITE_PACKAGES}/PySide6")
- file(GLOB hinting_stub_files RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/PySide6" "${CMAKE_CURRENT_BINARY_DIR}/PySide6/*.pyi")
- install(FILES ${hinting_stub_files}
- DESTINATION "${PYTHON_SITE_PACKAGES}/PySide6")
+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/PySide6/${module_NAME}/pyside6_${lower_module_name}_python.h
DESTINATION include/PySide6${pyside6_SUFFIX}/${module_NAME}/)