project(kcardgame) cmake_minimum_required(VERSION 3.12) cmake_policy(VERSION 3.12) find_package(ECM 5 REQUIRED CONFIG) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) find_package(Qt5 COMPONENTS Core Gui Svg REQUIRED) find_package(KF5 "5.0.0" REQUIRED COMPONENTS Completion Config ConfigWidgets CoreAddons Crash DBusAddons DocTools GuiAddons I18n KIO NewStuff WidgetsAddons XmlGui ) find_package(Shiboken2 "2.0.0" REQUIRED) find_package(PySide2 "2.0.0" REQUIRED) find_package(KF5KDEGames 4.9.0 REQUIRED) include(FeatureSummary) include(ECMAddAppIcon) include(ECMInstallIcons) include(KDEInstallDirs) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(ECMQtDeclareLoggingCategory) include(GenerateExportHeader) get_target_property(QtCore_location Qt5::Core LOCATION) get_filename_component(QtCore_libdir ${QtCore_location} DIRECTORY) set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_STANDARD 11) set(bindings_library "PySolFC_KCard") set(sample_library "lib_${bindings_library}_binding") set(wrapped_header ${CMAKE_SOURCE_DIR}/bindings.h) set(typesystem_file ${CMAKE_SOURCE_DIR}/bindings.xml) set(generated_sources ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/mykcarddeck_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pysolfc_kcard_module_wrapper.cpp) find_package(Python3 REQUIRED COMPONENTS Interpreter Development) if(NOT python_interpreter) find_program(python_interpreter "python33") endif() set(PYSIDE2_DIR ${Python3_SITELIB}/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(FATAL_ERROR "Error: Calling pyside2_config.py ${option} returned no output.") endif() if(is_list) string (REPLACE " " ";" ${output_var} "${${output_var}}") endif() endmacro() if () pyside2_config(--shiboken2-module-path shiboken2_module_path) pyside2_config(--shiboken2-generator-path shiboken2_generator_path) pyside2_config(--python-include-path python_include_dir) pyside2_config(--shiboken2-generator-include-path shiboken_include_dir 1) pyside2_config(--shiboken2-module-shared-libraries-cmake shiboken_shared_libraries 0) pyside2_config(--pyside2-shared-libraries-cmake pyside2_link 0) endif() set(shiboken_include_dir "/usr/include/shiboken2") set(python_include_dir "/usr/include/python3.7m") set(shiboken_path "/usr/bin/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) set(${sample_library}_sources kcardgame.cpp "${CMAKE_CURRENT_SOURCE_DIR}/../kpat/libkcardgame/kabstractcarddeck.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../kpat/libkcardgame/kcard.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../build-kpat/libkcardgame/libkcardgame_debug.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../kpat/libkcardgame/kcarddeck.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../kpat/libkcardgame/kcardtheme.cpp" ) add_library(${sample_library} SHARED ${${sample_library}_sources}) target_link_libraries(${sample_library} Qt5::Core Qt5::Gui) target_link_libraries(${sample_library} KF5::Crash KF5::DBusAddons KF5::I18n KF5::KIOCore KF5KDEGames ) target_link_libraries( ${sample_library} KF5::NewStuff KF5::GuiAddons Qt5::Svg KF5::Completion KF5::I18n) target_link_libraries(${sample_library} Shiboken2::libshiboken) target_link_libraries(${sample_library} PySide2::pyside2) set_property(TARGET ${sample_library} PROPERTY PREFIX "") get_target_property(qtgui_lib_includes Qt5::Gui INTERFACE_INCLUDE_DIRECTORIES) list(JOIN qtgui_lib_includes ";-I" lib2_includes) 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}" "-I${lib2_includes}") target_compile_definitions(${sample_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 -T/usr/share/PySide2/typesystems/ -I"${CMAKE_CURRENT_SOURCE_DIR}/../build-kpat/libkcardgame" -I"${CMAKE_CURRENT_SOURCE_DIR}/../kpat/libkcardgame" -I"${CMAKE_CURRENT_SOURCE_DIR}/../kpat/libkcardgame/include" ${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}) foreach (_lib ${bindings_library} ${sample_library}) target_include_directories(${_lib} PRIVATE ${python_include_dir} "${CMAKE_CURRENT_SOURCE_DIR}/../kpat/libkcardgame" "${CMAKE_CURRENT_SOURCE_DIR}/../build-kpat/" "${CMAKE_CURRENT_SOURCE_DIR}/../build-kpat/libkcardgame" "${CMAKE_CURRENT_SOURCE_DIR}/../kpat/libkcardgame/include" ${PYSIDE2_DIR}/include/ "/usr/include/PySide2" "/usr/include/PySide2/QtCore/" "/usr/include/PySide2/QtGui/" ${PYSIDE2_DIR}/include/QtCore ${shiboken_include_dir} ${CMAKE_SOURCE_DIR} ) endforeach() target_link_libraries(${bindings_library} PRIVATE ${shiboken_shared_libraries} ${sample_library} ${pyside2_link} ) set_property(TARGET ${bindings_library} PROPERTY PREFIX "") set_property(TARGET ${bindings_library} PROPERTY OUTPUT_NAME "${bindings_library}${PYTHON_EXTENSION_SUFFIX}") generate_export_header(${sample_library} BASE_NAME libkcardgame) install(TARGETS ${bindings_library} ${sample_library} LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )