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 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "-includeall")
26 SWIG_ADD_MODULE(gdcm python gdcm.i) #gdcm_wrap.cxx
27 SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES})
29 #SWIG_GET_EXTRA_OUTPUT_FILES(python foobar "/usr/" "gdcm" )
30 #MESSAGE(FATAL_ERROR ${swig_generated_file_fullname})
31 #MESSAGE(FATAL_ERROR ${swig_source_file_fullname})
33 # Swig creates a gdcm.py file put it in the right place, if only cmake
34 # was able to do stuff properly ...
35 ADD_CUSTOM_TARGET( CMAKE_S____ ALL)
39 COMMAND ${CMAKE_COMMAND}
41 ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py
42 ${GDCM_BINARY_DIR}/bin/gdcm.py
45 ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
47 # As of 09/10/2003 there was no FindSWIG.cmake
48 # later we should use SWIG instead of swig
49 FIND_PROGRAM(SWIG_EXECUTABLE
53 IF(NOT SWIG_EXECUTABLE)
54 MESSAGE(FATAL_ERROR "Swig could not be found wrapping is impossible")
55 ENDIF(NOT SWIG_EXECUTABLE)
57 # Build our custom command :
59 OUTPUT ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
60 COMMAND ${SWIG_EXECUTABLE}
61 ARGS -python -c++ -I${GDCM_SOURCE_DIR}/src -o
62 ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
63 ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i
64 DEPENDS ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i
65 COMMENT "Generating gdcm_wrap.cxx/gdcm.py based on gdcm.i"
67 # Since the file gdcm_wrap.cxx does not exist, mark it as GENERATED:
68 SET_SOURCE_FILES_PROPERTIES(${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx GENERATED)
70 ADD_LIBRARY(pygdcm gdcm_wrap.cxx)
71 TARGET_LINK_LIBRARIES(pygdcm
75 # http://www.cmake.org/pipermail/cmake/2003-August/004190.html
76 #SET_TARGET_PROPERTIES(pygdcm PROPERTIES PREFIX "_")
78 # This swig command will also outputs gdcm.py :
79 SET_SOURCE_FILES_PROPERTIES(${GDCM_BINARY_DIR}/gdcmPython/gdcm.py GENERATED)
81 # Instead of a simple copy operation let create our own gdcm.py file:
82 # First read what swig dumped:
83 IF(EXISTS ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py)
84 FILE(READ ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py SWIG_GDCM_PY)
85 ENDIF(EXISTS ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py)
87 # Then create the gdcm.py = gdcmVersion.py + gdcm.py (swig) file:
88 FILE(WRITE ${GDCM_BINARY_DIR}/bin/gdcmVersion.py
90 "gdcmVERSION=\"${GDCM_VERSION}\"\n"
91 "GDCM_DATA_PATH=\"${GDCM_DATA_ROOT}\"\n\n"
95 # Seems like they want instead a file called gdcmPython.py
96 # Thus add the custom command to copy it to proper location:
100 # COMMAND ${CMAKE_COMMAND}
102 # ${GDCM_BINARY_DIR}/bin/gdcm.py
103 # ${GDCM_BINARY_DIR}/bin/gdcmPython.py
106 # Here comes the hack to rename the library to a more 'swig' compliant scheme"
107 SET(LIB_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}pygdcm${CMAKE_SHARED_LIBRARY_SUFFIX})
108 SET(EXE_DIR ${GDCM_BINARY_DIR}/Executable)
109 IF(EXECUTABLE_OUTPUT_PATH)
110 SET(EXE_DIR ${EXECUTABLE_OUTPUT_PATH})
111 ENDIF(EXECUTABLE_OUTPUT_PATH)
112 SET(LIB_DIR ${GDCM_BINARY_DIR}/Library/Shared)
113 IF(LIBRARY_OUTPUT_PATH)
114 SET(LIB_DIR ${LIBRARY_OUTPUT_PATH})
115 ENDIF(LIBRARY_OUTPUT_PATH)
118 SET(SHARED_MUST_BE_IN_EXE_DIR 1)
119 ENDIF(WIN32 OR APPLE)
121 IF(NOT SHARED_MUST_BE_IN_EXE_DIR)
122 SET(EXE_DIR ${LIB_DIR})
123 ENDIF(NOT SHARED_MUST_BE_IN_EXE_DIR)
128 COMMAND ${CMAKE_COMMAND} ARGS -E copy
129 ${LIB_DIR}/${CMAKE_CFG_INTDIR}/${LIB_NAME}
130 ${EXE_DIR}/${CMAKE_CFG_INTDIR}/_gdcm${CMAKE_SHARED_LIBRARY_SUFFIX}
133 # Remove temporary (lib)pygdcm(.so .dll) library:
134 # ADD_CUSTOM_COMMAND(
137 # COMMAND ${CMAKE_COMMAND}
138 # ARGS -E remove ${LIB_DIR}/${CMAKE_CFG_INTDIR}/${LIB_NAME}
141 # where are library stored ?
142 # SET(GDCM_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
143 # ADD_CUSTOM_COMMAND(
146 # COMMAND ${CMAKE_COMMAND}
148 # ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${MY_LIB_NAME}${CMAKE_SHLIB_SUFFIX}
149 # ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/vtkXY.pvm
153 ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
156 #-----------------------------------------------------------------------------
161 ${GDCM_SOURCE_DIR}/vtk
164 SET(vtkgdcmPython_la_SOURCES
165 ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
167 SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
169 # Configure Python module, which is the plugin itself
170 IF (GDCM_WRAP_PYTHON)
171 IF(NOT VTK_WRAP_PYTHON)
172 MESSAGE(FATAL_ERROR "Can't build gdcm python wrapping if VTK_WRAP_PYTHON is OFF" )
173 ENDIF(NOT VTK_WRAP_PYTHON)
174 VTK_WRAP_PYTHON2(vtkgdcmPython gdcmWrapSOURCES
175 ${vtkgdcmPython_la_SOURCES})
176 # The C++ files must be made into a C++ library
177 ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmWrapSOURCES}) #MODULE on apple ?
178 # set the libraries to link against
179 #SET_TARGET_PROPERTIES(${foobar} PROPERTIES PREFIX "")
181 #GET_TARGET_PROPERTY(swig_gdcm_fullpath "${SWIG_MODULE_gdcm_REAL_NAME}" LOCATION)
182 TARGET_LINK_LIBRARIES (vtkgdcmPython
186 ENDIF (GDCM_WRAP_PYTHON)
189 # generate a setup.py according to VTK installation
190 # put it in subdir in order to not override old one
192 GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
194 ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
195 ${GDCM_BINARY_DIR}/setup.py
198 #-----------------------------------------------------------------------------
201 # Cmake cannot handle installing since python wants stuff to be installed
202 # in /usr/lib/pythonx.x/site-package and not a a std /usr/lib
203 # Thus generate a setup.py file using distutils
205 # Create a gdcm.pth file:
207 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcm.pth
211 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
216 FILE(APPEND ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
218 "if os.name == 'posix':\n"
219 " from libvtkgdcmPython import *\n"
221 " from vtkgdcmPython import *\n"
225 #-----------------------------------------------------------------------------
226 # Add test from demo subdir: