Skip to content

Commit

Permalink
Extend FindPySide2.cmake and FindShiboken2.cmake for current versions (
Browse files Browse the repository at this point in the history
  • Loading branch information
thestr4ng3r authored Mar 22, 2019
1 parent 7fd815b commit c84546e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ if(CUTTER_ENABLE_PYTHON)
find_package(Shiboken2 "${Qt5_VERSION}" REQUIRED)
find_package(PySide2 "${Qt5_VERSION}" REQUIRED)

set(PYSIDE_LIBRARY PySide2::pyside2)
get_target_property(PYSIDE_INCLUDE_DIR PySide2::pyside2 INTERFACE_INCLUDE_DIRECTORIES)
list(GET PYSIDE_INCLUDE_DIR 0 PYSIDE_INCLUDE_DIR)
include_directories(${PYSIDE_INCLUDE_DIR}
Expand Down
41 changes: 35 additions & 6 deletions src/cmake/FindPySide2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set(_module PySide2)

find_package(${_module} ${${_module}_FIND_VERSION} CONFIG QUIET)
set(_lib_target ${_module}::pyside2)

if(NOT ${_module}_FOUND)
include(PythonInfo)
Expand All @@ -23,13 +24,41 @@ if(NOT ${_module}_FOUND)
PATH_SUFFIXES "${PYTHON_SITE_PACKAGES}/PySide2/typesystems")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(${_module}
FOUND_VAR ${_module}_FOUND
REQUIRED_VARS PYSIDE_LIBRARY PYSIDE_INCLUDE_DIR PYSIDE_TYPESYSTEMS
VERSION_VAR ${_module}_VERSION)
if(TARGET ${_lib_target})
get_target_property(_is_imported ${_lib_target} IMPORTED)
if(_is_imported)
get_target_property(_imported_location ${_lib_target} IMPORTED_LOCATION)
if(NOT _imported_location)
message(STATUS "Target ${_lib_target} does not specify its IMPORTED_LOCATION! Trying to find it ourselves...")
set(_find_args)
if(${_module}_CONFIG)
get_filename_component(_pyside2_lib_dir "${${_module}_CONFIG}/../../../" ABSOLUTE)
set(_find_args PATHS "${_pyside2_lib_dir}")
endif()
find_library(PYSIDE_LIBRARY
NAMES
"pyside2${PYTHON_CONFIG_SUFFIX}"
"pyside2${PYTHON_CONFIG_SUFFIX}.${${_module}_FIND_VERSION_MAJOR}.${${_module}_FIND_VERSION_MINOR}"
${_find_args})
if(NOT PYSIDE_LIBRARY)
set(_message_type WARNING)
if(${_module}_FIND_REQUIRED)
set(_message_type FATAL_ERROR)
endif()
message(${_message_type} "Failed to manually find library for ${_module}")
return()
endif()
message(STATUS "IMPORTED_LOCATION for ${_lib_target} found: ${PYSIDE_LIBRARY}")
set_target_properties(${_lib_target} PROPERTIES IMPORTED_LOCATION "${PYSIDE_LIBRARY}")
endif()
endif()
else()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(${_module}
FOUND_VAR ${_module}_FOUND
REQUIRED_VARS PYSIDE_LIBRARY PYSIDE_INCLUDE_DIR PYSIDE_TYPESYSTEMS
VERSION_VAR ${_module}_VERSION)

if(NOT TARGET ${_module}::pyside2)
add_library(${_module}::pyside2 INTERFACE IMPORTED)
set_target_properties(${_module}::pyside2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${PYSIDE_INCLUDE_DIR}"
Expand Down
69 changes: 58 additions & 11 deletions src/cmake/FindShiboken2.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

set(_module Shiboken2)

find_package(${_module} ${${_module}_FIND_VERSION} CONFIG QUIET)
find_package(${_module} ${${_module}_FIND_VERSION} CONFIG)
set(_executable_target ${_module}::shiboken2)
set(_lib_target ${_module}::libshiboken)

if(NOT ${_module}_FOUND)
include(PythonInfo)
Expand All @@ -23,20 +25,65 @@ if(NOT ${_module}_FOUND)
PATH_SUFFIXES "${PYTHON_SITE_PACKAGES}/shiboken2_generator")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(${_module}
FOUND_VAR ${_module}_FOUND
REQUIRED_VARS SHIBOKEN_LIBRARY SHIBOKEN_INCLUDE_DIR SHIBOKEN_BINARY
VERSION_VAR ${_module}_VERSION)
if(TARGET ${_executable_target})
get_target_property(_is_imported ${_executable_target} IMPORTED)
if(_is_imported)
get_target_property(_imported_location ${_executable_target} IMPORTED_LOCATION)
if(NOT _imported_location)
message(STATUS "Target ${_executable_target} does not specify its IMPORTED_LOCATION! Trying to find it ourselves...")
find_file(SHIBOKEN_BINARY
shiboken2
PATHS "${SHIBOKEN_SHARED_LIBRARY_DIR}/../bin"
NO_DEFAULT_PATH)
if(NOT SHIBOKEN_BINARY)
set(_message_type WARNING)
if(${_module}_FIND_REQUIRED)
set(_message_type FATAL_ERROR)
endif()
message(${_message_type} "Failed to manually find executable for ${_module}")
return()
endif()
message(STATUS "IMPORTED_LOCATION for ${_executable_target} found: ${SHIBOKEN_BINARY}")
set_target_properties(${_executable_target} PROPERTIES IMPORTED_LOCATION "${SHIBOKEN_BINARY}")
endif()
endif()

if(NOT TARGET ${_module}::shiboken2)
add_library(${_module}::libshiboken INTERFACE IMPORTED)
set_target_properties(${_module}::libshiboken PROPERTIES
get_target_property(_is_imported ${_lib_target} IMPORTED)
if(_is_imported)
get_target_property(_imported_location ${_lib_target} IMPORTED_LOCATION)
if(NOT _imported_location)
message(STATUS "Target ${_lib_target} does not specify its IMPORTED_LOCATION! Trying to find it ourselves...")
find_library(SHIBOKEN_LIBRARY
NAMES
"shiboken2${SHIBOKEN_PYTHON_EXTENSION_SUFFIX}"
"shiboken2${SHIBOKEN_PYTHON_EXTENSION_SUFFIX}.${${_module}_FIND_VERSION_MAJOR}.${${_module}_FIND_VERSION_MINOR}"
PATHS "${SHIBOKEN_SHARED_LIBRARY_DIR}")
if(NOT SHIBOKEN_LIBRARY)
set(_message_type WARNING)
if(${_module}_FIND_REQUIRED)
set(_message_type FATAL_ERROR)
endif()
message(${_message_type} "Failed to manually find library for ${_module}")
return()
endif()
message(STATUS "IMPORTED_LOCATION for ${_lib_target} found: ${SHIBOKEN_LIBRARY}")
set_target_properties(${_lib_target} PROPERTIES IMPORTED_LOCATION "${SHIBOKEN_LIBRARY}")
endif()
endif()
else()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(${_module}
FOUND_VAR ${_module}_FOUND
REQUIRED_VARS SHIBOKEN_LIBRARY SHIBOKEN_INCLUDE_DIR SHIBOKEN_BINARY
VERSION_VAR ${_module}_VERSION)

add_library(${_lib_target} INTERFACE IMPORTED)
set_target_properties(${_lib_target} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SHIBOKEN_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${SHIBOKEN_LIBRARY}")

add_executable(${_module}::shiboken2 IMPORTED)
set_target_properties(${_module}::shiboken2 PROPERTIES
add_executable(${_executable_target} IMPORTED)
set_target_properties(${_executable_target} PROPERTIES
IMPORTED_LOCATION "${SHIBOKEN_BINARY}")
endif()

Expand Down

0 comments on commit c84546e

Please sign in to comment.