]> SALOME platform Git repositories - tools/configuration.git/commitdiff
Salome HOME
Porting: sip 5
authorvsr <vsr@opencascade.com>
Sat, 13 Mar 2021 07:03:48 +0000 (10:03 +0300)
committervsr <vsr@opencascade.com>
Sat, 13 Mar 2021 07:03:48 +0000 (10:03 +0300)
cmake/FindSIP.cmake
cmake/UseSIP.cmake

index 2a2a5d588fafdfb06bbd024c2416247c1ccf1da5..96ff22054bc7f1e13539c146f54a2862540517a2 100644 (file)
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-# - Find SIP
+# - Find sip
 # Sets the following variables:
-#   SIP_EXECUTABLE      - path to the SIP executable
-#   SIP_INCLUDE_DIR     - path to the SIP headers
-#   SIP_PYTHONPATH      - path to the SIP Python packages
+#   SIP_VERSION           - version of SIP
+#   SIP_MODULE_EXECUTABLE - path to the sip-module executable (sip >= 5)
+#   SIP_EXECUTABLE        - path to the sip executable
+#   SIP_INCLUDE_DIR       - path to the sip headers (sip < 5)
+#   SIP_PYTHONPATH        - path to the sip Python packages
 #
 #  The header sip.h is looked for.
 #  The binary 'sip' is looked for.
@@ -31,16 +33,44 @@ IF(NOT SIP_FIND_QUIETLY)
   MESSAGE(STATUS "Looking for SIP ...")
 ENDIF()
 
-FIND_PROGRAM(SIP_EXECUTABLE sip)
-FIND_PATH(SIP_INCLUDE_DIR sip.h PATH_SUFFIXES python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}m)
+# Find executable
+FIND_PROGRAM(SIP_EXECUTABLE
+             NAMES sip5 sip4 sip
+             HINTS $ENV{SIP_ROOT_DIR}
+             PATH_SUFFIXES bin)
 
-IF(SIP_INCLUDE_DIR)
-  GET_FILENAME_COMPONENT(SIP_PYTHONPATH "${SIP_INCLUDE_DIR}" PATH)
-  GET_FILENAME_COMPONENT(SIP_PYTHONPATH "${SIP_PYTHONPATH}" PATH)
+IF(SIP_EXECUTABLE)
+  # Set path to sip's Python module
+  GET_FILENAME_COMPONENT(SIP_PYTHONPATH "${SIP_EXECUTABLE}" PATH) # <root>/bin/sip -> <root>/bin
+  GET_FILENAME_COMPONENT(SIP_PYTHONPATH "${SIP_PYTHONPATH}" PATH) # <root>/bin -> <root>
   SET(SIP_PYTHONPATH "${SIP_PYTHONPATH}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages")
+
+  # Detect sip version
+  EXECUTE_PROCESS(COMMAND ${SIP_EXECUTABLE} "-V"
+                  OUTPUT_VARIABLE SIP_VERSION
+                  OUTPUT_STRIP_TRAILING_WHITESPACE
+                  ERROR_QUIET)
 ENDIF()
 
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(SIP REQUIRED_VARS SIP_INCLUDE_DIR SIP_EXECUTABLE SIP_PYTHONPATH)
+# Find sip-module executable (only for version >= 5)
+IF(SIP_VERSION AND SIP_VERSION VERSION_GREATER_EQUAL "5")
+  FIND_PROGRAM(SIP_MODULE_EXECUTABLE
+               NAMES sip-module
+               HINTS $ENV{SIP_ROOT_DIR}
+               PATH_SUFFIXES bin)
+ENDIF()
 
+# Find header file (only for version < 5)
+IF(NOT SIP_VERSION OR SIP_VERSION VERSION_LESS "5")
+  FIND_PATH(SIP_INCLUDE_DIR
+            NAMES sip.h
+            HINTS $ENV{SIP_ROOT_DIR}
+            PATH_SUFFIXES include python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}m)
+ENDIF()
 
+INCLUDE(FindPackageHandleStandardArgs)
+IF(SIP_VERSION AND SIP_VERSION VERSION_GREATER_EQUAL "5")
+  FIND_PACKAGE_HANDLE_STANDARD_ARGS(SIP REQUIRED_VARS SIP_EXECUTABLE SIP_MODULE_EXECUTABLE SIP_PYTHONPATH)
+ELSE()
+  FIND_PACKAGE_HANDLE_STANDARD_ARGS(SIP REQUIRED_VARS SIP_INCLUDE_DIR SIP_EXECUTABLE SIP_PYTHONPATH)
+ENDIF()
index 33ce2a4e566c926976af0479a4a96b98a32d31ef..7ca342f05af8a9b60ba4ecafacef4b1893e05e95 100644 (file)
@@ -109,9 +109,18 @@ MACRO(SIP_WRAP_SIP outfiles)
       SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_class_source})
     ENDFOREACH()
   ENDFOREACH()
+  IF(SIP_VERSION AND SIP_VERSION VERSION_GREATER_EQUAL "5")
+    LIST(GET _sip_files 0 _main_sip_file)
+    ADD_CUSTOM_COMMAND(
+      OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sip.h
+      COMMAND ${SIP_MODULE_EXECUTABLE} --sip-h --target-dir ${CMAKE_CURRENT_BINARY_DIR} ${_main_sip_file}
+      DEPENDS ${_sip_files}
+      )
+    SET(_extra_deps ${CMAKE_CURRENT_BINARY_DIR}/sip.h)
+  ENDIF()
   ADD_CUSTOM_COMMAND(
     OUTPUT ${_output}
     COMMAND ${SIP_EXECUTABLE} ${_options} ${CMAKE_CURRENT_SOURCE_DIR}/${_module_input}
-    MAIN_DEPENDENCY ${_module_input}
+    DEPENDS ${_module_input} ${_extra_deps}
     )
 ENDMACRO(SIP_WRAP_SIP)