Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1186 - trunk/SwigInterface/test


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1186 - trunk/SwigInterface/test
  • Date: Mon, 21 Aug 2006 12:52:32 -0600 (MDT)

Author: bigler
Date: Mon Aug 21 12:52:31 2006
New Revision: 1186

Added:
   trunk/SwigInterface/test/
   trunk/SwigInterface/test/CMakeLists.txt
   trunk/SwigInterface/test/MantaUseSWIG.cmake
   trunk/SwigInterface/test/child.cc
   trunk/SwigInterface/test/child.h
   trunk/SwigInterface/test/child.i
   trunk/SwigInterface/test/depend.mk
   trunk/SwigInterface/test/empty.depend.in
   trunk/SwigInterface/test/make2cmake.py   (contents, props changed)
   trunk/SwigInterface/test/oldCML.txt
   trunk/SwigInterface/test/parent.h
   trunk/SwigInterface/test/parent.i
   trunk/SwigInterface/test/test.i
Log:

This is a test bed for breaking up a python module into components and
having the dependencies be handled properly.  Currently CMake will
regenerate the wrapper file only if the interface (.i) file changes.
This sucks when a header file included by the interface file changes
and you really should regenerate the wrapper file.

Swig will produce a dependency list (a la GCC) that is makefile
suitable, but CMake can't use it in that form.  There's a script that
will translate makefile depenencies into a form CMake can use
(make2cmake.py).  Since you have to have python around in order to
make the python bindings, I decided to use python for the conversion
script.

There is also a customized version of UseSWIG.cmake that has extra
facilities to generate and pull in this dependency file.  Currently
you have to run make twice to get make to do nothing.  The first pass
generates the files, and the second pass does something with CMake
that I can't figure out for now.

test/CMakeLists.txt

  Top level CMake file for testing this small python extension build.

test/MantaUseSWIG.cmake

  Customized version of UseSWIG (taken from the distribution).
  Extended to get swig to generate dependencies and to bring them in
  to the CMake build environment.

test/child.cc
test/child.h
test/child.i
test/parent.h
test/parent.i
test/test.i

  Test interface classes and stuff.

test/depend.mk

  Simple makefile that tests the dependency generation build chain.

test/empty.depend.in

  Blank used for the wrapper.cxx.depend stub.

test/make2cmake.py

  Python script for converting makefile dependencies into CMake
  readable form.

test/oldCML.txt

  The old CMakeLists.txt file that uses the standard build tools.


Added: trunk/SwigInterface/test/CMakeLists.txt
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/test/CMakeLists.txt     Mon Aug 21 12:52:31 2006
@@ -0,0 +1,36 @@
+SET(CMAKE_VERBOSE_MAKEFILE ON)
+
+SET(BUILD_SWIG_INTERFACE TRUE CACHE BOOL "Check for swig/python")
+IF(BUILD_SWIG_INTERFACE)
+IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 2.1)
+  # This will dump all the interface files in the library path.  Note
+  # that this needs to be set before you try to find swig.
+  SET(CMAKE_SWIG_OUTDIR ${LIBRARY_OUTPUT_PATH})
+  # Only process the swig directory if we have swig stuff
+  FIND_PACKAGE(SWIG)
+  IF (SWIG_FOUND)
+   SET(MAIN_SUBDIRS ${MAIN_SUBDIRS} SwigInterface)
+  ENDIF (SWIG_FOUND)
+ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 2.1)
+ENDIF(BUILD_SWIG_INTERFACE)
+
+FIND_PACKAGE(PythonLibs)
+INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+
+INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/MantaUseSWIG.cmake)
+
+MACRO(MANTA_BUILD_SWIG_MODULE module_name interface_file)
+  SET_SOURCE_FILES_PROPERTIES(${interface_file} PROPERTIES CPLUSPLUS ON)
+  SET_SOURCE_FILES_PROPERTIES(${interface_file} PROPERTIES SWIG_FLAGS 
"-Wall")
+
+  SWIG_ADD_MODULE(${module_name} python ${interface_file} ${ARGN})
+  SWIG_LINK_LIBRARIES(${module_name} ${PYTHON_LIBRARIES})
+ENDMACRO(MANTA_BUILD_SWIG_MODULE)
+
+MANTA_BUILD_SWIG_MODULE(test test.i)
+MANTA_BUILD_SWIG_MODULE(child child.i child.cc child.h)
+MANTA_BUILD_SWIG_MODULE(parent parent.i parent.h)
+
+

Added: trunk/SwigInterface/test/MantaUseSWIG.cmake
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/test/MantaUseSWIG.cmake Mon Aug 21 12:52:31 2006
@@ -0,0 +1,335 @@
+#
+# SWIG module for CMake
+# 
+# Defines the following macros:
+#
+#   SWIG_ADD_MODULE(name language [ files ])
+#     - Define swig module with given name and specified language
+#
+#   SWIG_LINK_LIBRARIES(name [ libraries ])
+#     - Link libraries to swig module
+#
+# All other macros are for internal use only.
+#
+# To get the actual name of the swig module, use: 
${SWIG_MODULE_name_REAL_NAME}.
+# Set Source files propertis such as CPLUSPLUS and SWIG_FLAGS to specify
+# special behavior of SWIG. Also global CMAKE_SWIG_FLAGS can be used to add
+# special flags to all swig calls.
+# Another special variable is CMAKE_SWIG_OUTDIR, it allows one to specify 
+# where to write all the swig generated module (swig -outdir option)
+
+#######################################################################
+# This was taken and adapted from the CMake distribution.
+
+# cmake version 2.2-patch 3
+# Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#  * Redistributions of source code must retain the above copyright notice,
+#     this list of conditions and the following disclaimer.
+#  * Redistributions in binary form must reproduce the above copyright 
notice,
+#     this list of conditions and the following disclaimer in the 
documentation
+#     and/or other materials provided with the distribution.
+#  * The names of Kitware, Inc., the Insight Consortium, or the names of any
+#     consortium members, or of any contributors, may not be used to endorse 
or
+#     promote products derived from this software without specific prior
+#     written permission.
+#  * Modified source versions must be plainly marked as such, and must not be
+#     misrepresented as being the original software.
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS 
IS''
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 
FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# We need python to do some dependency checks
+FIND_PACKAGE(PythonInterp)
+IF(NOT PYTHONINTERP_FOUND)
+  MESSAGE(FATAL_ERROR "Could not find python interpreter")
+ENDIF(NOT PYTHONINTERP_FOUND)
+
+SET(SWIG_CXX_EXTENSION "cxx")
+SET(SWIG_EXTRA_LIBRARIES "")
+
+SET(SWIG_PYTHON_EXTRA_FILE_EXTENSION "py")
+
+#
+# For given swig module initialize variables associated with it
+#
+MACRO(SWIG_MODULE_INITIALIZE name language)
+  STRING(TOUPPER "${language}" swig_uppercase_language)
+  STRING(TOLOWER "${language}" swig_lowercase_language)
+  SET(SWIG_MODULE_${name}_LANGUAGE "${swig_uppercase_language}")
+  SET(SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG "${swig_lowercase_language}")
+
+  IF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xUNKNOWNx$")
+    MESSAGE(FATAL_ERROR "SWIG Error: Language \"${language}\" not found")
+  ENDIF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xUNKNOWNx$")
+
+  SET(SWIG_MODULE_${name}_REAL_NAME "${name}")
+  IF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPYTHONx$")
+    SET(SWIG_MODULE_${name}_REAL_NAME "_${name}")
+  ENDIF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPYTHONx$")
+  IF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPERLx$")
+    SET(SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow")
+  ENDIF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPERLx$")
+ENDMACRO(SWIG_MODULE_INITIALIZE)
+
+#
+# For a given language, input file, and output file, determine extra files 
that
+# will be generated. This is internal swig macro.
+#
+
+MACRO(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile)
+  FOREACH(it ${SWIG_PYTHON_EXTRA_FILE_EXTENSION})
+    SET(outfiles ${outfiles}
+      "${generatedpath}/${infile}.${it}")
+  ENDFOREACH(it)
+ENDMACRO(SWIG_GET_EXTRA_OUTPUT_FILES)
+
+#####################################################################
+## MANTA_INCLUDE_SWIG_DEPENDENCIES
+##
+
+# So we want to try and include the dependency file if it exists.  If
+# it doesn't exist then we need to create an empty one, so we can
+# include it.
+
+# If it does exist, then we need to check to see if all the files it
+# depends on exist.  If they don't then we should clear the dependency
+# file and regenerate it later.  This covers the case where a header
+# file has disappeared or moved.
+
+MACRO(MANTA_INCLUDE_SWIG_DEPENDENCIES dependency_file)
+  MESSAGE("MANTA_INCLUDE_SWIG_DEPENDENCIES, ${dependency_file}")
+  SET(MANTA_SWIG_DEPEND)
+  SET(MANTA_SWIG_DEPEND_REGENERATE)
+
+  # Include the dependency file.  Create it first if it doesn't exist
+  # for make files except for IDEs (see below).
+  IF(${CMAKE_MAKE_PROGRAM} MATCHES "make")
+    IF(EXISTS ${dependency_file})
+    ELSE(EXISTS ${dependency_file})
+      MESSAGE("GENERATING stub dependency file")
+      CONFIGURE_FILE(
+        ${CMAKE_SOURCE_DIR}/empty.depend.in
+        ${dependency_file} IMMEDIATE)
+    ENDIF(EXISTS ${dependency_file})
+    INCLUDE(${dependency_file})
+  ELSE(${CMAKE_MAKE_PROGRAM} MATCHES "make")
+    # for IDE generators like MS dev only include the depend files
+    # if they exist.   This is to prevent ecessive reloading of
+    # workspaces after each build.   This also means
+    # that the depends will not be correct until cmake
+    # is run once after the build has completed once.
+    # the depend files are created in the wrap tcl/python sections
+    # when the .xml file is parsed.
+    INCLUDE(${dependency_file} OPTIONAL)
+  ENDIF(${CMAKE_MAKE_PROGRAM} MATCHES "make")
+
+  # Now we need to verify the existence of all the included files
+  # here.  If they aren't there we need to just blank this variable and
+  # make the file regenerate again.
+  IF(MANTA_SWIG_DEPEND)
+    FOREACH(f ${MANTA_SWIG_DEPEND})
+      IF(EXISTS ${f})
+      ELSE(EXISTS ${f})
+        SET(MANTA_SWIG_DEPEND_REGENERATE 1)
+      ENDIF(EXISTS ${f})
+    ENDFOREACH(f)
+  ELSE(MANTA_SWIG_DEPEND)
+    # No dependencies, so regenerate the file.
+    SET(CABLE_SWIG_DEPEND_REGENERATE 1)
+  ENDIF(MANTA_SWIG_DEPEND)
+
+  # No incoming dependencies, so we need to generate them.  Make the
+  # output depend on the dependency file itself, which should cause the
+  # rule to re-run.
+  IF(MANTA_SWIG_DEPEND_REGENERATE)
+    SET(MANTA_SWIG_DEPEND ${dependency_file})
+    CONFIGURE_FILE(
+      ${CMAKE_SOURCE_DIR}/empty.depend.in
+      ${dependency_file} IMMEDIATE)
+  ENDIF(MANTA_SWIG_DEPEND_REGENERATE)
+      
+ENDMACRO(MANTA_INCLUDE_SWIG_DEPENDENCIES)
+
+#
+# Take swig (*.i) file and add proper custom commands for it
+#
+MACRO(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
+  SET(swig_full_infile ${infile})
+  GET_FILENAME_COMPONENT(swig_source_file_path "${infile}" PATH)
+  GET_FILENAME_COMPONENT(swig_source_file_name_we "${infile}" NAME_WE)
+  GET_SOURCE_FILE_PROPERTY(swig_source_file_generated ${infile} GENERATED)
+  GET_SOURCE_FILE_PROPERTY(swig_source_file_cplusplus ${infile} CPLUSPLUS)
+  GET_SOURCE_FILE_PROPERTY(swig_source_file_flags ${infile} SWIG_FLAGS)
+  IF("${swig_source_file_flags}" STREQUAL "NOTFOUND")
+    SET(swig_source_file_flags "")
+  ENDIF("${swig_source_file_flags}" STREQUAL "NOTFOUND")
+  SET(swig_source_file_fullname "${infile}")
+  IF(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_SOURCE_DIR}")
+    STRING(REGEX REPLACE 
+      "^${CMAKE_CURRENT_SOURCE_DIR}" ""
+      swig_source_file_relative_path
+      "${swig_source_file_path}")
+  ELSE(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_SOURCE_DIR}")
+    IF(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_BINARY_DIR}")
+      STRING(REGEX REPLACE 
+        "^${CMAKE_CURRENT_BINARY_DIR}" ""
+        swig_source_file_relative_path
+        "${swig_source_file_path}")
+      SET(swig_source_file_generated 1)
+    ELSE(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_BINARY_DIR}")
+      SET(swig_source_file_relative_path "${swig_source_file_path}")
+      IF(swig_source_file_generated)
+        SET(swig_source_file_fullname 
"${CMAKE_CURRENT_BINARY_DIR}/${infile}")
+      ELSE(swig_source_file_generated)
+        SET(swig_source_file_fullname 
"${CMAKE_CURRENT_SOURCE_DIR}/${infile}")
+      ENDIF(swig_source_file_generated)
+    ENDIF(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_BINARY_DIR}")
+  ENDIF(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_SOURCE_DIR}")
+
+  SET(swig_generated_file_fullname
+    "${CMAKE_CURRENT_BINARY_DIR}")
+  IF(swig_source_file_relative_path)
+    SET(swig_generated_file_fullname
+      "${swig_generated_file_fullname}/${swig_source_file_relative_path}")
+  ENDIF(swig_source_file_relative_path)
+  SWIG_GET_EXTRA_OUTPUT_FILES(${SWIG_MODULE_${name}_LANGUAGE}
+    swig_extra_generated_files
+    "${swig_generated_file_fullname}"
+    "${swig_source_file_name_we}")
+  SET(swig_generated_file_fullname
+    "${swig_generated_file_fullname}/${swig_source_file_name_we}")
+  # add the language into the name of the file (i.e. TCL_wrap)
+  # this allows for the same .i file to be wrapped into different languages
+  SET(swig_generated_file_fullname
+    "${swig_generated_file_fullname}${SWIG_MODULE_${name}_LANGUAGE}_wrap")
+
+  IF(swig_source_file_cplusplus)
+    SET(swig_generated_file_fullname
+      "${swig_generated_file_fullname}.${SWIG_CXX_EXTENSION}")
+  ELSE(swig_source_file_cplusplus)
+    SET(swig_generated_file_fullname
+      "${swig_generated_file_fullname}.c")
+  ENDIF(swig_source_file_cplusplus)
+
+  #MESSAGE("Full path to source file: ${swig_source_file_fullname}")
+  #MESSAGE("Full path to the output file: ${swig_generated_file_fullname}")
+  GET_DIRECTORY_PROPERTY(cmake_include_directories INCLUDE_DIRECTORIES)
+  SET(swig_include_dirs)
+  FOREACH(it ${cmake_include_directories})
+    SET(swig_include_dirs ${swig_include_dirs} "-I${it}")
+  ENDFOREACH(it)
+
+  SET(swig_special_flags)
+  # default is c, so add c++ flag if it is c++
+  IF(swig_source_file_cplusplus)
+    SET(swig_special_flags ${swig_special_flags} "-c++")
+  ENDIF(swig_source_file_cplusplus)
+  SET(swig_extra_flags)
+  IF(SWIG_MODULE_${name}_EXTRA_FLAGS)
+    SET(swig_extra_flags ${swig_extra_flags} 
${SWIG_MODULE_${name}_EXTRA_FLAGS})
+  ENDIF(SWIG_MODULE_${name}_EXTRA_FLAGS)
+
+  # Bring in the dependencies.  Creates a variable MANTA_SWIG_DEPEND
+  SET(cmake_dependency_file "${swig_generated_file_fullname}.depend")
+  MANTA_INCLUDE_SWIG_DEPENDENCIES(${cmake_dependency_file})
+  SET(swig_generated_dependency_file
+    "${swig_generated_file_fullname}.swig-depend")
+
+  MESSAGE("MANTA_SWIG_DEPEND =" ${MANTA_SWIG_DEPEND})
+
+  # If CMAKE_SWIG_OUTDIR was specified then pass it to -outdir
+  IF(CMAKE_SWIG_OUTDIR)
+  ADD_CUSTOM_COMMAND(
+    OUTPUT "${swig_generated_file_fullname}"
+    COMMAND "${SWIG_EXECUTABLE}"
+    ARGS "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}"
+    -MD -MF "${swig_generated_dependency_file}"
+    ${swig_source_file_flags}
+    ${CMAKE_SWIG_FLAGS}
+      -outdir ${CMAKE_SWIG_OUTDIR}
+    ${swig_special_flags}
+    ${swig_extra_flags}
+    ${swig_include_dirs}
+    -o "${swig_generated_file_fullname}"
+    "${swig_source_file_fullname}"
+    COMMAND "${PYTHONINTERP}"
+    ARGS "${CMAKE_CURRENT_SOURCE_DIR}/make2cmake.py" 
${swig_generated_dependency_file} ${cmake_dependency_file}
+    MAIN_DEPENDENCY "${swig_source_file_fullname}"
+    DEPENDS ${MANTA_SWIG_DEPEND}
+    COMMENT "Swig source") 
+  ELSE(CMAKE_SWIG_OUTDIR)
+    ADD_CUSTOM_COMMAND(
+      OUTPUT "${swig_generated_file_fullname}"
+      COMMAND "${SWIG_EXECUTABLE}"
+      ARGS "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}"
+      -MD -MF "${swig_generated_dependency_file}"
+      ${swig_source_file_flags}
+      ${CMAKE_SWIG_FLAGS}
+      ${swig_outdir_flags}
+      ${swig_special_flags}
+      ${swig_extra_flags}
+      ${swig_include_dirs}
+      -o "${swig_generated_file_fullname}"
+      "${swig_source_file_fullname}"
+      COMMAND "${PYTHON_EXECUTABLE}"
+      ARGS "${CMAKE_CURRENT_SOURCE_DIR}/make2cmake.py" 
${swig_generated_dependency_file} ${cmake_dependency_file}
+      MAIN_DEPENDENCY "${swig_source_file_fullname}"
+      DEPENDS ${MANTA_SWIG_DEPEND}
+      COMMENT "Swig source") 
+  ENDIF(CMAKE_SWIG_OUTDIR)
+  SET_SOURCE_FILES_PROPERTIES("${swig_generated_file_fullname}"
+    PROPERTIES GENERATED 1)
+  SET(${outfiles} "${swig_generated_file_fullname}")
+ENDMACRO(SWIG_ADD_SOURCE_TO_MODULE)
+
+#
+# Create Swig module
+#
+MACRO(SWIG_ADD_MODULE name language)
+  SWIG_MODULE_INITIALIZE(${name} ${language})
+  SET(swig_dot_i_sources)
+  SET(swig_other_sources)
+  FOREACH(it ${ARGN})
+    IF(${it} MATCHES ".*\\.i$")
+      SET(swig_dot_i_sources ${swig_dot_i_sources} "${it}")
+    ELSE(${it} MATCHES ".*\\.i$")
+      SET(swig_other_sources ${swig_other_sources} "${it}")
+    ENDIF(${it} MATCHES ".*\\.i$")
+  ENDFOREACH(it)
+
+  SET(swig_generated_sources)
+  FOREACH(it ${swig_dot_i_sources})
+    SWIG_ADD_SOURCE_TO_MODULE(${name} swig_generated_source ${it})
+    SET(swig_generated_sources ${swig_generated_sources} 
"${swig_generated_source}")
+  ENDFOREACH(it)
+  GET_DIRECTORY_PROPERTY(swig_extra_clean_files ADDITIONAL_MAKE_CLEAN_FILES)
+  SET_DIRECTORY_PROPERTIES(PROPERTIES
+    ADDITIONAL_MAKE_CLEAN_FILES 
"${swig_extra_clean_files};${swig_generated_sources}")
+  ADD_LIBRARY(${SWIG_MODULE_${name}_REAL_NAME}
+    MODULE
+    ${swig_generated_sources}
+    ${swig_other_sources})
+  SET_TARGET_PROPERTIES(${SWIG_MODULE_${name}_REAL_NAME}
+    PROPERTIES PREFIX "")
+ENDMACRO(SWIG_ADD_MODULE)
+
+#
+# Like TARGET_LINK_LIBRARIES but for swig modules
+#
+MACRO(SWIG_LINK_LIBRARIES name)
+  IF(SWIG_MODULE_${name}_REAL_NAME)
+    TARGET_LINK_LIBRARIES(${SWIG_MODULE_${name}_REAL_NAME} ${ARGN})
+  ELSE(SWIG_MODULE_${name}_REAL_NAME)
+    MESSAGE(SEND_ERROR "Cannot find Swig library \"${name}\".")
+  ENDIF(SWIG_MODULE_${name}_REAL_NAME)
+ENDMACRO(SWIG_LINK_LIBRARIES name)
+

Added: trunk/SwigInterface/test/child.cc
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/test/child.cc   Mon Aug 21 12:52:31 2006
@@ -0,0 +1,15 @@
+#include "child.h"
+
+#include <iostream>
+
+using namespace std;
+using namespace Test;
+
+Child::Child(int arg): Parent("Child"), arg(arg)
+{
+  whoami();
+}
+
+void Child::whoami() {
+  cerr << "I am a Child with arg = "<<arg<<", and name = "<<name<<"\n";
+}

Added: trunk/SwigInterface/test/child.h
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/test/child.h    Mon Aug 21 12:52:31 2006
@@ -0,0 +1,17 @@
+#include "parent.h"
+
+#include <string>
+
+using namespace std;
+
+namespace Test {
+  class Child: public Parent {
+  public:
+    Child(int arg);
+    virtual void whoami();
+
+  private:
+    int arg;
+  };
+
+} // end namespace Test

Added: trunk/SwigInterface/test/child.i
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/test/child.i    Mon Aug 21 12:52:31 2006
@@ -0,0 +1,9 @@
+%module child
+
+%import "parent.i"
+
+%{
+#include "child.h"
+%}
+
+%include "child.h"

Added: trunk/SwigInterface/test/depend.mk
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/test/depend.mk  Mon Aug 21 12:52:31 2006
@@ -0,0 +1,16 @@
+CXXPATH = /home/sci/bigler/manta/trunk/SwigInterface/test
+
+default: child.o
+
+child-copy.d:
+       touch child-copy.d
+
+include child-copy.d
+
+child.o: $(CXXPATH)/child.cc
+       g++ -c $< -o $@ -MD
+       cp child.d child-copy.d
+
+clean:
+       rm -f child.o child.d child-copy.d
+

Added: trunk/SwigInterface/test/empty.depend.in
==============================================================================

Added: trunk/SwigInterface/test/make2cmake.py
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/test/make2cmake.py      Mon Aug 21 12:52:31 2006
@@ -0,0 +1,38 @@
+#!/usr/bin/python
+
+import os,sys,string
+
+
+if __name__ == "__main__":
+    # Check the argument list size
+    if (len(sys.argv) < 3):
+        sys.stderr.write("USAGE: " + sys.argv[0] + " <input file> <output 
file>\n")
+        sys.exit(1)
+
+    infilename = sys.argv[1]
+    outfilename = sys.argv[2]
+
+    # Only generate the output file if the input file is newer (bigger
+    # numbers are newer).
+    if (os.path.getmtime(infilename) <= os.path.getmtime(outfilename)):
+        print " ---------------------- Not generating" + outfilename
+        sys.exit(0)
+    else:
+        print " ++++++++++++++++++++++ Generating: " + outfilename
+    
+    # U is the mode to open the file with universal newline support.
+    infile = open(infilename, "rU")
+    outfile = open(outfilename, "w")
+
+    # Now read the lines
+    lines = map( lambda x: string.strip(x, string.whitespace+"\\"),
+                 infile.readlines() )
+    infile.close()
+    
+    # Now write them
+    outfile.write("SET( MANTA_SWIG_DEPEND\n")
+    for l in lines[1:]:
+        outfile.write(l + "\n")
+    outfile.write(")\n")
+    outfile.close()
+    

Added: trunk/SwigInterface/test/oldCML.txt
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/test/oldCML.txt Mon Aug 21 12:52:31 2006
@@ -0,0 +1,62 @@
+SET(CMAKE_VERBOSE_MAKEFILE ON)
+
+SET(BUILD_SWIG_INTERFACE TRUE CACHE BOOL "Check for swig/python")
+IF(BUILD_SWIG_INTERFACE)
+IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.9)
+  # This will dump all the interface files in the library path.  Note
+  # that this needs to be set before you try to find swig.
+  SET(CMAKE_SWIG_OUTDIR ${LIBRARY_OUTPUT_PATH})
+  # Only process the swig directory if we have swig stuff
+  FIND_PACKAGE(SWIG)
+  IF (SWIG_FOUND)
+   SET(MAIN_SUBDIRS ${MAIN_SUBDIRS} SwigInterface)
+  ENDIF (SWIG_FOUND)
+ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.9)
+ENDIF(BUILD_SWIG_INTERFACE)
+
+INCLUDE(${SWIG_USE_FILE})
+
+FIND_PACKAGE(PythonLibs)
+INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+
+MACRO(MANTA_BUILD_SWIG_MODULE module_name interface_file)
+  SET_SOURCE_FILES_PROPERTIES(${interface_file} PROPERTIES CPLUSPLUS ON)
+  SET_SOURCE_FILES_PROPERTIES(${interface_file} PROPERTIES SWIG_FLAGS 
"-Wall")
+
+  SWIG_ADD_MODULE(${module_name} python ${interface_file} ${ARGN})
+  SWIG_LINK_LIBRARIES(${module_name} ${PYTHON_LIBRARIES})
+ENDMACRO(MANTA_BUILD_SWIG_MODULE)
+
+MANTA_BUILD_SWIG_MODULE(test test.i)
+MANTA_BUILD_SWIG_MODULE(child child.i child.cc child.h)
+MANTA_BUILD_SWIG_MODULE(parent parent.i parent.h)
+
+MACRO(MANTA_CREATE_SWIG_DEPENDENCIES Bin Output)
+  SET(MANTA_SWIG_DEPEND)
+  SET(MANTA_SWIG_DEPEND_REGENERATE)
+
+  # Include the dependency file.  Create it first if it doesn't exist
+  # for make files except for IDEs (see below).
+  IF(${CMAKE_MAKE_PROGRAM} MATCHES "make")
+    IF(EXISTS ${Bin}/${Output}.depend)
+    ELSE(EXISTS ${Bin}/${Output}.depend)
+      CONFIGURE_FILE(
+        ${CMAKE_SOURCE_DIR}/SwigInterface/test/empty.depend.in
+        ${Bin}/${Output}.depend IMMEDIATE)
+    ENDIF(EXISTS ${Bin}/${Output}.depend)
+    INCLUDE(${Bin}/${Output}.depend)
+  ELSE(${CMAKE_MAKE_PROGRAM} MATCHES "make")
+    # for IDE generators like MS dev only include the depend files
+    # if they exist.   This is to prevent ecessive reloading of
+    # workspaces after each build.   This also means
+    # that the depends will not be correct until cmake
+    # is run once after the build has completed once.
+    # the depend files are created in the wrap tcl/python sections
+    # when the .xml file is parsed.
+    INCLUDE(${Bin}/${Output}.depend OPTIONAL)
+  ENDIF(${CMAKE_MAKE_PROGRAM} MATCHES "make")
+
+  
+ENDMACRO(MANTA_CREATE_SWIG_DEPENDENCIES)
\ No newline at end of file

Added: trunk/SwigInterface/test/parent.h
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/test/parent.h   Mon Aug 21 12:52:31 2006
@@ -0,0 +1,20 @@
+
+#include <iostream>
+#include <string>
+
+using namespace std;
+
+namespace Test {
+  class Parent {
+  public:
+    Parent(): name("Parent") {}
+    Parent(const string& name): name(name) {}
+
+    virtual void whoami() {
+      cerr << "I am a Parent with name = "<<name<<"\n";
+    }
+  protected:
+    string name;
+  };
+
+} // end namespace Test

Added: trunk/SwigInterface/test/parent.i
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/test/parent.i   Mon Aug 21 12:52:31 2006
@@ -0,0 +1,7 @@
+%module parent
+
+%{
+#include "parent.h"
+%}
+
+%include "parent.h"

Added: trunk/SwigInterface/test/test.i
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/test/test.i     Mon Aug 21 12:52:31 2006
@@ -0,0 +1,5 @@
+%module test
+
+%import "parent.i"
+%import "child.i"
+




  • [MANTA] r1186 - trunk/SwigInterface/test, bigler, 08/21/2006

Archive powered by MHonArc 2.6.16.

Top of page