]> Creatis software - gdcm.git/blobdiff - gdcmPython/CMakeLists.txt
ENH: Cleanup the cmakelist, cmake 1.8 was barely supported anyway
[gdcm.git] / gdcmPython / CMakeLists.txt
index c7e9f69572825dbd482a6f4122e771fadff2c5bd..9581048645b7eb5fbe33a89a3c34b0901ed01338 100644 (file)
-#IF(GDCM_WRAP_PYTHON)
-#If we reach this dir we have selected this option
-
-
-#TODO
-#http://www.cmake.org/pipermail/cmake/2003-August/004185.html
-#http://www.cmake.org/pipermail/cmake/2003-January/001092.html
-
+# gdcm Python wrapping stuff:
 
 INCLUDE_DIRECTORIES(
   ${GDCM_SOURCE_DIR}/src
   ${PYTHON_INCLUDE_PATH}
-)
-
-SET(GDCM_INC
-  ${GDCM_SOURCE_DIR}/src
-#  -I$(top_builddir)
-)
-
-SET(SWIG_INC
-  ${PYTHON_INCLUDES}
-  ${GDCM_INC}
-)
-
-ADD_CUSTOM_TARGET(mathieu ALL)
-
-SET(GDCM_PYTHON_SOURCES
-  gdcm_wrap.cxx
-)
-
-SET_SOURCE_FILES_PROPERTIES(gdcm_wrap.cxx GENERATED)
-
-ADD_LIBRARY(pygdcm ${GDCM_PYTHON_SOURCES})
-TARGET_LINK_LIBRARIES(pygdcm 
-  ${PYTHON_LIBRARY}
-  gdcm
+  ${GDCM_BINARY_DIR}/
 )
 
 #-----------------------------------------------------------------------------
-# As of 09/10/2003 there was no FindSWIG.cmake
-# later we should use SWIG instead of swig
-# Build our custom command :
-ADD_CUSTOM_COMMAND(
-  SOURCE    ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i
-  COMMAND   swig
-  ARGS      -python -c++ -I${GDCM_SOURCE_DIR}/src -o 
-            ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx 
-            ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i 
-  TARGET    pygdcm
-  OUTPUTS   ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
-)
-
-
+# SWIG Wrapping
+#
+
+# CMake 2.0 will fully support Swig wrapping so split based on cmake version:
+
+# We need to pass that to swig to be sure all modules are generated in the proper dir
+SET(CMAKE_SWIG_FLAGS "-outdir ${GDCM_BINARY_DIR}/gdcmPython")
+# Looks like a bug to me in cmake 2.0.x:
+SEPARATE_ARGUMENTS(CMAKE_SWIG_FLAGS)
+
+FIND_PACKAGE(SWIG REQUIRED)
+INCLUDE(${SWIG_USE_FILE})
+
+SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON)
+# Setting SWIG_FLAGS to "-includeall" at the following line looks like
+# a bad idea since swig tries to recursively include all the referenced
+# files, "including" the C++ <sstream>, <list>, <map>... Of course swig
+# has no way of finding the path to those files (unless it is told by
+# cmake) since they are related to the compiler installation layout.
+# Anyhow, since this inclusion recursion is not necessary, just don't
+# do it.
+# Note: apparently the line is required in order to avoid a NOTFOUND
+#       as argument of swig on invocation of make.
+SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "")
+SWIG_ADD_MODULE(gdcm python gdcm.i)  #gdcm_wrap.cxx
+SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES})
+
+# Get rid of -Wall / -W / -pedantic if exist
+#SET(CMAKE_CXX_FLAGS "")
+# I guess I need to put them back on the this file:
+#SET_SOURCE_FILES_PROPERTIES(${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
+#                            PROPERTIES COMPILE_FLAGS "")
+ADD_DEPENDENCIES(
+  ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
+  ${GDCM_SOURCE_DIR}/gdcmConfigure.h
+  )
 
+INSTALL_TARGETS(/lib/gdcm/ _gdcm)
 
+#-----------------------------------------------------------------------------
+# VTK Wrapping
+# 
 IF(GDCM_VTK)
+  # Include the VTK library
+  INCLUDE(${VTK_USE_FILE})
+
   INCLUDE_DIRECTORIES(
     ${GDCM_SOURCE_DIR}/vtk
   )
 
   SET(vtkgdcmPython_la_SOURCES
-#      vtkGdcmReaderPython.cxx
-#      vtkGdcmInit.cxx
       ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
+      ${GDCM_SOURCE_DIR}/vtk/vtkGdcmWriter.cxx
   )
   SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
-  #vtkWrapPythonInit.c
   
-  # The C++ files must be made into a C++ library
-  #ADD_LIBRARY ( vtkgdcmPython ${vtkgdcmPython_la_SOURCES})
-
-  # set the libraries to link against
-  #TARGET_LINK_LIBRARIES(vtkgdcmPython vtkCommon)
-
   # Configure Python module, which is the plugin itself
   IF (GDCM_WRAP_PYTHON)
-    VTK_WRAP_PYTHON2(vtkgdcmPython gdcmfoo
+    IF(NOT VTK_WRAP_PYTHON)
+      MESSAGE(FATAL_ERROR "Can't build gdcm python wrapping if VTK_WRAP_PYTHON is OFF" )
+    ENDIF(NOT VTK_WRAP_PYTHON)
+    VTK_WRAP_PYTHON2(vtkgdcmPython gdcmWrapSOURCES
                    ${vtkgdcmPython_la_SOURCES})
-    ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmfoo})
+    # The C++ files must be made into a C++ library
+    ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmWrapSOURCES})  #MODULE on apple ?
+    # set the libraries to link against
+    #SET_TARGET_PROPERTIES(${foobar} PROPERTIES PREFIX "")
+
+    #GET_TARGET_PROPERTY(swig_gdcm_fullpath "${SWIG_MODULE_gdcm_REAL_NAME}" LOCATION)
     TARGET_LINK_LIBRARIES (vtkgdcmPython
-                         pygdcm
-                         vtkgdcm
-                         vtkCommonPython
-                         vtkIOPython)
+                           vtkgdcm
+                           vtkCommonPython
+                           vtkIOPython)
+    INSTALL_TARGETS(/lib/gdcm/ vtkgdcmPython)
+
   ENDIF (GDCM_WRAP_PYTHON)
 ENDIF(GDCM_VTK)
 
-#I should install in path of PYTHON_LIBRARY
-GET_FILENAME_COMPONENT(PYTHON_LIB_INSTALL ${PYTHON_LIBRARY} PATH)
-GET_FILENAME_COMPONENT(SITEPACKAGE ${PYTHON_LIB_INSTALL}/../site-packages ABSOLUTE)
-MESSAGE(STATUS ${SITEPACKAGE})
-#INSTALL_FILES(/include "\\.h$")
-#INSTALL_TARGETS(/lib/ gdcm)
+# generate a setup.py according to VTK installation
+# put it in subdir in order to not override old one
+#
+#GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
+#CONFIGURE_FILE(
+#    ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
+#    ${GDCM_BINARY_DIR}/setup.py
+#)
+
+#-----------------------------------------------------------------------------
+# Python package configuration
+FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmVersion.py
+    "gdcmVERSION=\"${GDCM_VERSION}\"\n"
+    )
+
+FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
+    "__all__ = [\"core\",\n"
+    "           \"vtk\",\n"
+    "          ]\n"
+    )
+
+FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/core.py
+    "from gdcmVersion import *\n"
+    "import gdcm\n"
+    "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
+    )
+
+IF(GDCM_VTK)
+  FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/vtk.py
+    "import os\n"
+    "from gdcmVersion import *\n"
+    "if os.name == 'posix':\n"
+    "  from libvtkgdcmPython import *\n"
+    "else:\n"
+    "  from vtkgdcmPython import *\n"
+    "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
+    )
+ENDIF(GDCM_VTK)
+
+#-----------------------------------------------------------------------------
+# Python installation
+IF(WIN32)
+  FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
+       "${GDCM_BINARY_DIR}\n"
+       "${GDCM_BINARY_DIR}/bin/release\n"
+  )
+ELSE(WIN32)
+  FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
+       "${CMAKE_INSTALL_PREFIX}/lib/gdcm\n"
+  )
+ENDIF(WIN32)
+FIND_PATH(PYTHON_INSTALL "site-packages"
+    [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath]
+    [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath]
+    [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath]
+    [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]
+    [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]
+    [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath]
+    [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath]
+    /usr/lib/python2.4
+    /usr/lib/python2.3
+    /usr/lib/python2.2
+    /usr/lib/python2.1
+    /usr/lib/python2.0
+    /usr/lib/python1.6
+    /usr/lib/python1.5
+)
+STRING(REGEX REPLACE "/usr(.*)/config.*" "\\1" PYTHON_INSTALL ${PYTHON_LIBRARY})
+
+INSTALL_FILES(${PYTHON_INSTALL}/site-packages "\\.pth$")
+INSTALL_FILES(/lib/gdcm/gdcmPython "\\.py$")
+INSTALL_FILES(/lib/gdcm/gdcmPython FILES "gdcm.py")
+
+#-----------------------------------------------------------------------------
+# Add test from demo subdir:
+
+SUBDIRS(demo)