1 # gdcm Python wrapping stuff:
9 #-----------------------------------------------------------------------------
13 # CMake 2.0 will fully support Swig wrapping so split based on cmake version:
15 IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
17 FIND_PACKAGE(SWIG REQUIRED)
18 INCLUDE(${SWIG_USE_FILE})
20 #INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
21 #SET(CMAKE_SWIG_FLAGS "")
23 #SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES PYTHON ON)
24 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON)
25 # Setting SWIG_FLAGS to "-includeall" at the following line looks like
26 # a bad idea since swig tries to reculsively include all the referenced
27 # files, "including" the C++ <sstream>, <list>, <map>... Of course swig
28 # has no way of finding the path to those files (unless it is told by
29 # cmake) since they are related to the compiler installation layout.
30 # Anyhow, since this inclusion recursion is not necessary, just don't
32 # Note: apparently the line is required in order to avoid a NOTFOUND
33 # as argument of swig on invocation of make.
34 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "")
35 SWIG_ADD_MODULE(gdcm python gdcm.i) #gdcm_wrap.cxx
36 SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES})
38 #SWIG_GET_EXTRA_OUTPUT_FILES(python foobar "/usr/" "gdcm" )
39 #MESSAGE(FATAL_ERROR ${swig_generated_file_fullname})
40 #MESSAGE(FATAL_ERROR ${swig_source_file_fullname})
42 # Swig creates a gdcm.py file put it in the right place, if only cmake
43 # was able to do stuff properly ...
44 ADD_CUSTOM_TARGET( CMAKE_S____ ALL)
48 COMMAND ${CMAKE_COMMAND}
50 ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py
51 ${GDCM_BINARY_DIR}/bin/gdcm.py
54 ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
56 # As of 09/10/2003 there was no FindSWIG.cmake
57 # later we should use SWIG instead of swig
58 FIND_PROGRAM(SWIG_EXECUTABLE
62 IF(NOT SWIG_EXECUTABLE)
63 MESSAGE(FATAL_ERROR "Swig could not be found wrapping is impossible")
64 ENDIF(NOT SWIG_EXECUTABLE)
66 # Build our custom command :
68 OUTPUT ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
69 COMMAND ${SWIG_EXECUTABLE}
70 ARGS -python -c++ -I${GDCM_SOURCE_DIR}/src -o
71 ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
72 ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i
73 DEPENDS ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i
74 COMMENT "Generating gdcm_wrap.cxx/gdcm.py based on gdcm.i"
76 # Since the file gdcm_wrap.cxx does not exist, mark it as GENERATED:
77 SET_SOURCE_FILES_PROPERTIES(${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx GENERATED)
79 ADD_LIBRARY(pygdcm gdcm_wrap.cxx)
80 TARGET_LINK_LIBRARIES(pygdcm
84 # http://www.cmake.org/pipermail/cmake/2003-August/004190.html
85 #SET_TARGET_PROPERTIES(pygdcm PROPERTIES PREFIX "_")
87 # This swig command will also outputs gdcm.py :
88 SET_SOURCE_FILES_PROPERTIES(${GDCM_BINARY_DIR}/gdcmPython/gdcm.py GENERATED)
90 # Instead of a simple copy operation let create our own gdcm.py file:
91 # First read what swig dumped:
92 IF(EXISTS ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py)
93 FILE(READ ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py SWIG_GDCM_PY)
94 ENDIF(EXISTS ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py)
96 # Then create the gdcm.py = gdcmVersion.py + gdcm.py (swig) file:
97 FILE(WRITE ${GDCM_BINARY_DIR}/bin/gdcmVersion.py
99 "gdcmVERSION=\"${GDCM_VERSION}\"\n"
100 "GDCM_DATA_PATH=\"${GDCM_DATA_ROOT}\"\n\n"
104 # Seems like they want instead a file called gdcmPython.py
105 # Thus add the custom command to copy it to proper location:
106 # ADD_CUSTOM_COMMAND(
109 # COMMAND ${CMAKE_COMMAND}
111 # ${GDCM_BINARY_DIR}/bin/gdcm.py
112 # ${GDCM_BINARY_DIR}/bin/gdcmPython.py
115 # Here comes the hack to rename the library to a more 'swig' compliant scheme"
116 SET(LIB_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}pygdcm${CMAKE_SHARED_LIBRARY_SUFFIX})
117 SET(EXE_DIR ${GDCM_BINARY_DIR}/Executable)
118 IF(EXECUTABLE_OUTPUT_PATH)
119 SET(EXE_DIR ${EXECUTABLE_OUTPUT_PATH})
120 ENDIF(EXECUTABLE_OUTPUT_PATH)
121 SET(LIB_DIR ${GDCM_BINARY_DIR}/Library/Shared)
122 IF(LIBRARY_OUTPUT_PATH)
123 SET(LIB_DIR ${LIBRARY_OUTPUT_PATH})
124 ENDIF(LIBRARY_OUTPUT_PATH)
127 SET(SHARED_MUST_BE_IN_EXE_DIR 1)
128 ENDIF(WIN32 OR APPLE)
130 IF(NOT SHARED_MUST_BE_IN_EXE_DIR)
131 SET(EXE_DIR ${LIB_DIR})
132 ENDIF(NOT SHARED_MUST_BE_IN_EXE_DIR)
137 COMMAND ${CMAKE_COMMAND} ARGS -E copy
138 ${LIB_DIR}/${CMAKE_CFG_INTDIR}/${LIB_NAME}
139 ${EXE_DIR}/${CMAKE_CFG_INTDIR}/_gdcm${CMAKE_SHARED_LIBRARY_SUFFIX}
142 # Remove temporary (lib)pygdcm(.so .dll) library:
143 # ADD_CUSTOM_COMMAND(
146 # COMMAND ${CMAKE_COMMAND}
147 # ARGS -E remove ${LIB_DIR}/${CMAKE_CFG_INTDIR}/${LIB_NAME}
150 # where are library stored ?
151 # SET(GDCM_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
152 # ADD_CUSTOM_COMMAND(
155 # COMMAND ${CMAKE_COMMAND}
157 # ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${MY_LIB_NAME}${CMAKE_SHLIB_SUFFIX}
158 # ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/vtkXY.pvm
162 ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
165 #-----------------------------------------------------------------------------
170 ${GDCM_SOURCE_DIR}/vtk
173 SET(vtkgdcmPython_la_SOURCES
174 ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
176 SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
178 # Configure Python module, which is the plugin itself
179 IF (GDCM_WRAP_PYTHON)
180 IF(NOT VTK_WRAP_PYTHON)
181 MESSAGE(FATAL_ERROR "Can't build gdcm python wrapping if VTK_WRAP_PYTHON is OFF" )
182 ENDIF(NOT VTK_WRAP_PYTHON)
183 VTK_WRAP_PYTHON2(vtkgdcmPython gdcmWrapSOURCES
184 ${vtkgdcmPython_la_SOURCES})
185 # The C++ files must be made into a C++ library
186 ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmWrapSOURCES}) #MODULE on apple ?
187 # set the libraries to link against
188 #SET_TARGET_PROPERTIES(${foobar} PROPERTIES PREFIX "")
190 #GET_TARGET_PROPERTY(swig_gdcm_fullpath "${SWIG_MODULE_gdcm_REAL_NAME}" LOCATION)
191 TARGET_LINK_LIBRARIES (vtkgdcmPython
195 ENDIF (GDCM_WRAP_PYTHON)
198 # generate a setup.py according to VTK installation
199 # put it in subdir in order to not override old one
201 GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
203 ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
204 ${GDCM_BINARY_DIR}/setup.py
207 #-----------------------------------------------------------------------------
210 # Cmake cannot handle installing since python wants stuff to be installed
211 # in /usr/lib/pythonx.x/site-package and not a a std /usr/lib
212 # Thus generate a setup.py file using distutils
214 # Create a gdcm.pth file:
216 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcm.pth
220 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
225 FILE(APPEND ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
227 "if os.name == 'posix':\n"
228 " from libvtkgdcmPython import *\n"
230 " from vtkgdcmPython import *\n"
234 #-----------------------------------------------------------------------------
235 # Add test from demo subdir: