Explorar el Código

Remove Light wrapping CMake script and directly invoke python executable

See #449

System integrating CTK will be responsible to ensure the proper
environment is set to execute the python interpreter.
Jean-Christophe Fillion-Robin hace 11 años
padre
commit
c6032b2fd7
Se han modificado 2 ficheros con 11 adiciones y 112 borrados
  1. 11 19
      CMake/ctkMacroWrapPythonQt.cmake
  2. 0 93
      CMake/ctkScriptWrapPythonQt_Light.cmake

+ 11 - 19
CMake/ctkMacroWrapPythonQt.cmake

@@ -79,18 +79,10 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
     message(FATAL_ERROR "PYTHON_EXECUTABLE not specified or inexistent when calling ctkMacroWrapPythonQt")
   endif()
 
-  # Extract python lib path
-  get_filename_component(PYTHON_DIR_PATH ${PYTHON_EXECUTABLE} PATH)
-  set(PYTHON_LIBRARY_PATH ${PYTHON_DIR_PATH}/../lib)
-  if(WIN32)
-    set(PYTHON_LIBRARY_PATH ${PYTHON_DIR_PATH})
-  endif()
-
   # Clear log file
   file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/ctkMacroWrapPythonQt_log.txt" "")
 
   set(SOURCES_TO_WRAP)
-  set(SOURCES_TO_WRAP_ARG) # Custom_command argument
 
   # For each class
   foreach(FILE ${SOURCES})
@@ -136,7 +128,6 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
       endif()
 
       list(APPEND SOURCES_TO_WRAP ${TMP_INPUT})
-      set(SOURCES_TO_WRAP_ARG "${SOURCES_TO_WRAP_ARG}^^${TMP_INPUT}")
     endif()
   endforeach()
 
@@ -157,6 +148,11 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
     @ONLY
     )
 
+  set(extra_args)
+  if(verbose)
+    set(extra_args --extra-verbose)
+  endif()
+
   # Custom command allow to generate ${WRAPPING_NAMESPACE_UNDERSCORE}_${TARGET}_init.cpp and
   # associated wrappers ${WRAPPING_NAMESPACE_UNDERSCORE}_${TARGET}.cpp
   set(wrapper_init_cpp_filename ${wrap_int_dir}${WRAPPING_NAMESPACE_UNDERSCORE}_${TARGET}_init.cpp)
@@ -167,16 +163,12 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
       ${wrapper_h_filename}
     DEPENDS
       ${SOURCES_TO_WRAP}
-      ${CTK_CMAKE_DIR}/ctkScriptWrapPythonQt_Light.cmake
-    COMMAND ${CMAKE_COMMAND}
-      -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE}
-      -DPYTHON_LIBRARY_PATH:PATH=${PYTHON_LIBRARY_PATH}
-      -DWRAPPING_SCRIPT:FILEPATH=${CTK_CMAKE_DIR}/ctkWrapPythonQt.py
-      -DWRAPPING_NAMESPACE:STRING=${WRAPPING_NAMESPACE}
-      -DTARGET:STRING=${TARGET}
-      -DSOURCES:STRING=${SOURCES_TO_WRAP_ARG}
-      -DOUTPUT_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/${wrap_int_dir}
-      -P ${CTK_CMAKE_DIR}/ctkScriptWrapPythonQt_Light.cmake
+      ${CTK_CMAKE_DIR}/ctkWrapPythonQt.py
+    COMMAND ${PYTHON_EXECUTABLE} ${CTK_CMAKE_DIR}/ctkWrapPythonQt.py
+      --target=${TARGET}
+      --namespace=${WRAPPING_NAMESPACE}
+      --output-dir=${CMAKE_CURRENT_BINARY_DIR}/${wrap_int_dir} ${extra_args}
+      ${SOURCES_TO_WRAP}
     COMMENT "PythonQt Wrapping - Generating ${wrapper_init_cpp_filename}"
     VERBATIM
     )

+ 0 - 93
CMake/ctkScriptWrapPythonQt_Light.cmake

@@ -1,93 +0,0 @@
-###########################################################################
-#
-#  Library:   CTK
-#
-#  Copyright (c) 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.apache.org/licenses/LICENSE-2.0.txt
-#
-#  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.
-#
-###########################################################################
-
-#
-# ctkScriptWrapPythonQt_Light
-#
-
-#
-# This script should be invoked either as a CUSTOM_COMMAND
-# or from the command line using the following syntax:
-#
-#    cmake -DWRAPPING_SCRIPT:FILEPATH=/path/to/ctkWrapPythonQt.py
-#          -DWRAPPING_NAMESPACE:STRING=org.commontk -DTARGET:STRING=MyLib
-#          -DSOURCES:STRING="file1^^file2"
-#          -DOUTPUT_DIR:PATH=/path
-#          -DPYTHON_EXECUTABLE:FILEPATH=/path/to/python
-#          -DPYTHON_LIBRARY_PATH:PATH=/path/to/pythonlib
-#          -P ctkScriptWrapPythonQt_Light.cmake
-#
-
-#
-# LOG FILE:
-#   File ctkScriptWrapPythonQt_Light_log.txt will be created in the current directory.
-#   It will contain the list of class and the constructor signature that will be wrapped.
-#
-
-# Check for non-defined var
-foreach(var WRAPPING_NAMESPACE TARGET SOURCES)
-  if(NOT DEFINED ${var})
-    message(FATAL_ERROR "${var} not specified when calling ctkScriptWrapPythonQt")
-  endif()
-endforeach()
-
-# Check for non-existing ${var}
-foreach(var WRAPPING_SCRIPT OUTPUT_DIR PYTHON_EXECUTABLE PYTHON_LIBRARY_PATH)
-  if(NOT EXISTS ${${var}})
-    message(FATAL_ERROR "Failed to find ${var}=\"${${var}}\" when calling ctkScriptWrapPythonQt")
-  endif()
-endforeach()
-
-# Convert ^^ separated string to list
-string(REPLACE "^^" ";" SOURCES "${SOURCES}")
-
-if(WIN32)
-  set(ENV{PATH} ${PYTHON_LIBRARY_PATH};$ENV{PATH})
-elseif(APPLE)
-  set(ENV{DYLD_LIBRARY_PATH} ${PYTHON_LIBRARY_PATH}:$ENV{DYLD_LIBRARY_PATH})
-else()
-  set(ENV{LD_LIBRARY_PATH} ${PYTHON_LIBRARY_PATH}:$ENV{LD_LIBRARY_PATH})
-endif()
-
-set(verbose 0)
-
-set(extra_args)
-if(verbose)
-  set(extra_args --extra-verbose)
-endif()
-
-execute_process(
-  COMMAND ${PYTHON_EXECUTABLE} ${WRAPPING_SCRIPT}
-    --target=${TARGET} --namespace=${WRAPPING_NAMESPACE} --output-dir=${OUTPUT_DIR} ${extra_args}
-    ${SOURCES}
-  RESULT_VARIABLE result
-  OUTPUT_VARIABLE output
-  ERROR_VARIABLE error
-  OUTPUT_STRIP_TRAILING_WHITESPACE
-  )
-if(NOT result EQUAL 0)
-  message(FATAL_ERROR "Failed to wrap target: ${TARGET}\n${output}\n${error}")
-else()
-  if(verbose)
-    message(${output})
-  endif()
-endif()
-
-