Text archives Help
- From:
- To:
- Subject: [Manta] r2311 - in trunk: CMake SwigInterface scenes/csafe scenes/csafe/python
- Date: Mon, 28 Jul 2008 22:30:57 -0600 (MDT)
Author: abe
Date: Mon Jul 28 22:30:56 2008
New Revision: 2311
Added:
trunk/CMake/PythonInvoke.cmake
trunk/CMake/python_invoke.cc.CMakeTemplate
trunk/CMake/python_invoke.csh.CMakeTemplate (contents, props changed)
trunk/scenes/csafe/python/CMakeLists.txt
Modified:
trunk/SwigInterface/CMakeLists.txt
trunk/scenes/csafe/CMakeLists.txt
Log:
Added convenience to create invocation scripts (or executables,
depending on platform) to setup the python path and launch a python
script. In visual studio the invocation executable may be targeted by
the IDE debugger to enable debugging through the python interface.
For example:
bin/objviewer -f ~/models/house.obj
Instead of:
source bin/pythonpath.csh
python ../SwigIterface/objviewer.py -f ~/models/house.obj
The invocation programs are created if the BUILD_SWIG_INTERFACE option
is enabled in CMake.
AM CMake/python_invoke.csh.CMakeTemplate
A CMake/python_invoke.cc.CMakeTemplate
A CMake/PythonInvoke.cmake
A scenes/csafe/python/CMakeLists.txt
M scenes/csafe/CMakeLists.txt
M SwigInterface/CMakeLists.txt
Added: trunk/CMake/PythonInvoke.cmake
==============================================================================
--- (empty file)
+++ trunk/CMake/PythonInvoke.cmake Mon Jul 28 22:30:56 2008
@@ -0,0 +1,117 @@
+#
+# The contents of this archive are governed by the following license:
+#
+# For more information, please see:
http://software.sci.utah.edu
+#
+# The MIT License
+#
+# Copyright (c) 2008
+# Scientific Computing and Imaging Institute, University of Utah
+#
+# License for the specific language governing rights and limitations under
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+#
+
+###############################################################################
+#
+# This macro creates an invocation shortcut for the specified python
+# script.
+#
+# For example:
+#
+# PYTHON_ADD_EXECUTABLE(cuda_test
+# ${CMAKE_CURRENT_SOURCE_DIR}/cuda_test.py
+# ${CMAKE_CURRENT_SOURCE_DIR}
+# ${LIBRARY_OUTPUT_PATH}
+# )
+#
+# Creates either an executable or script (depending on platform)
+# bin/cuda_test that executes the specified python file and sets the
+# python path to include the last two arguments.
+#
+###############################################################################
+
+
+
+MACRO(PYTHON_ADD_EXECUTABLE python_target python_source)
+
+ SET(PY_SOURCE_FILE ${python_source})
+
+ # Create a helper invocation script or executable.
+ IF (NOT WIN32)
+
+
###########################################################################
+ # Apple: create a script (pythonw workaround).
+
+ IF (APPLE)
+ SET(PY_COMMAND pythonw)
+ ELSE(APPLE)
+ SET(PY_COMMAND python)
+ ENDIF(APPLE)
+
+ # Construct the python search path.
+ SET(PY_SEARCH_PATH "")
+ FOREACH(path ${ARGN})
+ IF (WIN32)
+ STRING(REPLACE "/" "\\\\" path ${path}) # Convert slashes to
back slashes on windows.
+ ENDIF(WIN32)
+ SET(PY_SEARCH_PATH "${PY_SEARCH_PATH}\nsetenv PYTHONPATH
\"$PYTHONPATH\":${path}")
+ ENDFOREACH(path)
+
+ CONFIGURE_FILE (
+ ${CMAKE_SOURCE_DIR}/CMake/python_invoke.csh.CMakeTemplate
+ ${CMAKE_BINARY_DIR}/bin/${python_target}
+ )
+
+ ELSE (NOT WIN32)
+
+
###########################################################################
+ # Windows and Linux: create an executable (appears as target in visual
studio).
+
+ # Construct the python search path.
+ SET(PY_SEARCH_PATH "")
+ FOREACH(path ${ARGN})
+ IF (WIN32)
+ STRING(REPLACE "/" "\\\\" path ${path}) # Convert slashes to
back slashes on windows.
+ ENDIF(WIN32)
+ SET(PY_SEARCH_PATH "${PY_SEARCH_PATH}\n
PyRun_SimpleString(\"sys.path.append(r'${path}')\\n\");\n")
+ ENDFOREACH(path)
+
+ SET(target_source
"${CMAKE_BINARY_DIR}/src/${python_target}-generated.cc")
+
+ # Configure the invoker source file.
+ CONFIGURE_FILE(
+ ${CMAKE_SOURCE_DIR}/CMake/python_invoke.cc.CMakeTemplate
+ ${target_source}
+ )
+
+ # Add python include directory.
+ INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
+
+ # Add the executable.
+ ADD_EXECUTABLE(${python_target}
+ ${target_source}
+ )
+ TARGET_LINK_LIBRARIES(${python_target}
+ ${PYTHON_LIBRARY}
+ )
+
+ ENDIF (NOT WIN32)
+
+ENDMACRO(PYTHON_ADD_EXECUTABLE)
Added: trunk/CMake/python_invoke.cc.CMakeTemplate
==============================================================================
--- (empty file)
+++ trunk/CMake/python_invoke.cc.CMakeTemplate Mon Jul 28 22:30:56 2008
@@ -0,0 +1,50 @@
+
+#include <Python.h>
+#include <stdio.h>
+
+#include <vector>
+
+const char source_file[] = "${PY_SOURCE_FILE}";
+
+// This program provides an invocation target to run a specific python
+// script.
+int main(int argc, char **argv) {
+
+ // Open the source file.
+ FILE* fp = fopen( source_file, "r" );
+ if (fp == 0) {
+ perror("Could not open source file.");
+ return 1;
+ }
+
+ // Determine the file length.
+ fseek( fp, 0, SEEK_END );
+ const size_t bytes = ftell( fp );
+ fseek( fp, 0, SEEK_SET );
+
+ // Read in the file.
+ std::vector<char> buffer(bytes+1);
+ fread( &buffer[0], 1, bytes, fp );
+ buffer[bytes] = '\0';
+ fclose( fp );
+
+ // Setup python.
+ Py_Initialize();
+ PySys_SetArgv(argc,argv);
+
+ // Add hard coded paths.
+ PyRun_SimpleString("import sys\n");
+
+ // These lines added by CMAKE
///////////////////////////////////////////////
+ ${PY_SEARCH_PATH}
+
/////////////////////////////////////////////////////////////////////////////
+
+ // Invoke the script.
+ // PyRun_SimpleFile( fp, source_file );
+ PyRun_SimpleString( &buffer[0] );
+
+ // Clean up.
+ Py_Finalize();
+
+ return 0;
+}
Added: trunk/CMake/python_invoke.csh.CMakeTemplate
==============================================================================
--- (empty file)
+++ trunk/CMake/python_invoke.csh.CMakeTemplate Mon Jul 28 22:30:56 2008
@@ -0,0 +1,4 @@
+#!/bin/tcsh
+setenv PYTHONPATH ""
+${PY_SEARCH_PATH}
+${PY_COMMAND} ${PY_SOURCE_FILE} $*
Modified: trunk/SwigInterface/CMakeLists.txt
==============================================================================
--- trunk/SwigInterface/CMakeLists.txt (original)
+++ trunk/SwigInterface/CMakeLists.txt Mon Jul 28 22:30:56 2008
@@ -125,7 +125,24 @@
SWIG_ADD_MODULE(pycallback python pycallback.i pycallback.cc pycallback.h)
SWIG_LINK_LIBRARIES(pycallback ${PYTHON_LIBRARIES})
+############################################################
# Output a helper script for setting up path variables.
+INCLUDE(${CMAKE_SOURCE_DIR}/CMake/PythonInvoke.cmake)
+
+PYTHON_ADD_EXECUTABLE(runwxmanta
+ ${CMAKE_CURRENT_SOURCE_DIR}/runwxmanta.py
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${LIBRARY_OUTPUT_PATH}
+ )
+
+PYTHON_ADD_EXECUTABLE(objviewer
+ ${CMAKE_CURRENT_SOURCE_DIR}/objviewer.py
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${LIBRARY_OUTPUT_PATH}
+ )
+
+
+
FILE(WRITE ${CMAKE_BINARY_DIR}/bin/pythonpath.csh
"setenv PYTHONPATH
${CMAKE_SOURCE_DIR}/SwigInterface:${CMAKE_BINARY_DIR}/lib\n\n")
FILE(WRITE ${CMAKE_BINARY_DIR}/bin/pythonpath.sh
Modified: trunk/scenes/csafe/CMakeLists.txt
==============================================================================
--- trunk/scenes/csafe/CMakeLists.txt (original)
+++ trunk/scenes/csafe/CMakeLists.txt Mon Jul 28 22:30:56 2008
@@ -109,4 +109,5 @@
SUBDIRS(
swig
+ python
)
Added: trunk/scenes/csafe/python/CMakeLists.txt
==============================================================================
--- (empty file)
+++ trunk/scenes/csafe/python/CMakeLists.txt Mon Jul 28 22:30:56 2008
@@ -0,0 +1,9 @@
+
+INCLUDE(${CMAKE_SOURCE_DIR}/CMake/PythonInvoke.cmake)
+
+PYTHON_ADD_EXECUTABLE(csafe_demo
+ ${CMAKE_CURRENT_SOURCE_DIR}/csafe_demo.py
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/SwigInterface
+ ${LIBRARY_OUTPUT_PATH}
+ )
- [Manta] r2311 - in trunk: CMake SwigInterface scenes/csafe scenes/csafe/python, abe, 07/28/2008
Archive powered by MHonArc 2.6.16.