]> Creatis software - gdcm.git/blob - gdcmPython/CMakeLists.txt
BUG: Apparently python2.5 do not like extension to have a .dll extension, we need...
[gdcm.git] / gdcmPython / CMakeLists.txt
1 # gdcm Python wrapping stuff:
2
3 INCLUDE_DIRECTORIES(
4   ${GDCM_SOURCE_DIR}/src
5   ${GDCM_SOURCE_DIR}/gdcmPython
6   ${PYTHON_INCLUDE_PATH}
7   ${GDCM_BINARY_DIR}/
8 )
9
10 #-----------------------------------------------------------------------------
11 # SWIG Wrapping
12 #
13
14 # CMake 2.0 will fully support Swig wrapping so split based on cmake version:
15
16 # We need to pass that to swig to be sure all modules are generated in the proper dir
17 SET(CMAKE_SWIG_FLAGS "-outdir \"${GDCM_BINARY_DIR}/gdcmPython\"")
18 #SET(CMAKE_SWIG_OUTDIR "${GDCM_BINARY_DIR}/gdcmPython")
19 # Looks like a bug to me in cmake 2.0.x:
20 SEPARATE_ARGUMENTS(CMAKE_SWIG_FLAGS)
21
22 FIND_PACKAGE(SWIG REQUIRED)
23 IF(SWIG_FOUND)
24   INCLUDE(${SWIG_USE_FILE})
25 ENDIF(SWIG_FOUND)
26
27
28 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON)
29 # BUG: This is only needed with cmake <= 2.0.5
30 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "")
31 # END OF BUG
32 #FIXME :
33 #where must we put the keyword SHARED 
34 #- just like in ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmWrapSOURCES}) -
35 #to allow use of a static/shared libray ?
36 # JPRx
37 SWIG_ADD_MODULE(gdcm python gdcm.i)  #gdcm_wrap.cxx, or gdcmPYTHON_wrap.cxx
38 SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES})
39
40 # Get rid of -Wall / -W / -pedantic if exist
41 SET(CMAKE_CXX_FLAGS "")
42 # I guess I need to put them back on this file:
43 #SET_SOURCE_FILES_PROPERTIES(
44 #  ${swig_generated_file_fullname}
45 #  PROPERTIES COMPILE_FLAGS "")
46
47 INSTALL_TARGETS(/lib/gdcm/ _gdcm)
48
49 #-----------------------------------------------------------------------------
50 # VTK Wrapping
51
52 IF(GDCM_VTK)
53   # Include the VTK library
54   INCLUDE(${VTK_USE_FILE})
55
56   INCLUDE_DIRECTORIES(
57     ${GDCM_SOURCE_DIR}/vtk
58   )
59
60   SET(vtkgdcmPython_la_SOURCES
61       ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
62       ${GDCM_SOURCE_DIR}/vtk/vtkGdcmWriter.cxx
63   )
64   SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
65   
66   # Configure Python module, which is the plugin itself
67   IF (GDCM_WRAP_PYTHON)
68     IF(NOT VTK_WRAP_PYTHON)
69       MESSAGE(FATAL_ERROR "Can't build gdcm python wrapping if VTK_WRAP_PYTHON is OFF" )
70     ENDIF(NOT VTK_WRAP_PYTHON)
71     IF("${VTK_MAJOR_VERSION}" GREATER 4)
72       INCLUDE(${VTK_CMAKE_DIR}/vtkWrapPython.cmake)
73     ENDIF("${VTK_MAJOR_VERSION}" GREATER 4)
74     VTK_WRAP_PYTHON2(vtkgdcmPython gdcmWrapSOURCES
75                    ${vtkgdcmPython_la_SOURCES})
76     # The C++ files must be made into a C++ library
77     ADD_LIBRARY(vtkgdcmPython MODULE ${gdcmWrapSOURCES})  #MODULE on apple ?
78
79     # Python extension modules on Windows must have the extension ".pyd"
80     # instead of ".dll" as of Python 2.5.  Older python versions do support
81     # this suffix.
82     IF(WIN32 AND NOT CYGWIN)
83       SET_TARGET_PROPERTIES(vtkgdcmPython PROPERTIES SUFFIX ".pyd")
84     ENDIF(WIN32 AND NOT CYGWIN)
85
86     # set the libraries to link against
87     #SET_TARGET_PROPERTIES(${foobar} PROPERTIES PREFIX "")
88
89     #GET_TARGET_PROPERTY(swig_gdcm_fullpath "${SWIG_MODULE_gdcm_REAL_NAME}" LOCATION)
90     IF("${VTK_MAJOR_VERSION}" LESS 5)
91       TARGET_LINK_LIBRARIES (vtkgdcmPython
92                              vtkgdcm
93                              vtkCommonPython
94                              vtkIOPython)
95     ELSE("${VTK_MAJOR_VERSION}" LESS 5)
96       TARGET_LINK_LIBRARIES (vtkgdcmPython
97                              vtkgdcm
98                              vtkCommonPythonD
99                              vtkIOPythonD)
100     ENDIF("${VTK_MAJOR_VERSION}" LESS 5)
101     INSTALL_TARGETS(/lib/gdcm/ vtkgdcmPython)
102
103   ENDIF (GDCM_WRAP_PYTHON)
104 ENDIF(GDCM_VTK)
105
106 # generate a setup.py according to VTK installation
107 # put it in subdir in order to not override old one
108 #
109 #GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
110 #CONFIGURE_FILE(
111 #    ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
112 #    ${GDCM_BINARY_DIR}/setup.py
113 #)
114
115 #-----------------------------------------------------------------------------
116 # Python package configuration
117 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmVersion.py
118     "gdcmVERSION=\"${GDCM_VERSION}\"\n"
119     )
120
121 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
122     "__all__ = [\"core\",\n"
123     "           \"vtk\",\n"
124     "          ]\n"
125     )
126
127 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/core.py
128     "from gdcmVersion import *\n"
129     "import gdcm\n"
130     "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
131     )
132
133 IF(GDCM_VTK)
134   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/vtk.py
135     "import os\n"
136     "from gdcmVersion import *\n"
137     "if os.name == 'posix':\n"
138     "  from libvtkgdcmPython import *\n"
139     "else:\n"
140     "  from vtkgdcmPython import *\n"
141     "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
142     )
143 ENDIF(GDCM_VTK)
144
145 #-----------------------------------------------------------------------------
146 # Python installation
147 IF(WIN32)
148   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
149        "${GDCM_BINARY_DIR}\n"
150        "${GDCM_BINARY_DIR}/bin/release\n"
151   )
152   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/InstallOnly/gdcmPython.pth
153        "${GDCM_SOURCE_DIR}\n"
154        "${GDCM_SOURCE_DIR}/bin\n"
155   )
156 ELSE(WIN32)
157   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
158        "${CMAKE_INSTALL_PREFIX}/lib/gdcm\n"
159   )
160   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/InstallOnly/gdcmPython.pth
161        "/usr/lib/gdcm\n"
162   )
163 ENDIF(WIN32)
164
165 # Install a python path file in site-packages that tells
166 # python where to find the gdcmPython module
167 IF(UNIX)
168   FIND_PATH(PYTHON_DIR "site-packages"
169      /usr/lib/python2.5  
170      /usr/lib/python2.4
171      /usr/lib/python2.3
172      /usr/lib/python2.2
173      /usr/lib/python2.1
174   ) 
175   STRING(REGEX REPLACE "/usr" "" PYTHON_DIR ${PYTHON_DIR})
176
177   INSTALL_FILES(${PYTHON_DIR}/site-packages FILES 
178     "${GDCM_BINARY_DIR}/gdcmPython/InstallOnly/gdcmPython.pth"
179   )
180   INSTALL_FILES(/lib/gdcm/gdcmPython FILES 
181     "gdcm.py" 
182     "__init__.py" 
183     "gdcmVersion.py" 
184     "core.py" 
185     "vtk.py"
186   )
187 ENDIF(UNIX)
188
189 #-----------------------------------------------------------------------------
190 # Add test from demo subdir:
191
192 SUBDIRS(demo)