1 # gdcm Python wrapping stuff:
5 ${GDCM_SOURCE_DIR}/gdcmPython
10 #-----------------------------------------------------------------------------
14 # CMake 2.0 will fully support Swig wrapping so split based on cmake version:
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)
22 FIND_PACKAGE(SWIG REQUIRED)
24 INCLUDE(${SWIG_USE_FILE})
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 "")
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 ?
37 SWIG_ADD_MODULE(gdcm python gdcm.i) #gdcm_wrap.cxx, or gdcmPYTHON_wrap.cxx
38 SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES})
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 "")
47 INSTALL_TARGETS(/lib/gdcm/ _gdcm)
49 #-----------------------------------------------------------------------------
53 # Include the VTK library
54 INCLUDE(${VTK_USE_FILE})
57 ${GDCM_SOURCE_DIR}/vtk
60 SET(vtkgdcmPython_la_SOURCES
61 ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
62 ${GDCM_SOURCE_DIR}/vtk/vtkGdcmWriter.cxx
64 SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
66 # Configure Python module, which is the plugin itself
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 SHARED ${gdcmWrapSOURCES}) #MODULE on apple ?
78 # set the libraries to link against
79 #SET_TARGET_PROPERTIES(${foobar} PROPERTIES PREFIX "")
81 #GET_TARGET_PROPERTY(swig_gdcm_fullpath "${SWIG_MODULE_gdcm_REAL_NAME}" LOCATION)
82 IF("${VTK_MAJOR_VERSION}" LESS 5)
83 TARGET_LINK_LIBRARIES (vtkgdcmPython
87 ELSE("${VTK_MAJOR_VERSION}" LESS 5)
88 TARGET_LINK_LIBRARIES (vtkgdcmPython
92 ENDIF("${VTK_MAJOR_VERSION}" LESS 5)
93 INSTALL_TARGETS(/lib/gdcm/ vtkgdcmPython)
95 ENDIF (GDCM_WRAP_PYTHON)
98 # generate a setup.py according to VTK installation
99 # put it in subdir in order to not override old one
101 #GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
103 # ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
104 # ${GDCM_BINARY_DIR}/setup.py
107 #-----------------------------------------------------------------------------
108 # Python package configuration
109 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmVersion.py
110 "gdcmVERSION=\"${GDCM_VERSION}\"\n"
113 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
114 "__all__ = [\"core\",\n"
119 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/core.py
120 "from gdcmVersion import *\n"
122 "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
126 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/vtk.py
128 "from gdcmVersion import *\n"
129 "if os.name == 'posix':\n"
130 " from libvtkgdcmPython import *\n"
132 " from vtkgdcmPython import *\n"
133 "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
137 #-----------------------------------------------------------------------------
138 # Python installation
140 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
141 "${GDCM_BINARY_DIR}\n"
142 "${GDCM_BINARY_DIR}/bin/release\n"
144 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/InstallOnly/gdcmPython.pth
145 "${GDCM_SOURCE_DIR}\n"
146 "${GDCM_SOURCE_DIR}/bin\n"
149 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
150 "${CMAKE_INSTALL_PREFIX}/lib/gdcm\n"
152 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/InstallOnly/gdcmPython.pth
157 # Install a python path file in site-packages that tells
158 # python where to find the gdcmPython module
160 FIND_PATH(PYTHON_DIR "site-packages"
167 STRING(REGEX REPLACE "/usr" "" PYTHON_DIR ${PYTHON_DIR})
169 INSTALL_FILES(${PYTHON_DIR}/site-packages FILES
170 "${GDCM_BINARY_DIR}/gdcmPython/InstallOnly/gdcmPython.pth"
172 INSTALL_FILES(/lib/gdcm/gdcmPython FILES
181 #-----------------------------------------------------------------------------
182 # Add test from demo subdir: