Salome HOME
Copyright update 2022
[tools/configuration.git] / cmake / FindSIP.cmake
1 # Copyright (C) 2013-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # - Find sip
21 # Sets the following variables:
22 #   SIP_VERSION           - version of SIP
23 #   SIP_MODULE_EXECUTABLE - path to the sip-module executable (sip >= 5)
24 #   SIP_EXECUTABLE        - path to the sip executable
25 #   SIP_INCLUDE_DIR       - path to the sip headers (sip < 5)
26 #   SIP_PYTHONPATH        - path to the sip Python packages
27 #
28 #  The header sip.h is looked for.
29 #  The binary 'sip' is looked for.
30 #
31
32 IF(NOT SIP_FIND_QUIETLY)
33   MESSAGE(STATUS "Looking for SIP ...")
34 ENDIF()
35
36 # Find executable
37 FIND_PROGRAM(SIP_EXECUTABLE
38              NAMES sip5 sip4 sip
39              HINTS $ENV{SIP_ROOT_DIR}
40              PATH_SUFFIXES bin Scripts)
41
42 IF(SIP_EXECUTABLE)
43   # Set path to sip's Python module
44   GET_FILENAME_COMPONENT(SIP_PYTHONPATH "${SIP_EXECUTABLE}" PATH) # <root>/bin/sip -> <root>/bin
45   GET_FILENAME_COMPONENT(SIP_PYTHONPATH "${SIP_PYTHONPATH}" PATH) # <root>/bin -> <root>
46   IF(WIN32)
47     SET(SIP_PYTHONPATH "${SIP_PYTHONPATH}/lib/site-packages")
48   ELSE()
49     SET(SIP_PYTHONPATH "${SIP_PYTHONPATH}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages")
50   ENDIF()
51
52   # Detect sip version
53   EXECUTE_PROCESS(COMMAND ${SIP_EXECUTABLE} "-V"
54                   OUTPUT_VARIABLE SIP_VERSION
55                   OUTPUT_STRIP_TRAILING_WHITESPACE
56                   ERROR_QUIET)
57 ENDIF()
58
59 # Find sip-module executable (only for version >= 5)
60 IF(SIP_VERSION AND SIP_VERSION VERSION_GREATER_EQUAL "5")
61   FIND_PROGRAM(SIP_MODULE_EXECUTABLE
62                NAMES sip-module
63                HINTS $ENV{SIP_ROOT_DIR}
64                PATH_SUFFIXES bin Scripts)
65 ENDIF()
66
67 # Find header file (only for version < 5)
68 IF(NOT SIP_VERSION OR SIP_VERSION VERSION_LESS "5")
69   FIND_PATH(SIP_INCLUDE_DIR
70             NAMES sip.h
71             HINTS $ENV{SIP_ROOT_DIR}
72             PATH_SUFFIXES include python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}m)
73 ENDIF()
74
75 INCLUDE(FindPackageHandleStandardArgs)
76 IF(SIP_VERSION AND SIP_VERSION VERSION_GREATER_EQUAL "5")
77   FIND_PACKAGE_HANDLE_STANDARD_ARGS(SIP REQUIRED_VARS SIP_EXECUTABLE SIP_MODULE_EXECUTABLE SIP_PYTHONPATH)
78 ELSE()
79   FIND_PACKAGE_HANDLE_STANDARD_ARGS(SIP REQUIRED_VARS SIP_INCLUDE_DIR SIP_EXECUTABLE SIP_PYTHONPATH)
80 ENDIF()