1 # gdcm Python wrapping stuff:
10 #-----------------------------------------------------------------------------
14 # CMake 2.0 will fully support Swig wrapping so split based on cmake version:
16 IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
18 FIND_PACKAGE(SWIG REQUIRED)
19 INCLUDE(${SWIG_USE_FILE})
21 #INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
23 #SET(CMAKE_SWIG_FLAGS "")
25 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON)
26 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "-includeall")
27 SWIG_ADD_MODULE(gdcm python
29 SWIG_LINK_LIBRARIES(gdcm ${PYTHON_LIBRARIES})
30 TARGET_LINK_LIBRARIES(_gdcm gdcm)
32 ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
34 # As of 09/10/2003 there was no FindSWIG.cmake
35 # later we should use SWIG instead of swig
36 FIND_PROGRAM(SWIG_EXECUTABLE
40 IF(NOT SWIG_EXECUTABLE)
41 MESSAGE(FATAL_ERROR "Swig could not be found wrapping is impossible")
42 ENDIF(NOT SWIG_EXECUTABLE)
44 # Bad hack to work around bug #846 in cmake, hopefully will desepear soon anyway
45 FILE(READ ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py SWIG_GDCM_PY)
47 # Build our custom command :
49 OUTPUT ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
50 COMMAND ${SWIG_EXECUTABLE}
51 ARGS -python -c++ -I${GDCM_SOURCE_DIR}/src -o
52 ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
53 ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i
54 DEPENDS ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i
55 COMMENT "Generating gdcm_wrap.cxx/gdcm.py based on gdcm.i"
57 # Since the file gdcm_wrap.cxx does not exist, mark it as GENERATED:
58 SET_SOURCE_FILES_PROPERTIES(${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx GENERATED)
60 ADD_LIBRARY(pygdcm gdcm_wrap.cxx)
61 TARGET_LINK_LIBRARIES(pygdcm
65 # http://www.cmake.org/pipermail/cmake/2003-August/004190.html
66 #SET_TARGET_PROPERTIES(pygdcm PROPERTIES PREFIX "_")
68 # This swig command will also outputs gdcm.py :
69 SET_SOURCE_FILES_PROPERTIES(${GDCM_BINARY_DIR}/gdcmPython/gdcm.py GENERATED)
71 # Instead of a simple copy operation let create our own gdcm.py file:
72 # First read what swig dumped:
73 FILE(READ ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py SWIG_GDCM_PY)
75 # Then create the gdcm.py = gdcmVersion.py + gdcm.py (swig) file:
76 FILE(WRITE ${GDCM_BINARY_DIR}/bin/gdcm.py
78 "gdcmVERSION=\"${GDCM_VERSION_FULL}\"\n"
79 "GDCM_DATA_PATH=\"${GDCM_DATA_ROOT}\"\n\n"
83 # Seems like they want instead a file called gdcmPython.py
84 # Thus add the custom command to copy it to proper location:
88 COMMAND ${CMAKE_COMMAND}
90 ${GDCM_BINARY_DIR}/bin/gdcm.py
91 ${GDCM_BINARY_DIR}/bin/gdcmPython.py
94 # Here comes the hack to rename the library to a more 'swig' compliant scheme"
95 SET(LIB_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}pygdcm${CMAKE_SHARED_LIBRARY_SUFFIX})
96 SET(EXE_DIR ${GDCM_BINARY_DIR}/Executable)
97 IF(EXECUTABLE_OUTPUT_PATH)
98 SET(EXE_DIR ${EXECUTABLE_OUTPUT_PATH})
99 ENDIF(EXECUTABLE_OUTPUT_PATH)
100 SET(LIB_DIR ${GDCM_BINARY_DIR}/Library/Shared)
101 IF(LIBRARY_OUTPUT_PATH)
102 SET(LIB_DIR ${LIBRARY_OUTPUT_PATH})
103 ENDIF(LIBRARY_OUTPUT_PATH)
106 SET(SHARED_MUST_BE_IN_EXE_DIR 1)
107 ENDIF(WIN32 OR APPLE)
109 IF(NOT SHARED_MUST_BE_IN_EXE_DIR)
110 SET(EXE_DIR ${LIB_DIR})
111 ENDIF(NOT SHARED_MUST_BE_IN_EXE_DIR)
116 COMMAND ${CMAKE_COMMAND} ARGS -E copy
117 ${LIB_DIR}/${CMAKE_CFG_INTDIR}/${LIB_NAME}
118 ${EXE_DIR}/${CMAKE_CFG_INTDIR}/_gdcm${CMAKE_SHARED_LIBRARY_SUFFIX}
121 # Remove temporary (lib)pygdcm(.so .dll) library:
125 COMMAND ${CMAKE_COMMAND}
126 ARGS -E remove ${LIB_DIR}/${CMAKE_CFG_INTDIR}/${LIB_NAME}
129 # where are library stored ?
130 # SET(GDCM_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
131 # ADD_CUSTOM_COMMAND(
134 # COMMAND ${CMAKE_COMMAND}
136 # ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${MY_LIB_NAME}${CMAKE_SHLIB_SUFFIX}
137 # ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/vtkXY.pvm
141 ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
144 #-----------------------------------------------------------------------------
149 ${GDCM_SOURCE_DIR}/vtk
152 SET(vtkgdcmPython_la_SOURCES
153 ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
155 SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
157 # Configure Python module, which is the plugin itself
158 IF (GDCM_WRAP_PYTHON)
159 VTK_WRAP_PYTHON2(vtkgdcmPython gdcmfoo
160 ${vtkgdcmPython_la_SOURCES})
161 # The C++ files must be made into a C++ library
162 ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmfoo})
163 # set the libraries to link against
164 TARGET_LINK_LIBRARIES (vtkgdcmPython
169 ENDIF (GDCM_WRAP_PYTHON)
171 #generate a setup.py according to VTK installation
172 #put it in subdir in order to not override old one
173 # as it is a pain...override existing file...
175 GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
177 ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
178 ${GDCM_BINARY_DIR}/setup.py
180 #MESSAGE(STATUS ${VTKPATH})
183 #-----------------------------------------------------------------------------
186 #Should install in path of PYTHON_LIBRARY and not the default CMAKE_INSTALL_PREFIX
188 GET_FILENAME_COMPONENT(PYTHON_LIB_INSTALL ${PYTHON_LIBRARY} PATH)
189 GET_FILENAME_COMPONENT(SITEPACKAGE
190 ${PYTHON_LIB_INSTALL}/../site-packages ABSOLUTE)
191 #MESSAGE(STATUS ${SITEPACKAGE})
192 #INSTALL_FILES(/include "\\.h$")
193 #INSTALL_TARGETS(/lib/ gdcm)
195 # gdcm.py is a file generated by swig
196 # then from python you can do import gdcm, and it will load _gdcm.so
197 #INSTALL_TARGETS(/lib/ gdcm.py)
198 #INSTALL_PROGRAMS(/lib/ gdcm.py)
199 #INSTALL_FILES(/lib/ .py gdcm.py)
201 # When installing swig-generated python module one should pay attention
202 # to library naming convention, see here for more detail:
203 # http://www.swig.org/Doc1.3/Python.html#n6
204 # even with the $swig -module mylib, there is always a trailing underscore added