aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/cmake/Macros/PySideModules.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside2/cmake/Macros/PySideModules.cmake')
-rw-r--r--sources/pyside2/cmake/Macros/PySideModules.cmake225
1 files changed, 104 insertions, 121 deletions
diff --git a/sources/pyside2/cmake/Macros/PySideModules.cmake b/sources/pyside2/cmake/Macros/PySideModules.cmake
index 36488912d..42ba8e8a0 100644
--- a/sources/pyside2/cmake/Macros/PySideModules.cmake
+++ b/sources/pyside2/cmake/Macros/PySideModules.cmake
@@ -1,3 +1,14 @@
+include(CMakeParseArguments)
+
+# A version of cmake_parse_arguments that makes sure all arguments are processed and errors out
+# with a message about ${type} having received unknown arguments.
+macro(pyside_parse_all_arguments prefix type flags options multiopts)
+ cmake_parse_arguments(${prefix} "${flags}" "${options}" "${multiopts}" ${ARGN})
+ if(DEFINED ${prefix}_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unknown arguments were passed to ${type} (${${prefix}_UNPARSED_ARGUMENTS}).")
+ endif()
+endmacro()
+
macro(make_path varname)
# accepts any number of path variables
string(REPLACE ";" "${PATH_SEP}" ${varname} "${ARGN}")
@@ -7,46 +18,59 @@ macro(unmake_path varname)
string(REPLACE "${PATH_SEP}" ";" ${varname} "${ARGN}")
endmacro()
-macro(create_pyside_module
- module_name
- module_include_dir
- module_libraries
- module_deps
- module_typesystem_path
- module_sources
- module_static_sources)
- string(TOLOWER ${module_name} _module)
- string(REGEX REPLACE ^qt "" _module ${_module})
- if(${ARGC} GREATER 7)
- set (typesystem_name ${ARGV7})
- else()
- set (typesystem_name "")
+# Sample usage
+# create_pyside_module(NAME QtGui
+# INCLUDE_DIRS QtGui_include_dirs
+# LIBRARIES QtGui_libraries
+# DEPS QtGui_deps
+# TYPESYSTEM_PATH QtGui_SOURCE_DIR
+# SOURCES QtGui_SRC
+# STATIC_SOURCES QtGui_static_sources
+# TYPESYSTEM_NAME ${QtGui_BINARY_DIR}/typesystem_gui.xml
+# DROPPED_ENTRIES QtGui_DROPPED_ENTRIES
+# GLUE_SOURCES QtGui_glue_sources)
+macro(create_pyside_module)
+ pyside_parse_all_arguments(
+ "module" # Prefix
+ "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
+ ${ARGN} # Number of arguments given when the macros is called
+ )
+
+ if ("${module_NAME}" STREQUAL "")
+ message(FATAL_ERROR "create_pyside_module needs a NAME value.")
+ endif()
+ if ("${module_INCLUDE_DIRS}" STREQUAL "")
+ message(FATAL_ERROR "create_pyside_module needs at least one INCLUDE_DIRS value.")
endif()
- if(${ARGC} GREATER 8)
- string(REPLACE ";" "\\;" dropped_entries "${${ARGV8}}")
+ if ("${module_TYPESYSTEM_PATH}" STREQUAL "")
+ message(FATAL_ERROR "create_pyside_module needs a TYPESYSTEM_PATH value.")
+ endif()
+ if ("${module_SOURCES}" STREQUAL "")
+ message(FATAL_ERROR "create_pyside_module needs at least one SOURCES value.")
+ endif()
+
+ string(TOLOWER ${module_NAME} _module)
+ string(REGEX REPLACE ^qt "" _module ${_module})
+
+ if(${module_DROPPED_ENTRIES})
+ string(REPLACE ";" "\\;" dropped_entries "${${module_DROPPED_ENTRIES}}")
else()
set (dropped_entries "")
endif()
- if (NOT EXISTS ${typesystem_name})
- set(typesystem_path ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_${_module}.xml)
+ if(${module_GLUE_SOURCES})
+ set (module_GLUE_SOURCES "${${module_GLUE_SOURCES}}")
else()
- set(typesystem_path ${typesystem_name})
+ set (module_GLUE_SOURCES "")
endif()
- # check for class files that were commented away.
- if(DEFINED ${module_sources}_skipped_files)
- if(DEFINED PYTHON3_EXECUTABLE)
- set(_python_interpreter "${PYTHON3_EXECUTABLE}")
- else()
- set(_python_interpreter "${PYTHON_EXECUTABLE}")
- endif()
- if(NOT _python_interpreter)
- message(FATAL_ERROR "*** we need a python interpreter for postprocessing!")
- endif()
- set(_python_postprocessor "${_python_interpreter}" "${CMAKE_CURRENT_BINARY_DIR}/filter_init.py")
+ if (NOT EXISTS ${module_TYPESYSTEM_NAME})
+ set(typesystem_path ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_${_module}.xml)
else()
- set(_python_postprocessor "")
+ set(typesystem_path ${module_TYPESYSTEM_NAME})
endif()
# Create typesystem XML dependencies list, so that whenever they change, shiboken is invoked
@@ -56,7 +80,7 @@ macro(create_pyside_module
get_filename_component(typesystem_root "${CMAKE_CURRENT_SOURCE_DIR}" DIRECTORY)
- set(deps ${module_name} ${${module_deps}})
+ set(deps ${module_NAME} ${${module_DEPS}})
foreach(dep ${deps})
set(glob_expression "${typesystem_root}/${dep}/*.xml")
file(GLOB type_system_files ${glob_expression})
@@ -80,44 +104,74 @@ macro(create_pyside_module
get_filename_component(pyside_binary_dir ${CMAKE_CURRENT_BINARY_DIR} DIRECTORY)
- add_custom_command(OUTPUT ${${module_sources}}
+ # Install module glue files.
+ string(TOLOWER ${module_NAME} lower_module_name)
+ set(${module_NAME}_glue "${CMAKE_CURRENT_SOURCE_DIR}/../glue/${lower_module_name}.cpp")
+ set(${module_name}_glue_dependency "")
+ if(EXISTS ${${module_NAME}_glue})
+ install(FILES ${${module_NAME}_glue} DESTINATION share/PySide2${pyside2_SUFFIX}/glue)
+ set(${module_NAME}_glue_dependency ${${module_NAME}_glue})
+ endif()
+
+ # Install standalone glue files into typesystems subfolder, so that the resolved relative
+ # paths remain correct.
+ if (module_GLUE_SOURCES)
+ install(FILES ${module_GLUE_SOURCES} DESTINATION share/PySide2${pyside2_SUFFIX}/typesystems/glue)
+ endif()
+
+ add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log"
+ BYPRODUCTS ${${module_SOURCES}}
COMMAND "${SHIBOKEN_BINARY}" ${GENERATOR_EXTRA_FLAGS}
- "${pyside2_BINARY_DIR}/${module_name}_global.h"
+ "${pyside2_BINARY_DIR}/${module_NAME}_global.h"
--include-paths=${shiboken_include_dirs}
${shiboken_framework_include_dirs_option}
- --typesystem-paths=${pyside_binary_dir}${PATH_SEP}${pyside2_SOURCE_DIR}${PATH_SEP}${${module_typesystem_path}}
+ --typesystem-paths=${pyside_binary_dir}${PATH_SEP}${pyside2_SOURCE_DIR}${PATH_SEP}${${module_TYPESYSTEM_PATH}}
--output-directory=${CMAKE_CURRENT_BINARY_DIR}
--license-file=${CMAKE_CURRENT_SOURCE_DIR}/../licensecomment.txt
${typesystem_path}
--api-version=${SUPPORTED_QT_VERSION}
--drop-type-entries="${dropped_entries}"
- COMMAND ${_python_postprocessor}
DEPENDS ${total_type_system_files}
+ ${module_GLUE_SOURCES}
+ ${${module_NAME}_glue_dependency}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- COMMENT "Running generator for ${module_name}...")
+ COMMENT "Running generator for ${module_NAME}...")
- include_directories(${module_name} ${${module_include_dir}} ${pyside2_SOURCE_DIR})
- add_library(${module_name} MODULE ${${module_sources}} ${${module_static_sources}})
- set_target_properties(${module_name} PROPERTIES
+ include_directories(${module_NAME} ${${module_INCLUDE_DIRS}} ${pyside2_SOURCE_DIR})
+ add_library(${module_NAME} MODULE ${${module_SOURCES}}
+ ${${module_STATIC_SOURCES}})
+ set_target_properties(${module_NAME} PROPERTIES
PREFIX ""
- OUTPUT_NAME "${module_name}${PYTHON_EXTENSION_SUFFIX}"
+ OUTPUT_NAME "${module_NAME}${PYTHON_EXTENSION_SUFFIX}"
LIBRARY_OUTPUT_DIRECTORY ${pyside2_BINARY_DIR})
if(WIN32)
- set_target_properties(${module_name} PROPERTIES SUFFIX ".pyd")
+ set_target_properties(${module_NAME} PROPERTIES SUFFIX ".pyd")
# Sanitize windows.h as pulled by gl.h to prevent clashes with QAbstract3dAxis::min(), etc.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX")
endif()
- target_link_libraries(${module_name} ${${module_libraries}})
- if(${module_deps})
- add_dependencies(${module_name} ${${module_deps}})
+ target_link_libraries(${module_NAME} ${${module_LIBRARIES}})
+ if(${module_DEPS})
+ add_dependencies(${module_NAME} ${${module_DEPS}})
endif()
-
+ create_generator_target(${module_NAME})
+
+ # build type hinting stubs
+ add_custom_command( TARGET ${module_NAME} POST_BUILD
+ COMMAND "${SHIBOKEN_PYTHON_INTERPRETER}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../support/generate_pyi.py" run --skip
+ --sys-path "${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}/../shiboken2/shibokenmodule"
+ --lib-path "${CMAKE_BINARY_DIR}/libpyside" "${CMAKE_BINARY_DIR}/../shiboken2/libshiboken"
+ )
# install
- install(TARGETS ${module_name} LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES}/PySide2)
- string(TOLOWER ${module_name} lower_module_name)
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/PySide2/${module_name}/pyside2_${lower_module_name}_python.h
- DESTINATION include/PySide2${pyside2_SUFFIX}/${module_name}/)
+ install(TARGETS ${module_NAME} LIBRARY DESTINATION "${PYTHON_SITE_PACKAGES}/PySide2")
+
+ install(DIRECTORY "${CMAKE_BINARY_DIR}/" DESTINATION "${PYTHON_SITE_PACKAGES}"
+ OPTIONAL
+ FILES_MATCHING PATTERN "*.pyi")
+
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/PySide2/${module_NAME}/pyside2_${lower_module_name}_python.h
+ DESTINATION include/PySide2${pyside2_SUFFIX}/${module_NAME}/)
file(GLOB typesystem_files ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_*.xml ${typesystem_path})
# Copy typesystem files and remove module names from the <load-typesystem> element
@@ -134,77 +188,6 @@ macro(create_pyside_module
endforeach()
endmacro()
-#macro(check_qt_class_with_namespace module namespace class optional_source_files dropped_entries [namespace] [module])
-macro(check_qt_class module class optional_source_files dropped_entries)
- if (${ARGC} GREATER 4)
- set (namespace ${ARGV4})
- string(TOLOWER ${namespace} _namespace)
- else ()
- set (namespace "")
- endif ()
- if (${ARGC} GREATER 5)
- set (include_file ${ARGV5})
- else ()
- set (include_file ${class})
- endif ()
- string(TOLOWER ${class} _class)
- # Remove the "Qt" prefix.
- string(SUBSTRING ${module} 2 -1 _module_no_qt_prefix)
- if (_namespace)
- set(_cppfile ${CMAKE_CURRENT_BINARY_DIR}/PySide2/${module}/${_namespace}_${_class}_wrapper.cpp)
- else ()
- set(_cppfile ${CMAKE_CURRENT_BINARY_DIR}/PySide2/${module}/${_class}_wrapper.cpp)
- endif ()
- if (DEFINED PYSIDE_${class})
- if (PYSIDE_${class})
- list(APPEND ${optional_source_files} ${_cppfile})
- else()
- list(APPEND ${dropped_entries} PySide2.${module}.${class})
- endif()
- else()
- if (NOT ${namespace} STREQUAL "" )
- set (NAMESPACE_USE "using namespace ${namespace};")
- else ()
- set (NAMESPACE_USE "")
- endif ()
- set(SRC_FILE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test${class}.cxx)
- file(WRITE ${SRC_FILE}
- "#include <${include_file}>\n"
- "${NAMESPACE_USE}\n"
- "int main() { sizeof(${class}); }\n"
- )
-
- # Because Qt is built with -fPIC (by default), the compile tests also have to have that.
- get_property(ADDITIONAL_FLAGS TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_OPTIONS)
-
- # Don't add version tagging, because for some reason linker fails with:
- # (.qtversion[qt_version_tag]+0x0): undefined reference to `qt_version_tag'
- # Force usage of the C++11 standard. CMAKE_CXX_STANDARD does not work with try_compile
- # but the issue has a fix in CMake 3.9. Thus we use a terrible workaround, we pass the C++
- # standard flag the way CheckCXXSourceCompiles.cmake does it.
-
- set(ADDITIONAL_FLAGS "${ADDITIONAL_FLAGS} -DQT_NO_VERSION_TAGGING ${CMAKE_CXX11_EXTENSION_COMPILE_OPTION}")
-
- try_compile(Q_WORKS ${CMAKE_BINARY_DIR}
- ${SRC_FILE}
- CMAKE_FLAGS
- "-DINCLUDE_DIRECTORIES=${QT_INCLUDE_DIR};${Qt5${_module_no_qt_prefix}_INCLUDE_DIRS}"
- "-DCOMPILE_DEFINITIONS:STRING=${ADDITIONAL_FLAGS}"
- OUTPUT_VARIABLE OUTPUT)
- file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCheckQtClassTest.log ${OUTPUT})
-
- set("PYSIDE_${class}" ${Q_WORKS} CACHE STRING "Has ${class} class been found?")
- if(Q_WORKS)
- message(STATUS "Checking for ${class} in ${module} -- found")
- list(APPEND ${optional_source_files} ${_cppfile})
- else()
- message(STATUS "Checking for ${class} in ${module} -- not found")
- list(APPEND ${dropped_entries} PySide2.${module}.${class})
- endif()
- endif()
-endmacro()
-
-
# Only add subdirectory if the associated Qt module is found.
# As a side effect, this macro now also defines the variable ${name}_GEN_DIR
# and must be called for every subproject.