Changeset View
Changeset View
Standalone View
Standalone View
find-modules/module_generation/FindSIP.cmake
- This file was added.
1 | # Copyright 2017 Shaheed Haque <srhaque@theiet.org> | ||||
---|---|---|---|---|---|
2 | # | ||||
3 | # Redistribution and use in source and binary forms, with or without | ||||
4 | # modification, are permitted provided that the following conditions | ||||
5 | # are met: | ||||
6 | # | ||||
7 | # 1. Redistributions of source code must retain the copyright | ||||
8 | # notice, this list of conditions and the following disclaimer. | ||||
9 | # 2. Redistributions in binary form must reproduce the copyright | ||||
10 | # notice, this list of conditions and the following disclaimer in the | ||||
11 | # documentation and/or other materials provided with the distribution. | ||||
12 | # 3. The name of the author may not be used to endorse or promote products | ||||
13 | # derived from this software without specific prior written permission. | ||||
14 | # | ||||
15 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||||
16 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||||
17 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||||
18 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||||
19 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||||
20 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||
21 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
22 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||||
24 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
25 | | ||||
26 | #.rst: | ||||
27 | # FindSIP | ||||
28 | # ------- | ||||
29 | # | ||||
30 | # Find SIP | ||||
31 | # | ||||
32 | # This module finds an installed SIP. It sets the following variables: | ||||
33 | # | ||||
34 | # :: | ||||
35 | # | ||||
36 | # SIP_FOUND - set to true if SIP is found | ||||
37 | # SIP_DIR - the directory where SIP is installed | ||||
38 | # SIP_EXECUTABLE - the path to the SIP executable | ||||
39 | # SIP_INCLUDE_DIRS - Where to find sip.h. | ||||
40 | # SIP_VERSION - the version number of the SIP executable | ||||
41 | # | ||||
42 | # | ||||
43 | # | ||||
44 | # The minimum required version of SIP can be specified using the | ||||
45 | # standard syntax, e.g. find_package(SIP 4.19) | ||||
46 | # | ||||
47 | # All information is collected from the SIP_EXECUTABLE so the version | ||||
48 | # to be found can be changed from the command line by means of setting | ||||
49 | # SIP_EXECUTABLE | ||||
50 | | ||||
51 | find_program(SIP_EXECUTABLE NAMES sip) | ||||
52 | | ||||
53 | if(SIP_EXECUTABLE) | ||||
54 | execute_process(COMMAND ${SIP_EXECUTABLE} -V | ||||
55 | OUTPUT_VARIABLE SIP_version_output | ||||
56 | ERROR_VARIABLE SIP_version_output | ||||
57 | RESULT_VARIABLE SIP_version_result) | ||||
58 | | ||||
59 | if(SIP_version_result) | ||||
60 | message(SEND_ERROR "Command \"${SIP_EXECUTABLE} -V\" failed with output:\n${SIP_version_output}") | ||||
61 | else() | ||||
62 | string(REGEX REPLACE "[\n\r]+" "" SIP_version_output ${SIP_version_output}) | ||||
63 | set(SIP_VERSION ${SIP_version_output} CACHE STRING "SIP version" FORCE) | ||||
64 | endif() | ||||
65 | endif() | ||||
66 | | ||||
67 | # | ||||
68 | # See https://github.com/pybind/pybind11/blob/master/tools/FindPythonLibsNew.cmake. | ||||
69 | # | ||||
70 | find_package(PythonInterp QUIET REQUIRED) | ||||
71 | find_package(PythonLibs QUIET REQUIRED) | ||||
72 | execute_process( | ||||
73 | COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig as s;import sys;import struct; | ||||
74 | print('.'.join(str(v) for v in sys.version_info)); | ||||
75 | print(sys.prefix); | ||||
76 | print(s.get_python_inc(plat_specific=True)); | ||||
77 | print(s.get_python_lib(plat_specific=True)); | ||||
78 | print(s.get_config_var('SO')); | ||||
79 | print(hasattr(sys, 'gettotalrefcount')+0); | ||||
80 | print(struct.calcsize('@P')); | ||||
81 | print(s.get_config_var('LDVERSION') or s.get_config_var('VERSION')); | ||||
82 | print(s.get_config_var('LIBDIR') or ''); | ||||
83 | print(s.get_config_var('MULTIARCH') or ''); | ||||
84 | " | ||||
85 | RESULT_VARIABLE _PYTHON_SUCCESS | ||||
86 | OUTPUT_VARIABLE _PYTHON_VALUES | ||||
87 | ERROR_VARIABLE _PYTHON_ERROR_VALUE) | ||||
88 | # | ||||
89 | # Convert the process output into a list. | ||||
90 | # | ||||
91 | string(REGEX REPLACE ";" "\\\\;" _PYTHON_VALUES ${_PYTHON_VALUES}) | ||||
92 | string(REGEX REPLACE "\n" ";" _PYTHON_VALUES ${_PYTHON_VALUES}) | ||||
93 | list(GET _PYTHON_VALUES 0 _PYTHON_VERSION_LIST) | ||||
94 | list(GET _PYTHON_VALUES 1 PYTHON_PREFIX) | ||||
95 | list(GET _PYTHON_VALUES 2 PYTHON_INCLUDE_DIR) | ||||
96 | list(GET _PYTHON_VALUES 3 PYTHON_SITE_PACKAGES) | ||||
97 | list(GET _PYTHON_VALUES 4 PYTHON_MODULE_EXTENSION) | ||||
98 | list(GET _PYTHON_VALUES 5 PYTHON_IS_DEBUG) | ||||
99 | list(GET _PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P) | ||||
100 | list(GET _PYTHON_VALUES 7 PYTHON_LIBRARY_SUFFIX) | ||||
101 | list(GET _PYTHON_VALUES 8 PYTHON_LIBDIR) | ||||
102 | list(GET _PYTHON_VALUES 9 PYTHON_MULTIARCH) | ||||
103 | # | ||||
104 | # Find sip.h. | ||||
105 | # | ||||
106 | find_file(SIP_HEADER NAMES sip.h | ||||
107 | HINTS "${PYTHON_INCLUDE_DIR}") | ||||
108 | if(SIP_HEADER) | ||||
109 | set(SIP_INCLUDE_DIRS ${PYTHON_INCLUDE_DIR}) | ||||
110 | file(STRINGS "${SIP_HEADER}" SIP_VERSION_TMP REGEX ".*SIP_VERSION_STR.*\"\([0-9]+.[0-9]+\.*)\"") | ||||
111 | string(REGEX REPLACE ".*SIP_VERSION_STR.*\"\([0-9]+.[0-9]+\.*)\"" "\\1" SIP_VERSION_TMP "${SIP_VERSION_TMP}") | ||||
112 | set(SIP_HEADER_VERSION ${SIP_VERSION_TMP} CACHE STRING "LibSIP version" FORCE) | ||||
113 | if(NOT SIP_VERSION STREQUAL SIP_HEADER_VERSION) | ||||
114 | message(SEND_ERROR "Command version \"${SIP_VERSION}\" does not match header version ${SIP_HEADER_VERSION}") | ||||
115 | endif() | ||||
116 | endif() | ||||
117 | | ||||
118 | include(FindPackageHandleStandardArgs) | ||||
119 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SIP REQUIRED_VARS SIP_EXECUTABLE SIP_INCLUDE_DIRS | ||||
120 | VERSION_VAR SIP_VERSION) | ||||
121 | | ||||
122 | mark_as_advanced(SIP_VERSION) |