From 0581a83aa2dd16d441c4108dd78f3dff5a21c3a6 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Thu, 16 Jun 2016 10:36:20 -0600 Subject: [PATCH] Directly call python when executing expander.py On Unix-based systems, you can directly execute a script and the system will automatically run it through its associated interpreter. However, on Windows this does not work. You just get an error about the script, which is just a text file, being an invalid executable. This was an issue when running pyexpander. Now, Python is called directly for pyexpander. --- CMake/FindPyexpander.cmake | 5 +++++ CMake/VTKmCheckPyexpander.cmake | 17 +++++++++++------ CMake/VTKmMacros.cmake | 3 ++- CMakeLists.txt | 4 ++++ 4 files changed, 22 insertions(+), 7 deletions(-) mode change 100644 => 100755 CMake/FindPyexpander.cmake mode change 100644 => 100755 CMake/VTKmCheckPyexpander.cmake mode change 100644 => 100755 CMake/VTKmMacros.cmake mode change 100644 => 100755 CMakeLists.txt diff --git a/CMake/FindPyexpander.cmake b/CMake/FindPyexpander.cmake old mode 100644 new mode 100755 index f949b454c..e3fe496aa --- a/CMake/FindPyexpander.cmake +++ b/CMake/FindPyexpander.cmake @@ -28,6 +28,11 @@ # PYEXPANDER_FOUND - True if pyexpander is found # PYEXPANDER_COMMAND - The pyexpander executable # +# Note that on some platforms (such as Windows), you cannot execute a python +# script directly. Thus, it could be safer to execute the Python interpreter +# with PYEXPANDER_COMMAND as an argument. See FindPythonInterp.cmake for help +# in finding the Python interpreter. +# find_program(PYEXPANDER_COMMAND expander.py) diff --git a/CMake/VTKmCheckPyexpander.cmake b/CMake/VTKmCheckPyexpander.cmake old mode 100644 new mode 100755 index 820d7d182..90e5f4a13 --- a/CMake/VTKmCheckPyexpander.cmake +++ b/CMake/VTKmCheckPyexpander.cmake @@ -23,9 +23,14 @@ # version stored in the source code. If the versions are different, an # error message is printed with further instructions. # -# To use this script, the CMake variables PYEXPANDER_COMMAND, SOURCE_FILE, -# and GENERATED_FILE must be defined as the two files to compare. A ".in" -# is appended to SOURCE_FILE to get the pyexpander input. +# To use this script, the CMake variables PYTHON_EXECUTABLE PYEXPANDER_COMMAND, +# SOURCE_FILE, and GENERATED_FILE must be defined as the two files to compare. +# A ".in" is appended to SOURCE_FILE to get the pyexpander input. + +if(NOT PYTHON_EXECUTABLE) + message(SEND_ERROR "Variable PYTHON_EXECUTABLE must be set.") + return() +endif() if(NOT PYEXPANDER_COMMAND) message(SEND_ERROR "Variable PYEXPANDER_COMMAND must be set.") @@ -43,14 +48,14 @@ if(NOT GENERATED_FILE) endif() execute_process( - COMMAND ${PYEXPANDER_COMMAND} ${SOURCE_FILE}.in + COMMAND ${PYTHON_EXECUTABLE} ${PYEXPANDER_COMMAND} ${SOURCE_FILE}.in RESULT_VARIABLE pyexpander_result OUTPUT_VARIABLE pyexpander_output ) -if(${pyexpander_result}) +if(pyexpander_result) # If pyexpander returned non-zero, it failed. - message(SEND_ERROR "Running pyexpander failed.") + message(SEND_ERROR "Running pyexpander failed (${pyexpander_result}).") return() endif() diff --git a/CMake/VTKmMacros.cmake b/CMake/VTKmMacros.cmake old mode 100644 new mode 100755 index 960f01964..bfc7895fa --- a/CMake/VTKmMacros.cmake +++ b/CMake/VTKmMacros.cmake @@ -198,10 +198,11 @@ endfunction(vtkm_declare_worklets) function(vtkm_pyexpander_generated_file generated_file_name) # If pyexpander is available, add targets to build and check - if(PYEXPANDER_FOUND) + if(PYEXPANDER_FOUND AND PYTHONINTERP_FOUND) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${generated_file_name}.checked COMMAND ${CMAKE_COMMAND} + -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DPYEXPANDER_COMMAND=${PYEXPANDER_COMMAND} -DSOURCE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${generated_file_name} -DGENERATED_FILE=${CMAKE_CURRENT_BINARY_DIR}/${generated_file_name} diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 index b682596bd..dcde002ef --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,6 +207,10 @@ if(UNIX AND VTKm_ENABLE_OPENGL_INTEROP) find_package(Threads REQUIRED) endif() +#----------------------------------------------------------------------------- +# Find the Python interpreter, which we will use during the build process +find_package(PythonInterp) + #----------------------------------------------------------------------------- # Find Pyexpander in case somebody wants to update the auto generated # faux variadic template code