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})
22 #SET(CMAKE_SWIG_FLAGS "")
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 ${PYTHON_LIBRARIES})
28 TARGET_LINK_LIBRARIES(_gdcm gdcm)
30 ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
32 # As of 09/10/2003 there was no FindSWIG.cmake
33 # later we should use SWIG instead of swig
34 FIND_PROGRAM(SWIG_EXECUTABLE
38 IF(NOT SWIG_EXECUTABLE)
39 MESSAGE(FATAL_ERROR "Swig could not be found wrapping is impossible")
40 ENDIF(NOT SWIG_EXECUTABLE)
42 # Build our custom command :
44 OUTPUT ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
45 COMMAND ${SWIG_EXECUTABLE}
46 ARGS -python -c++ -I${GDCM_SOURCE_DIR}/src -o
47 ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
48 ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i
49 DEPENDS ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i
50 COMMENT "Generating gdcm_wrap.cxx/gdcm.py based on gdcm.i"
52 # Since the file gdcm_wrap.cxx does not exist, mark it as GENERATED:
53 SET_SOURCE_FILES_PROPERTIES(${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx GENERATED)
55 ADD_LIBRARY(pygdcm gdcm_wrap.cxx)
56 TARGET_LINK_LIBRARIES(pygdcm
60 # http://www.cmake.org/pipermail/cmake/2003-August/004190.html
61 #SET_TARGET_PROPERTIES(pygdcm PROPERTIES PREFIX "_")
63 # This swig command will also outputs gdcm.py :
64 SET_SOURCE_FILES_PROPERTIES(${GDCM_BINARY_DIR}/gdcmPython/gdcm.py GENERATED)
66 # Instead of a simple copy operation let create our own gdcm.py file:
67 # First read what swig dumped:
68 IF(EXISTS ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py)
69 FILE(READ ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py SWIG_GDCM_PY)
70 ENDIF(EXISTS ${GDCM_BINARY_DIR}/gdcmPython/gdcm.py)
72 # Then create the gdcm.py = gdcmVersion.py + gdcm.py (swig) file:
73 FILE(WRITE ${GDCM_BINARY_DIR}/bin/gdcmVersion.py
75 "gdcmVERSION=\"${GDCM_VERSION_FULL}\"\n"
76 "GDCM_DATA_PATH=\"${GDCM_DATA_ROOT}\"\n\n"
80 # Seems like they want instead a file called gdcmPython.py
81 # Thus add the custom command to copy it to proper location:
85 # COMMAND ${CMAKE_COMMAND}
87 # ${GDCM_BINARY_DIR}/bin/gdcm.py
88 # ${GDCM_BINARY_DIR}/bin/gdcmPython.py
91 # Here comes the hack to rename the library to a more 'swig' compliant scheme"
92 SET(LIB_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}pygdcm${CMAKE_SHARED_LIBRARY_SUFFIX})
93 SET(EXE_DIR ${GDCM_BINARY_DIR}/Executable)
94 IF(EXECUTABLE_OUTPUT_PATH)
95 SET(EXE_DIR ${EXECUTABLE_OUTPUT_PATH})
96 ENDIF(EXECUTABLE_OUTPUT_PATH)
97 SET(LIB_DIR ${GDCM_BINARY_DIR}/Library/Shared)
98 IF(LIBRARY_OUTPUT_PATH)
99 SET(LIB_DIR ${LIBRARY_OUTPUT_PATH})
100 ENDIF(LIBRARY_OUTPUT_PATH)
103 SET(SHARED_MUST_BE_IN_EXE_DIR 1)
104 ENDIF(WIN32 OR APPLE)
106 IF(NOT SHARED_MUST_BE_IN_EXE_DIR)
107 SET(EXE_DIR ${LIB_DIR})
108 ENDIF(NOT SHARED_MUST_BE_IN_EXE_DIR)
113 COMMAND ${CMAKE_COMMAND} ARGS -E copy
114 ${LIB_DIR}/${CMAKE_CFG_INTDIR}/${LIB_NAME}
115 ${EXE_DIR}/${CMAKE_CFG_INTDIR}/_gdcm${CMAKE_SHARED_LIBRARY_SUFFIX}
118 # Remove temporary (lib)pygdcm(.so .dll) library:
119 # ADD_CUSTOM_COMMAND(
122 # COMMAND ${CMAKE_COMMAND}
123 # ARGS -E remove ${LIB_DIR}/${CMAKE_CFG_INTDIR}/${LIB_NAME}
126 # where are library stored ?
127 # SET(GDCM_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
128 # ADD_CUSTOM_COMMAND(
131 # COMMAND ${CMAKE_COMMAND}
133 # ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${MY_LIB_NAME}${CMAKE_SHLIB_SUFFIX}
134 # ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/vtkXY.pvm
138 ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
141 #-----------------------------------------------------------------------------
146 ${GDCM_SOURCE_DIR}/vtk
149 SET(vtkgdcmPython_la_SOURCES
150 ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
152 SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
154 # Configure Python module, which is the plugin itself
155 IF (GDCM_WRAP_PYTHON)
156 IF(NOT VTK_WRAP_PYTHON)
157 MESSAGE(FATAL_ERROR "Can't build gdcm python wrapping if VTK_WRAP_PYTHON is OFF" )
158 ENDIF(NOT VTK_WRAP_PYTHON)
159 VTK_WRAP_PYTHON2(vtkgdcmPython gdcmWrapSOURCES
160 ${vtkgdcmPython_la_SOURCES})
161 # The C++ files must be made into a C++ library
162 ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmWrapSOURCES}) #MODULE on apple ?
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
174 GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
176 ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
177 ${GDCM_BINARY_DIR}/gdcmPython/setup.py
181 #-----------------------------------------------------------------------------
184 # Cmake cannot handle installing since python wants stuff to be installed
185 # in /usr/lib/pythonx.x/site-package and not a a std /usr/lib
186 # Thus generate a setup.py file using distutils
189 #-----------------------------------------------------------------------------
190 # Add test from demo subdir: