Debian Codegraph @

cmake/modules/FindSIP.cmake

raw
1 # Find SIP
2 # ~~~~~~~~
3 #
4 # SIP website: http://www.riverbankcomputing.co.uk/sip/index.php
5 #
6 # Find the installed version of SIP. FindSIP should be called after Python
7 # has been found.
8 #
9 # This file defines the following variables:
10 #
11 # SIP_VERSION - The version of SIP found expressed as a 6 digit hex number
12 # suitable for comparison as a string.
13 #
14 # SIP_VERSION_STR - The version of SIP found as a human readable string.
15 #
16 # SIP_EXECUTABLE - Path and filename of the SIP command line executable.
17 #
18 # SIP_INCLUDE_DIR - Directory holding the SIP C++ header file.
19 #
20 # SIP_DEFAULT_SIP_DIR - Default directory where .sip files should be installed
21 # into.
22
23 # SPDX-FileCopyrightText: 2007 Simon Edwards <[email protected]>
24 # SPDX-FileCopyrightText: 2021 L. E. Segovia <[email protected]>
25 #
26 # SPDX-License-Identifier: BSD-3-Clause
27 #
28
29 IF(SIP_VERSION)
30 # Already in cache, be silent
31 SET(SIP_FOUND TRUE)
32 ELSE(SIP_VERSION)
33
34 FIND_FILE(_find_sip_py FindSIP.py PATHS ${CMAKE_MODULE_PATH})
35
36 # TODO: we don't use cmake_path(CONVERT TO_NATIVE_PATH_LIST) here, because
37 # it is unknown if it is going to work on Windows. Currently, our paths
38 # on Windows use '/' as well. We need to test if switching them into '\'
39 # will still work
40 set(_path_list_separator ":")
41 if (WIN32)
42 set(_path_list_separator ";")
43 endif()
44
45 set(all_paths ${KRITA_PYTHONPATH_V4} ${KRITA_PYTHONPATH_V5} $ENV{PYTHONPATH})
46 list(REMOVE_ITEM all_paths "")
47 list(JOIN all_paths "${_path_list_separator}" _pyqt5_python_path)
48
49 EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E env
50 "PYTHONPATH=${_pyqt5_python_path}"
51 ${Python_EXECUTABLE} ${_find_sip_py}
52 OUTPUT_VARIABLE sip_config)
53
54 IF(sip_config)
55 STRING(REGEX REPLACE "^sip_version:([^\n]+).*$" "\\1" SIP_VERSION ${sip_config})
56 STRING(REGEX REPLACE ".*\nsip_version_str:([^\n]+).*$" "\\1" SIP_VERSION_STR ${sip_config})
57 STRING(REGEX REPLACE ".*\nsip_bin:([^\n]+).*$" "\\1" SIP_EXECUTABLE ${sip_config})
58 IF(${SIP_VERSION_STR} VERSION_LESS 5)
59 IF(NOT SIP_DEFAULT_SIP_DIR)
60 STRING(REGEX REPLACE ".*\ndefault_sip_dir:([^\n]+).*$" "\\1" SIP_DEFAULT_SIP_DIR ${sip_config})
61 ENDIF(NOT SIP_DEFAULT_SIP_DIR)
62 STRING(REGEX REPLACE ".*\nsip_inc_dir:([^\n]+).*$" "\\1" SIP_INCLUDE_DIR ${sip_config})
63 FILE(TO_CMAKE_PATH ${SIP_INCLUDE_DIR} SIP_INCLUDE_DIR)
64 FILE(TO_CMAKE_PATH ${SIP_DEFAULT_SIP_DIR} SIP_DEFAULT_SIP_DIR)
65 ELSE(${SIP_VERSION_STR} VERSION_LESS 5)
66 FIND_PROGRAM(SIP_MODULE_EXECUTABLE sip-module)
67 ENDIF(${SIP_VERSION_STR} VERSION_LESS 5)
68 if (WIN32 AND ${SIP_VERSION_STR} VERSION_LESS 5)
69 set(SIP_EXECUTABLE ${SIP_EXECUTABLE}.exe)
70 endif()
71 IF(EXISTS ${SIP_EXECUTABLE})
72 SET(SIP_FOUND TRUE)
73 ELSE()
74 MESSAGE(STATUS "Found SIP configuration but the sip executable could not be found.")
75 ENDIF()
76 ENDIF(sip_config)
77
78 IF(SIP_FOUND)
79 IF(NOT SIP_FIND_QUIETLY)
80 MESSAGE(STATUS "Found SIP version: ${SIP_VERSION_STR}")
81 ENDIF(NOT SIP_FIND_QUIETLY)
82 ELSE(SIP_FOUND)
83 IF(SIP_FIND_REQUIRED)
84 MESSAGE(FATAL_ERROR "Could not find SIP")
85 ENDIF(SIP_FIND_REQUIRED)
86 ENDIF(SIP_FOUND)
87
88 ENDIF(SIP_VERSION)