cmake_minimum_required(VERSION 3.1) cmake_policy(VERSION 3.1) # Consider changing the project name to something relevant for you. project(qtwebenginewidgets) # ================================ General configuration ====================================== # Set CPP standard to C++11 minimum set(CMAKE_CXX_STANDARD 14) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 1) # The sample library for which we will create bindings. You can change the name to something # relevant for your project. set(sample_library "PySide2") # The name of the generated bindings module (as imported in Python). You can change the name # to something relevant for your project. set(bindings_library "bind") # The header file with all the types and functions for which bindings will be generated. # Usually it simply includes other headers of the library you are creating bindings for. set(wrapped_header ${CMAKE_SOURCE_DIR}/QtWebEngineWidgets) # The typesystem xml file which defines the relationships between the C++ types / functions # and the corresponding Python equivalents. set(typesystem_file ${CMAKE_SOURCE_DIR}/typesystem_webenginewidgets.xml) # Specify which C++ files will be generated by shiboken. This includes the module wrapper # and a '.cpp' file per C++ type. These are needed for generating the module shared # library. set(generated_sources ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/PySide2/QtWebEngineWidgets/qwebenginedownloaditem_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/PySide2/QtWebEngineWidgets/qwebenginecertificateerror_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/PySide2/QtWebEngineWidgets/qtwebenginewidgets_module_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/PySide2/QtWebEngineWidgets/qwebenginehistoryitem_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/PySide2/QtWebEngineWidgets/qwebenginepage_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/PySide2/QtWebEngineWidgets/qwebengineprofile_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/PySide2/QtWebEngineWidgets/qwebenginescript_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/PySide2/QtWebEngineWidgets/qwebengineview_wrapper.cpp ) # =============================== CMake target - sample_library =============================== if(NOT python_interpreter) find_program(python_interpreter "python") endif() message(STATUS "Using python interpreter: ${python_interpreter}") # Define the sample shared library for which we will create bindings. set(${sample_library}_sources ${generated_sources}) add_library(${sample_library} SHARED ${${sample_library}_sources}) set_property(TARGET ${sample_library} PROPERTY PREFIX "") # Needed mostly on Windows to export symbols, and create a .lib file, otherwise the binding # library can't link to the sample library.te target_compile_definitions(${sample_library} PRIVATE BINDINGS_BUILD) set(shiboken2_module_path C:/Users/PC/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/shiboken2_generator) set(shiboken2_generator_path C:/Users/PC/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/shiboken2_generator) set(python_include_dir C:/Users/PC/AppData/Local/Programs/Python/Python37-32/include) set(shiboken_include_dir C:/Users/PC/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/shiboken2_generator/include 1) set(python_linking_data C:/Users/PC/AppData/Local/Programs/Python/Python37-32/libs 1) set(shiboken_path "${shiboken2_generator_path}/shiboken2${CMAKE_EXECUTABLE_SUFFIX}") if(NOT EXISTS ${shiboken_path}) message(FATAL_ERROR "Shiboken executable not found at path: ${shiboken_path}") endif() # ====================== Shiboken target for generating binding C++ files ==================== # Set up the options to pass to shiboken. set(shiboken_options --generator-set=shiboken --enable-parent-ctor-heuristic --enable-return-value-heuristic --use-isnull-as-nb_nonzero --avoid-protected-hack -IC:/Qt/Qt-5.15.2/include/ -TC:/Qt/Qt-5.15.2/include/ --output-directory=bind ) set(generated_sources_dependencies ${wrapped_header} ${typesystem_file}) # Add custom target to run shiboken to generate the binding cpp files. add_custom_command(OUTPUT ${generated_sources} COMMAND ${shiboken_path} ${shiboken_options} ${wrapped_header} ${typesystem_file} DEPENDS ${generated_sources_dependencies} IMPLICIT_DEPENDS CXX ${wrapped_header} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Running generator for ${typesystem_file}.") # =============================== CMake target - bindings_library ============================= # Set the cpp files which will be used for the bindings library. set(${bindings_library}_sources ${generated_sources}) # Define and build the bindings library. add_library(${bindings_library} MODULE ${${bindings_library}_sources}) # Apply relevant include and link flags. include_directories(C:/Qt/Qt-5.15.2/include/libpyside C:/Qt/Qt-5.15.2/include/QtWebChannel C:/Qt/Qt-5.15.2/include/QtWebChannel/test/PySide2/QtWebChannel C:/Users/PC/AppData/Local/Programs/Python/Python39/Lib/site-packages/shiboken2_generator/include ${python_include_dir} ${CMAKE_SOURCE_DIR} C:/Qt/Qt-5.15.2/include C:/Qt/Qt-5.15.2/include/QtCore C:/Qt/Qt-5.15.2/include/QtCore/test/PySide2/QtCore C:/Qt/Qt-5.15.2/include/QtWidgets C:/Qt/Qt-5.15.2/include/QtWidgets/test/PySide2/QtWidgets C:/Qt/Qt-5.15.2/include/QtGui C:/Qt/Qt-5.15.2/include/QtGui/test/PySide2/QtGui C:/Qt/Qt-5.15.2/include/QtNetwork C:/Qt/Qt-5.15.2/include/QtNetwork/test/PySide2/QtNetwork) target_include_directories(${bindings_library} PRIVATE ${python_include_dir}) target_include_directories(${bindings_library} PRIVATE ${shiboken_include_dir}) target_include_directories(${bindings_library} PRIVATE ${CMAKE_SOURCE_DIR}) target_link_libraries(${bindings_library} PRIVATE ${sample_library}) # Adjust the name of generated module. set_property(TARGET ${bindings_library} PROPERTY PREFIX "") set_property(TARGET ${bindings_library} PROPERTY OUTPUT_NAME "${bindings_library}${PYTHON_EXTENSION_SUFFIX}") set_property(TARGET ${bindings_library} PROPERTY SUFFIX ".pyd") # Make sure the linker doesn't complain about not finding Python symbols on macOS # Find and link to the python import library only on Windows. # On Linux and macOS, the undefined symbols will get resolved by the dynamic linker # (the symbols will be picked up in the Python executable). if (WIN32) set(python_link_flags "") list(GET python_linking_data 0 python_libdir) list(GET python_linking_data 1 python_lib) find_library(python_link_flags ${python_lib} PATHS ${python_libdir} HINTS ${python_libdir}) target_link_libraries(${bindings_library} PRIVATE ${python_link_flags}) endif() # ================================= Dubious deployment section ================================ set(windows_shiboken_shared_libraries) if(WIN32) # ========================================================================================= # !!! (The section below is deployment related, so in a real world application you will # want to take care of this properly (this is simply to eliminate errors that users usually # encounter. # ========================================================================================= # Circumvent some "#pragma comment(lib)"s in "include/pyconfig.h" which might force to link # against a wrong python shared library. set(python_versions_list 3 32 33 34 35 36 37 38) set_target_properties(${sample_library} PROPERTIES LINK_FLAGS "${python_additional_link_flags}") # Compile a list of shiboken shared libraries to be installed, so that # the user doesn't have to set the PATH manually to point to the PySide2 package. set(python_additional_link_flags "") foreach(ver ${python_versions_list}) set(python_additional_link_flags "${python_additional_link_flags} /NODEFAULTLIB:/"python${ver}_d.lib/"") set(python_additional_link_flags "${python_additional_link_flags} /NODEFAULTLIB:/"python${ver}.lib/"") endforeach() # ========================================================================================= # !!! End of dubious section. # ========================================================================================= endif() # ============================================================================================= # !!! (The section below is deployment related, so in a real world application you will want to # take care of this properly with some custom script or tool). # ============================================================================================= # Install the library and the bindings module into the source folder near the main.py file, so # that the Python interpeter successfully imports the used module. install(TARGETS ${bindings_library} ${sample_library} LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) install(FILES ${windows_shiboken_shared_libraries} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}) # ============================================================================================= # !!! End of dubious section. # =============================================================================================