Browse Source

Merge topic 'python_wrapping'

  COMP: In ctkMacroWrapPythonQt, updated path with python library path to make sure python executable works properly.
  ENH: Added macro ctkMacroSetPath that should be used instead of ctkFunctionExecuteProcess
Jean-Christophe Fillion-Robin 14 years ago
parent
commit
c7e37b7db4

+ 0 - 76
CMake/ctkExecuteProcess.cmake.in

@@ -1,76 +0,0 @@
-###########################################################################
-#
-#  Library:   CTK
-# 
-#  Copyright (c) 2010  Kitware Inc.
-#
-#  Licensed under the Apache License, Version 2.0 (the "License");
-#  you may not use this file except in compliance with the License.
-#  You may obtain a copy of the License at
-#
-#      http://www.commontk.org/LICENSE
-#
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-# 
-###########################################################################
-
-#
-# This script is configured and executed by ctkFunctionExecuteProcess
-#
-
-SET(PATH_LIST @CONFIG_PATH_LIST@)
-
-FOREACH(p ${PATH_LIST})
-  IF(WIN32)
-    SET(ENV{PATH} ${p};$ENV{PATH})
-  ELSEIF(APPLE)
-    SET(ENV{DYLD_LIBRARY_PATH} ${p}:$ENV{DYLD_LIBRARY_PATH})
-  ELSE()
-    SET(ENV{LD_LIBRARY_PATH} ${p}:$ENV{LD_LIBRARY_PATH})
-  ENDIF()
-ENDFOREACH()
-
-EXECUTE_PROCESS(
-  @CONFIG_COMMAND@
-  @CONFIG_WORKING_DIRECTORY@
-  @CONFIG_TIMEOUT@
-  @CONFIG_RESULT_VARIABLE@
-  @CONFIG_OUTPUT_VARIABLE@
-  @CONFIG_ERROR_VARIABLE@
-  @CONFIG_INPUT_FILE@
-  @CONFIG_OUTPUT_FILE@
-  @CONFIG_ERROR_FILE@
-  @CONFIG_OUTPUT_QUIET@
-  @CONFIG_ERROR_QUIET@
-  @CONFIG_OUTPUT_STRIP_TRAILING_WHITESPACE@
-  @CONFIG_ERROR_STRIP_TRAILING_WHITESPACE@
-  )
-
-SET(var "@VARNAME_RESULT_VARIABLE@")
-IF (NOT var STREQUAL "")
-  SET(SETTER_RESULT_VARIABLE "SET(@VARNAME_RESULT_VARIABLE@ ${@VARNAME_RESULT_VARIABLE@} PARENT_SCOPE)")
-ENDIF()
-
-SET(var "@VARNAME_OUTPUT_VARIABLE@")
-IF (NOT var STREQUAL "")
-  SET(SETTER_OUTPUT_VARIABLE "SET(@VARNAME_OUTPUT_VARIABLE@ ${@VARNAME_OUTPUT_VARIABLE@} PARENT_SCOPE)")
-ENDIF()
-
-SET(var "@VARNAME_ERROR_VARIABLE@")
-IF (NOT var STREQUAL "")
-  SET(SETTER_ERROR_VARIABLE "SET(@VARNAME_ERROR_VARIABLE@ ${@VARNAME_ERROR_VARIABLE@} PARENT_SCOPE)")
-ENDIF()
-
-file(WRITE "@CMAKE_CURRENT_BINARY_DIR@/CMake/ctkExecuteProcess-@EXECUTABLE_NAME@-output.cmake" "
-#
-# File auto-generated by @CMAKE_CURRENT_BINARY_DIR@/CMake/ctkExecuteProcess-@EXECUTABLE_NAME@-output.cmake
-#
-
-${SETTER_RESULT_VARIABLE}
-${SETTER_OUTPUT_VARIABLE}
-${SETTER_ERROR_VARIABLE}
-")

+ 0 - 103
CMake/ctkFunctionExecuteProcess.cmake

@@ -1,103 +0,0 @@
-###########################################################################
-#
-#  Library:   CTK
-# 
-#  Copyright (c) 2010  Kitware Inc.
-#
-#  Licensed under the Apache License, Version 2.0 (the "License");
-#  you may not use this file except in compliance with the License.
-#  You may obtain a copy of the License at
-#
-#      http://www.commontk.org/LICENSE
-#
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-# 
-###########################################################################
-
-#
-# Same as EXECUTE_PROCESS command except it can accept the extra parameter: PATH_LIST
-#
-# According to the platform, either PATH, LD_LIBRARY_PATH or DYLD_LIBRARY_PATH
-# will be updated using the paths specified using PATH_LIST
-#
-#
-
-FUNCTION(ctkFunctionExecuteProcess)
-  CtkMacroParseArguments(MY
-    "COMMAND;PATH_LIST;WORKING_DIRECTORY;TIMEOUT;RESULT_VARIABLE;OUTPUT_VARIABLE;ERROR_VARIABLE;INPUT_FILE;OUTPUT_FILE;ERROR_FILE"
-    "OUTPUT_QUIET;ERROR_QUIET;OUTPUT_STRIP_TRAILING_WHITESPACE;ERROR_STRIP_TRAILING_WHITESPACE"
-    ${ARGN}
-    )
-
-  # Sanity checks
-  IF(NOT DEFINED MY_COMMAND)
-    MESSAGE(SEND_ERROR "COMMAND is mandatory")
-  ENDIF()
-
-  # Extract executable
-  LIST(LENGTH MY_COMMAND command_length)
-  LIST(GET MY_COMMAND 0 MY_EXECUTABLE)
-  GET_FILENAME_COMPONENT(EXECUTABLE_NAME ${MY_EXECUTABLE} NAME_WE)
-  #MESSAGE("EXECUTABLE_NAME:${EXECUTABLE_NAME}")
-  
-  IF(NOT EXISTS ${MY_EXECUTABLE})
-    MESSAGE(FATAL_ERROR "Exectuable ${MY_EXECUTABLE} doesn't exist !")
-  ENDIF()
-  
-  # Command
-  SET(CONFIG_COMMAND COMMAND)
-  FOREACH(command_part ${MY_COMMAND})
-    SET(CONFIG_COMMAND "${CONFIG_COMMAND} \"${command_part}\"")
-  ENDFOREACH()
-  #MESSAGE(STATUS CONFIG_COMMAND:"${CONFIG_COMMAND}")
-
-  # Arguments list
-  SET(arg_names WORKING_DIRECTORY TIMEOUT RESULT_VARIABLE OUTPUT_VARIABLE ERROR_VARIABLE INPUT_FILE OUTPUT_FILE ERROR_FILE)
-  FOREACH(arg_name ${arg_names})
-    IF(DEFINED MY_${arg_name})
-      SET(CONFIG_${arg_name} "${arg_name} \"${MY_${arg_name}}\"")
-    ENDIF()
-  ENDFOREACH()
-
-  # Options list
-  SET(option_names OUTPUT_QUIET ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)
-  FOREACH(option_name ${option_names})
-    IF(${MY_${option_name}})
-      SET(CONFIG_${option_name} ${option_name})
-    ENDIF()
-  ENDFOREACH()
-
-  SET(CONFIG_PATH_LIST ${MY_PATH_LIST})
-  SET(VARNAME_RESULT_VARIABLE ${MY_RESULT_VARIABLE})
-  SET(VARNAME_OUTPUT_VARIABLE ${MY_OUTPUT_VARIABLE})
-  SET(VARNAME_ERROR_VARIABLE ${MY_ERROR_VARIABLE})
-
-  SET(cmd ${CMAKE_CURRENT_BINARY_DIR}/CMake/ctkExecuteProcess-${EXECUTABLE_NAME}.cmake)
-  CONFIGURE_FILE(
-    ${CMAKE_CURRENT_SOURCE_DIR}/CMake/ctkExecuteProcess.cmake.in
-    ${cmd}
-    @ONLY)
-
-  # Execute process
-  EXECUTE_PROCESS(
-    COMMAND ${CMAKE_COMMAND} -P "${cmd}"
-    RESULT_VARIABLE error_code
-    )
-
-  IF(error_code)
-    MESSAGE(FATAL_ERROR "Failed to execute ${cmd}")
-  ENDIF()
-  
-
-  SET(output_file "${CMAKE_CURRENT_BINARY_DIR}/CMake/ctkExecuteProcess-${EXECUTABLE_NAME}-output.cmake")
-  IF(NOT EXISTS ${output_file})
-    MESSAGE(FATAL_ERROR "Output file doesn't exist - Problem executing: ${cmd}")
-  ENDIF()
-
-  INCLUDE(${output_file})
-  
-ENDFUNCTION()

+ 36 - 0
CMake/ctkMacroSetPaths.cmake

@@ -0,0 +1,36 @@
+###########################################################################
+#
+#  Library:   CTK
+# 
+#  Copyright (c) 2010  Kitware Inc.
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.commontk.org/LICENSE
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+# 
+###########################################################################
+
+#
+# Depending on the platform, either PATH, LD_LIBRARY_PATH or DYLD_LIBRARY_PATH
+# will be updated using the paths specified using PATH_LIST
+#
+
+MACRO(ctkMacroSetPaths PATH_LIST)
+  FOREACH(p ${PATH_LIST})
+    IF(WIN32)
+      SET(ENV{PATH} ${p};$ENV{PATH})
+    ELSEIF(APPLE)
+      SET(ENV{DYLD_LIBRARY_PATH} ${p}:$ENV{DYLD_LIBRARY_PATH})
+    ELSE()
+      SET(ENV{LD_LIBRARY_PATH} ${p}:$ENV{LD_LIBRARY_PATH})
+    ENDIF()
+  ENDFOREACH()
+ENDMACRO()

+ 3 - 3
CMake/ctkMacroValidateBuildOptions.cmake

@@ -113,9 +113,9 @@ MACRO(ctkMacroValidateBuildOptions dir executable target_directories)
 
     IF(${${option_name}})
       # Obtain dependency path
-      ctkFunctionExecuteProcess(
+      ctkMacroSetPaths("${QT_INSTALLED_LIBRARY_DIR}")
+      EXECUTE_PROCESS(
         COMMAND "${executable}" "${CTK_BINARY_DIR}/DGraphInput-alldep.txt" -paths ${target_project_name}
-        PATH_LIST \"${QT_INSTALLED_LIBRARY_DIR}\"
         WORKING_DIRECTORY ${CTK_BINARY_DIR}
         RESULT_VARIABLE RESULT_VAR
         OUTPUT_VARIABLE dep_paths
@@ -149,4 +149,4 @@ MACRO(ctkMacroValidateBuildOptions dir executable target_directories)
   ENDFOREACH()
 
   #MESSAGE(STATUS "Validated: CTK_LIB_*, CTK_PLUGIN_*, CTK_APP_*")
-ENDMACRO()
+ENDMACRO()

+ 16 - 5
CMake/ctkMacroWrapPythonQt.cmake

@@ -67,7 +67,7 @@ ENDFUNCTION()
 # Convenient function allowing to invoke re.search(regex, string) using the given interpreter.
 # Note that is_matching will be set to True if there is a match
 #
-FUNCTION(ctkMacroWrapPythonQt_reSearchFile python_exe regex file is_matching)
+FUNCTION(ctkMacroWrapPythonQt_reSearchFile python_exe python_library_path regex file is_matching)
 
   set(python_cmd "import re\; f = open('${file}', 'r')\;
 res = re.search\(\"${regex}\", f.read(), re.MULTILINE\)\;
@@ -76,8 +76,9 @@ else: print \"TRUE\"
 ")
   #message("python_cmd: ${python_cmd}")
 
+  ctkMacroSetPaths("${python_library_path}")
   EXECUTE_PROCESS(
-    COMMAND ${python_exe} -c ${python_cmd};
+    COMMAND ${python_exe} -c ${python_cmd}
     RESULT_VARIABLE result
     OUTPUT_VARIABLE output
     ERROR_VARIABLE error
@@ -98,9 +99,17 @@ MACRO(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
   ENDIF()
   
   find_package(PythonInterp)
-  IF(NOT EXISTS "${PYTHON_EXECUTABLE}")
+  IF(NOT PYTHONINTERP_FOUND)
     MESSAGE(SEND_ERROR "PYTHON_EXECUTABLE not specified or inexistent when calling ctkMacroWrapPythonQt")
   ENDIF()
+
+  find_package(PythonLibs)
+  IF(NOT PYTHONLIBS_FOUND)
+    MESSAGE(SEND_ERROR "PYTHON_LIBRARY not specified or inexistent when calling ctkMacroWrapPythonQt")
+  ENDIF()
+
+  # Extract python lib path
+  get_filename_component(PYTHON_LIBRARY_PATH ${PYTHON_LIBRARY} PATH)
   
   # Clear log file
   FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/ctkMacroWrapPythonQt_log.txt" "")
@@ -167,7 +176,8 @@ MACRO(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
       IF(NOT IS_WRAP_FULL)
         # Constructor with either QWidget or QObject as first parameter
         SET(regex "[^~]${className}[\\s\\n]*\\([\\s\\n]*((QObject|QWidget)[\\s\\n]*\\*[\\s\\n]*\\w+[\\s\\n]*(\\=[\\s\\n]*(0|NULL)|,.*\\=.*\\)|\\)|\\)))")
-        ctkMacroWrapPythonQt_reSearchFile(${PYTHON_EXECUTABLE} ${regex} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} is_matching)
+        ctkMacroWrapPythonQt_reSearchFile(${PYTHON_EXECUTABLE} ${PYTHON_LIBRARY_PATH}
+                                          ${regex} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} is_matching)
         IF(NOT is_matching)
           SET(skip_wrapping TRUE)
           ctkMacroWrapPythonQt_log("${FILE}: skipping - Missing expected constructor signature")
@@ -178,7 +188,8 @@ MACRO(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
     IF(NOT skip_wrapping)
       # Skip wrapping if object has a virtual pure method 
       SET(regex "virtual[\\w\\n\\s\\(\\)]+\\=[\\s\\n]*(0|NULL)[\\s\\n]*\\x3b")
-      ctkMacroWrapPythonQt_reSearchFile(${PYTHON_EXECUTABLE} ${regex} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} is_matching)
+      ctkMacroWrapPythonQt_reSearchFile(${PYTHON_EXECUTABLE} ${PYTHON_LIBRARY_PATH}
+                                        ${regex} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} is_matching)
       IF(is_matching)
         SET(skip_wrapping TRUE)
         ctkMacroWrapPythonQt_log("${FILE}: skipping - Contains a virtual pure method")

+ 3 - 3
CMakeLists.txt

@@ -136,6 +136,7 @@ SET(CTK_LIBRARIES CACHE INTERNAL "CTK libraries" FORCE)
 # CMake Function(s) and Macro(s)
 #
 INCLUDE(CMake/ctkMacroParseArguments.cmake)
+INCLUDE(CMake/ctkMacroSetPaths.cmake)
 INCLUDE(CMake/ctkMacroListFilter.cmake)
 INCLUDE(CMake/ctkMacroBuildLib.cmake)
 INCLUDE(CMake/ctkMacroBuildPlugin.cmake)
@@ -146,7 +147,6 @@ INCLUDE(CMake/ctkMacroWrapPythonQt.cmake)
 INCLUDE(CMake/ctkMacroSetupQt.cmake)
 INCLUDE(CMake/ctkMacroTargetLibraries.cmake) # Import multiple macros
 INCLUDE(CMake/ctkFunctionExtractOptionNameAndValue.cmake)
-INCLUDE(CMake/ctkFunctionExecuteProcess.cmake)
 INCLUDE(CMake/ctkMacroValidateBuildOptions.cmake)
 INCLUDE(CMake/ctkMacroAddCtkLibraryOptions.cmake)
 INCLUDE(CMake/ctkFunctionGenerateDGraphInput.cmake)
@@ -427,9 +427,9 @@ ctkMacroValidateBuildOptions("${CTK_BINARY_DIR}" "${DGraph_EXECUTABLE}" "${targe
 ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}" TRUE)
 
 # Obtain list of target ordered topologically
-ctkFunctionExecuteProcess(
+ctkMacroSetPaths("${QT_INSTALLED_LIBRARY_DIR}")
+EXECUTE_PROCESS(
   COMMAND "${DGraph_EXECUTABLE}" "${CTK_BINARY_DIR}/DGraphInput.txt"
-  PATH_LIST \"${QT_INSTALLED_LIBRARY_DIR}\"
   WORKING_DIRECTORY ${CTK_BINARY_DIR}
   RESULT_VARIABLE RESULT_VAR
   OUTPUT_VARIABLE CTEST_PROJECT_SUBPROJECTS