]> Creatis software - gdcm.git/blobdiff - gdcmPython/CMakeLists.txt
ENH: Get rid of -Wall / -W / -pedantic if present this should get rid of the warnings...
[gdcm.git] / gdcmPython / CMakeLists.txt
index faeedec531da338b04cf3f08d23994f4d8112dd7..04a30511a219ad8b7e494b3c942f83e387d3bf2a 100644 (file)
@@ -14,19 +14,38 @@ INCLUDE_DIRECTORIES(
 
 IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
 
+  # 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}/bin")
+  # Looks like a bug to me in cmake 2.0.x:
+  SEPARATE_ARGUMENTS(CMAKE_SWIG_FLAGS)
+
   FIND_PACKAGE(SWIG REQUIRED)
   INCLUDE(${SWIG_USE_FILE})
 
-  #INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
-
-  #SET(CMAKE_SWIG_FLAGS "")
-
+  #SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES PYTHON ON)
   SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON)
-  SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "-includeall")
-  SWIG_ADD_MODULE(gdcm python gdcm.i gdcm_wrap.cxx)
-  SWIG_LINK_LIBRARIES(gdcm ${PYTHON_LIBRARIES})
-  TARGET_LINK_LIBRARIES(_gdcm gdcm)
-
+  # Setting SWIG_FLAGS to "-includeall" at the following line looks like
+  # a bad idea since swig tries to reculsively 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})
+
+  SET(GDCM_CXX_FLAGS ${CMAKE_SWIG_FLAGS})
+  # 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 "")
+#  SET_TARGET_PROPERTIES(${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
+#                        PROPERTIES CMAKE_CXX_FLAGS "-foo")
+  
 ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)   
 
   # As of 09/10/2003 there was no FindSWIG.cmake
@@ -72,7 +91,7 @@ ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
   # Then create the gdcm.py = gdcmVersion.py + gdcm.py (swig) file:
   FILE(WRITE ${GDCM_BINARY_DIR}/bin/gdcmVersion.py
     "import os\n"
-    "gdcmVERSION=\"${GDCM_VERSION_FULL}\"\n"
+    "gdcmVERSION=\"${GDCM_VERSION}\"\n"
     "GDCM_DATA_PATH=\"${GDCM_DATA_ROOT}\"\n\n"
     ${SWIG_GDCM_PY}
     )
@@ -142,6 +161,9 @@ ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
 # VTK Wrapping
 # 
 IF(GDCM_VTK)
+  # Include the VTK library
+  INCLUDE(${VTK_USE_FILE})
+
   INCLUDE_DIRECTORIES(
     ${GDCM_SOURCE_DIR}/vtk
   )
@@ -161,22 +183,24 @@ IF(GDCM_VTK)
     # 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)
   ENDIF (GDCM_WRAP_PYTHON)
-  
+ENDIF(GDCM_VTK)
+
   # 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}/gdcmPython/setup.py
+      ${GDCM_BINARY_DIR}/setup.py
   )
-ENDIF(GDCM_VTK)
 
 #-----------------------------------------------------------------------------
 # Install stuff:
@@ -185,6 +209,25 @@ ENDIF(GDCM_VTK)
 # in /usr/lib/pythonx.x/site-package and not a a std /usr/lib
 # Thus generate a setup.py file using distutils
 
+# Create a gdcm.pth file:
+
+FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcm.pth
+    "gdcmPython\n"
+    )
+
+FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
+    "import gdcm\n"
+    )
+
+IF(GDCM_VTK)
+  FILE(APPEND ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
+    "import os\n"
+    "if os.name == 'posix':\n"
+    "  from libvtkgdcmPython import *\n"
+    "else:\n"
+    "  from vtkgdcmPython import *\n"
+    )
+ENDIF(GDCM_VTK)
 
 #-----------------------------------------------------------------------------
 # Add test from demo subdir: