]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
CMake: wrote a safer command for the PyQt4 executable
authorbruneton <bruneton>
Thu, 4 Jul 2013 14:22:02 +0000 (14:22 +0000)
committerbruneton <bruneton>
Thu, 4 Jul 2013 14:22:02 +0000 (14:22 +0000)
(ensuring the proper PYTHONPATH is set)

CMakeLists.txt
adm_local/cmake_files/FindPyQt4.cmake
adm_local/cmake_files/FindSIP.cmake
adm_local/cmake_files/FindSalomePyQt4.cmake
src/GUI_PY/CMakeLists.txt

index a2b1e5ec7756553d86b004b3d4f97e257af43abd..b5f4bb4884565e90767a057e8939571e4378f2df 100755 (executable)
@@ -123,7 +123,7 @@ ENDIF()
 ## GUI specifics
 ##
 
-FIND_PACKAGE(SalomeSIP REQUIRED)  # should come after Python
+FIND_PACKAGE(SalomeSIP REQUIRED)  # should come after Python and before PyQt4
 
 # Qt4
 FIND_PACKAGE(SalomeQt4 REQUIRED COMPONENTS QtCore QtGui QtXml QtWebKit QtOpenGL)
index d025b58afd4c6e408d41e6bb3a382e6d341f8a07..d4fa3b9594e8f454da131be46e11ba08ece59a1e 100644 (file)
@@ -1,6 +1,7 @@
 # - Find PyQt4 installation
 # Sets the following variables:
-#    PYQT_PYUIC_EXECUTABLE  - path to the pyuic4 executable
+#    PYQT_PYUIC_EXECUTABLE  - command to launch pyuic with the correct PYTHONPATH
+#    PYQT_PYUIC_PATH        - path to the pyuic executable
 #    PYQT_PYTHONPATH        - path to the PyQt Python modules
 #    PYQT_SIPS_DIR          - path to main include directory (which contains several sub folders)
 #    PYQT_INCLUDE_DIRS      - list of paths to include when compiling (all rooted on PYQT_SIP_DIRS)
@@ -42,10 +43,10 @@ IF(NOT PyQt4_FIND_QUIETLY)
   MESSAGE(STATUS "Looking for PyQt4 ...")
 ENDIF()
 
-FIND_PROGRAM(PYQT_PYUIC_EXECUTABLE NAMES pyuic4 pyuic4.bat)
+FIND_PROGRAM(PYQT_PYUIC_PATH NAMES pyuic4 pyuic4.bat)
 
 # Get root dir locally, going up two levels from the exec:
-GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${PYQT_PYUIC_EXECUTABLE}" PATH)
+GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${PYQT_PYUIC_PATH}" PATH)
 GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${_tmp_ROOT_DIR}" PATH)
 
 # Typical locations of qobject.sip are: 
@@ -61,9 +62,13 @@ ENDIF()
 MARK_AS_ADVANCED(PYQT_SIP_MAIN_FILE)
 
 # Get PyQt compilation flags:
-SET(PYQT_PYTHONPATH "${PYQT_PYTHONPATH}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages")
+SET(PYQT_PYTHONPATH "${_tmp_ROOT_DIR}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages")
 SET(PYQT_SIPFLAGS)
-EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import sys; sys.path[:0] = ['${PYQT_PYTHONPATH}']; from PyQt4 import pyqtconfig; sys.stdout.write(pyqtconfig.Configuration().pyqt_sip_flags)"
+EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import sys; 
+sys.path[:0] = ['${PYQT_PYTHONPATH}'] 
+sys.path[:0] = ['${SIP_PYTHONPATH}']
+from PyQt4 import pyqtconfig; 
+sys.stdout.write(pyqtconfig.Configuration().pyqt_sip_flags)"
   OUTPUT_VARIABLE PYQT_SIPFLAGS)
 SEPARATE_ARGUMENTS(PYQT_SIPFLAGS)
 
@@ -86,6 +91,14 @@ FOREACH(_dir ${PYQT_INCLUDE_DIRS})
   LIST(APPEND PYQT_SIPFLAGS -I ${_dir})
 ENDFOREACH()
 
+# Wrap the final executable so that it always uses the proper environment:
+IF(WIN32 AND NOT CYGWIN)
+  MESSAGE(WARNING "PyQt4 command was not tested under Linux")
+  SET(PYQT_PYUIC_EXECUTABLE set PYTHONPATH=${PYQT_PYTHONPATH};${SIP_PYTHONPATH} && ${PYQT_PYUIC_PATH})
+ELSE()
+  SET(PYQT_PYUIC_EXECUTABLE /usr/bin/env PYTHONPATH=${PYQT_PYTHONPATH}:${SIP_PYTHONPATH} ${PYQT_PYUIC_PATH})
+ENDIF()
+
 INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(PyQt4 REQUIRED_VARS PYQT_PYUIC_EXECUTABLE PYQT_SIPS_DIR PYQT_SIPFLAGS)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PyQt4 REQUIRED_VARS PYQT_PYUIC_PATH PYQT_SIPS_DIR PYQT_SIPFLAGS)
 
index 1a05df1152fde8c0fa0a7b2a0436ad198d76ae3a..5011f5d134e19fad8b77183faf391ac1f64f7b6f 100644 (file)
@@ -2,6 +2,7 @@
 # Sets the following variables:
 #   SIP_EXECUTABLE      - path to the SIP executable
 #   SIP_INCLUDE_DIR     - path to the SIP headers
+#   SIP_PYTHON_PATH     - path to the SIP Python packages
 #
 #  The header sip.h is looked for.
 #  The binary 'sip' is looked for.
@@ -37,7 +38,13 @@ ENDIF()
 FIND_PROGRAM(SIP_EXECUTABLE sip)
 FIND_PATH(SIP_INCLUDE_DIR sip.h PATH_SUFFIXES python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
 
+IF(SIP_INCLUDE_DIR)
+  GET_FILENAME_COMPONENT(SIP_PYTHONPATH "${SIP_INCLUDE_DIR}" PATH)
+  GET_FILENAME_COMPONENT(SIP_PYTHONPATH "${SIP_PYTHONPATH}" PATH)
+  SET(SIP_PYTHONPATH "${SIP_PYTHONPATH}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages")
+ENDIF()
+
 INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(SIP REQUIRED_VARS SIP_INCLUDE_DIR SIP_EXECUTABLE)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SIP REQUIRED_VARS SIP_INCLUDE_DIR SIP_EXECUTABLE SIP_PYTHONPATH)
 
 
index 0903ecadc561c01f49ca7849edfedcd0208716b9..358f3955ead6209cd3e000438f82667d64ae0a68 100644 (file)
 #
 #  !! Please read the generic detection procedure in SalomeMacros.cmake !!
 #
-SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(PyQt4 PYQT_PYUIC_EXECUTABLE 2)
+
+IF(NOT SalomeSIP_FOUND AND NOT SalomePyQt4_FIND_QUIETLY)
+   MESSAGE(WARNING "PyQt4 needs SIP to be found correctly!")
+ENDIF()   
+
+SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(PyQt4 PYQT_PYUIC_PATH 2)
 MARK_AS_ADVANCED(PYQT_PYUIC_EXECUTABLE PYQT_SIPS_DIR)
index 53a636543c20c800ba09723e71f4b4867dbdc060..102720c42ce4e55796271a870715cca43e023d1e 100755 (executable)
@@ -44,7 +44,9 @@ FOREACH(output ${PYUIC_FILES})
     OUTPUT ${output}
     COMMAND ${PYQT_PYUIC_EXECUTABLE} -o ${output} ${input}
     MAIN_DEPENDENCY ${input}
+    VERBATIM
   )
+  #${PYQT_PYUIC_EXECUTABLE}
 ENDFOREACH(output ${PYUIC_FILES})
 
 ADD_CUSTOM_TARGET(BUILD_PY_UI_FILES ALL DEPENDS ${PYUIC_FILES})