1 # gdcm Python wrapping stuff:
9 #-----------------------------------------------------------------------------
13 # CMake 2.0 will fully support Swig wrapping so split based on cmake version:
15 # We need to pass that to swig to be sure all modules are generated in the proper dir
16 SET(CMAKE_SWIG_FLAGS "-outdir \"${GDCM_BINARY_DIR}/gdcmPython\"")
17 #SET(CMAKE_SWIG_OUTDIR "${GDCM_BINARY_DIR}/gdcmPython")
18 # Looks like a bug to me in cmake 2.0.x:
19 SEPARATE_ARGUMENTS(CMAKE_SWIG_FLAGS)
21 FIND_PACKAGE(SWIG REQUIRED)
23 INCLUDE(${SWIG_USE_FILE})
27 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON)
28 # BUG: This is only needed with cmake <= 2.0.5
29 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "")
31 SWIG_ADD_MODULE(gdcm python gdcm.i) #gdcm_wrap.cxx, or gdcmPYTHON_wrap.cxx
32 SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES})
34 # Get rid of -Wall / -W / -pedantic if exist
35 SET(CMAKE_CXX_FLAGS "")
36 # I guess I need to put them back on this file:
37 #SET_SOURCE_FILES_PROPERTIES(
38 # ${swig_generated_file_fullname}
39 # PROPERTIES COMPILE_FLAGS "")
41 INSTALL_TARGETS(/lib/gdcm/ _gdcm)
43 #-----------------------------------------------------------------------------
47 # Include the VTK library
48 INCLUDE(${VTK_USE_FILE})
51 ${GDCM_SOURCE_DIR}/vtk
54 SET(vtkgdcmPython_la_SOURCES
55 ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
56 ${GDCM_SOURCE_DIR}/vtk/vtkGdcmWriter.cxx
58 SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
60 # Configure Python module, which is the plugin itself
62 IF(NOT VTK_WRAP_PYTHON)
63 MESSAGE(FATAL_ERROR "Can't build gdcm python wrapping if VTK_WRAP_PYTHON is OFF" )
64 ENDIF(NOT VTK_WRAP_PYTHON)
65 VTK_WRAP_PYTHON2(vtkgdcmPython gdcmWrapSOURCES
66 ${vtkgdcmPython_la_SOURCES})
67 # The C++ files must be made into a C++ library
68 ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmWrapSOURCES}) #MODULE on apple ?
69 # set the libraries to link against
70 #SET_TARGET_PROPERTIES(${foobar} PROPERTIES PREFIX "")
72 #GET_TARGET_PROPERTY(swig_gdcm_fullpath "${SWIG_MODULE_gdcm_REAL_NAME}" LOCATION)
73 TARGET_LINK_LIBRARIES (vtkgdcmPython
77 INSTALL_TARGETS(/lib/gdcm/ vtkgdcmPython)
79 ENDIF (GDCM_WRAP_PYTHON)
82 # generate a setup.py according to VTK installation
83 # put it in subdir in order to not override old one
85 #GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
87 # ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
88 # ${GDCM_BINARY_DIR}/setup.py
91 #-----------------------------------------------------------------------------
92 # Python package configuration
93 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmVersion.py
94 "gdcmVERSION=\"${GDCM_VERSION}\"\n"
97 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
98 "__all__ = [\"core\",\n"
103 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/core.py
104 "from gdcmVersion import *\n"
106 "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
110 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/vtk.py
112 "from gdcmVersion import *\n"
113 "if os.name == 'posix':\n"
114 " from libvtkgdcmPython import *\n"
116 " from vtkgdcmPython import *\n"
117 "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
121 #-----------------------------------------------------------------------------
122 # Python installation
124 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
125 "${GDCM_BINARY_DIR}\n"
126 "${GDCM_BINARY_DIR}/bin/release\n"
129 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
130 "${CMAKE_INSTALL_PREFIX}/lib/gdcm\n"
134 # Install a python path file in site-packages that tells
135 # python where to find the gdcmPython module
137 FIND_PATH(PYTHON_DIR "site-packages"
143 STRING(REGEX REPLACE "/usr" "" PYTHON_DIR ${PYTHON_DIR})
145 INSTALL_FILES(${PYTHON_DIR}/site-packages FILES
146 "${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth"
148 INSTALL_FILES(/lib/gdcm/gdcmPython FILES
157 #-----------------------------------------------------------------------------
158 # Add test from demo subdir: