From b2499ebee41ed6b245d23db144bf73dc67bc74b7 Mon Sep 17 00:00:00 2001 From: bruneton Date: Thu, 4 Jul 2013 14:22:02 +0000 Subject: [PATCH] CMake: wrote a safer command for the PyQt4 executable (ensuring the proper PYTHONPATH is set) --- CMakeLists.txt | 2 +- adm_local/cmake_files/FindPyQt4.cmake | 25 ++++++++++++++++----- adm_local/cmake_files/FindSIP.cmake | 9 +++++++- adm_local/cmake_files/FindSalomePyQt4.cmake | 7 +++++- src/GUI_PY/CMakeLists.txt | 2 ++ 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a2b1e5ec7..b5f4bb488 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/adm_local/cmake_files/FindPyQt4.cmake b/adm_local/cmake_files/FindPyQt4.cmake index d025b58af..d4fa3b959 100644 --- a/adm_local/cmake_files/FindPyQt4.cmake +++ b/adm_local/cmake_files/FindPyQt4.cmake @@ -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) diff --git a/adm_local/cmake_files/FindSIP.cmake b/adm_local/cmake_files/FindSIP.cmake index 1a05df115..5011f5d13 100644 --- a/adm_local/cmake_files/FindSIP.cmake +++ b/adm_local/cmake_files/FindSIP.cmake @@ -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) diff --git a/adm_local/cmake_files/FindSalomePyQt4.cmake b/adm_local/cmake_files/FindSalomePyQt4.cmake index 0903ecadc..358f3955e 100644 --- a/adm_local/cmake_files/FindSalomePyQt4.cmake +++ b/adm_local/cmake_files/FindSalomePyQt4.cmake @@ -23,5 +23,10 @@ # # !! 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) diff --git a/src/GUI_PY/CMakeLists.txt b/src/GUI_PY/CMakeLists.txt index 53a636543..102720c42 100755 --- a/src/GUI_PY/CMakeLists.txt +++ b/src/GUI_PY/CMakeLists.txt @@ -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}) -- 2.39.2