project(MyUtils) set(cpp_library "myutils") set(${cpp_library}_sources smoketest.cpp text/textutils.cpp) set(bindings_library "MyUtils") set(generated_sources ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/myutils_module_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/smoketest_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/textutils_textutils_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/textutils_wrapper.cpp ) cmake_minimum_required(VERSION 3.12) cmake_policy(VERSION 3.12) find_package(Qt5 COMPONENTS Core Network Xml Sql REQUIRED) get_target_property(QtCore_location Qt5::Core LOCATION) # Qt Core library path get_filename_component(QtCore_libdir ${QtCore_location} DIRECTORY) # Drectory for all modules (? suspect this points to incomplete directory) #message("QtCore_libdir=${QtCore_libdir}") set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(wrapped_header ${CMAKE_SOURCE_DIR}/bindings.h) # this is where the source code is set(typesystem_file ${CMAKE_SOURCE_DIR}/bindings.xml) find_package(Python3 REQUIRED COMPONENTS Interpreter Development) message("python_interpreter = ${python_interpreter}") if(NOT python_interpreter) find_program(python_interpreter "python") endif() message("Python3_SITELIB=${Python3_SITELIB}") set(PYSIDE2_DIR ${Python3_SITELIB}/PySide2) # /opt/pyside-setup/pyside2build/lib/python3.6/site-packages/PySide2 macro(pyside2_config option output_var) if(${ARGC} GREATER 2) set(is_list ${ARGV2}) else() set(is_list "") endif() execute_process( COMMAND ${python_interpreter} "${PYSIDE2_DIR}/examples/utils/pyside2_config.py" ${option} OUTPUT_VARIABLE ${output_var} OUTPUT_STRIP_TRAILING_WHITESPACE) if ("${${output_var}}" STREQUAL "") message("DEBUG: executing ${PYSIDE2_DIR}/examples/utils/pyside2_config.py ${option}") message(FATAL_ERROR "Error: Calling pyside2_config.py ${option} returned no output.") endif() if(is_list) string (REPLACE " " ";" ${output_var} "${${output_var}}") endif() message("DEBUG - pyside2_config: option=${option} -> output_var=${${output_var}}") endmacro() pyside2_config(--shiboken2-module-path shiboken2_module_path) # /opt/pyside-setup/pyside2build/lib/python3.6/site-packages/shiboken2 pyside2_config(--shiboken2-generator-path shiboken2_generator_path) # /opt/pyside-setup/pyside2build/lib/python3.6/site-packages/shiboken2_generator pyside2_config(--python-include-path python_include_dir) # /usr/include/python3.6m pyside2_config(--shiboken2-generator-include-path shiboken_include_dir 1) # /opt/pyside-setup/pyside2build/lib/python3.6/site-packages/shiboken2_generator/include pyside2_config(--shiboken2-module-shared-libraries-cmake shiboken_shared_libraries 0) # /opt/pyside-setup/pyside2build/lib/python3.6/site-packages/shiboken2/libshiboken2.cpython-36m-x86_64-linux-gnu.so.5.14 pyside2_config(--pyside2-shared-libraries-cmake pyside2_link 0) # /opt/pyside-setup/pyside2build/lib/python3.6/site-packages/PySide2/libpyside2.cpython-36m-x86_64-linux-gnu.so.5.14 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() set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_INSTALL_RPATH ${shiboken2_module_path} ${CMAKE_CURRENT_SOURCE_DIR} ${QtCore_libdir}) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) add_library(${cpp_library} SHARED ${${cpp_library}_sources}) # define files to be included in the library target_link_libraries(${cpp_library} Qt5::Core Qt5::Network Qt5::Xml Qt5::Sql) # add all libraries defined on top here set_property(TARGET ${cpp_library} PROPERTY PREFIX "") get_target_property(qtcore_lib_includes Qt5::Core INTERFACE_INCLUDE_DIRECTORIES) list(JOIN qtcore_lib_includes ";-I" lib_includes) set(lib_includes "-I${lib_includes}") target_compile_definitions(${cpp_library} PRIVATE BINDINGS_BUILD) set(shiboken_options --generator-set=shiboken --enable-parent-ctor-heuristic --enable-return-value-heuristic --use-isnull-as-nb_nonzero --avoid-protected-hack --enable-pyside-extensions ${lib_includes} -I${CMAKE_SOURCE_DIR} -T${CMAKE_SOURCE_DIR} -T${PYSIDE2_DIR}/typesystems/ --output-directory=${CMAKE_CURRENT_BINARY_DIR} ) set(generated_sources_dependencies ${wrapped_header} ${typesystem_file}) 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}.") set(${bindings_library}_sources ${generated_sources}) add_library(${bindings_library} MODULE ${${bindings_library}_sources}) target_include_directories(${bindings_library} PRIVATE ${python_include_dir}) target_include_directories(${bindings_library} PRIVATE ${PYSIDE2_DIR}/include/) target_include_directories(${bindings_library} PRIVATE ${PYSIDE2_DIR}/include/QtCore) target_include_directories(${bindings_library} PRIVATE ${shiboken_include_dir}) target_include_directories(${bindings_library} PRIVATE ${CMAKE_SOURCE_DIR}) target_link_libraries(${bindings_library} PRIVATE ${shiboken_shared_libraries}) target_link_libraries(${bindings_library} PRIVATE ${cpp_library}) target_link_libraries(${bindings_library} PRIVATE ${pyside2_link}) set_property(TARGET ${bindings_library} PROPERTY PREFIX "") set_property(TARGET ${bindings_library} PROPERTY OUTPUT_NAME "${bindings_library}${PYTHON_EXTENSION_SUFFIX}") install(TARGETS ${bindings_library} ${cpp_library} LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )