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 # Looks like a bug to me in cmake 2.0.x:
18 SEPARATE_ARGUMENTS(CMAKE_SWIG_FLAGS)
20 FIND_PACKAGE(SWIG REQUIRED)
22 INCLUDE(${SWIG_USE_FILE})
26 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON)
27 # BUG: This is only needed with cmake <= 2.0.5
28 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "")
30 SWIG_ADD_MODULE(gdcm python gdcm.i) #gdcm_wrap.cxx, or gdcmPYTHON_wrap.cxx
31 SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES})
33 # Get rid of -Wall / -W / -pedantic if exist
34 SET(CMAKE_CXX_FLAGS "")
35 # I guess I need to put them back on this file:
36 #SET_SOURCE_FILES_PROPERTIES(
37 # ${swig_generated_file_fullname}
38 # PROPERTIES COMPILE_FLAGS "")
40 INSTALL_TARGETS(/lib/gdcm/ _gdcm)
42 #-----------------------------------------------------------------------------
46 # Include the VTK library
47 INCLUDE(${VTK_USE_FILE})
50 ${GDCM_SOURCE_DIR}/vtk
53 SET(vtkgdcmPython_la_SOURCES
54 ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
55 ${GDCM_SOURCE_DIR}/vtk/vtkGdcmWriter.cxx
57 SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
59 # Configure Python module, which is the plugin itself
61 IF(NOT VTK_WRAP_PYTHON)
62 MESSAGE(FATAL_ERROR "Can't build gdcm python wrapping if VTK_WRAP_PYTHON is OFF" )
63 ENDIF(NOT VTK_WRAP_PYTHON)
64 VTK_WRAP_PYTHON2(vtkgdcmPython gdcmWrapSOURCES
65 ${vtkgdcmPython_la_SOURCES})
66 # The C++ files must be made into a C++ library
67 ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmWrapSOURCES}) #MODULE on apple ?
68 # set the libraries to link against
69 #SET_TARGET_PROPERTIES(${foobar} PROPERTIES PREFIX "")
71 #GET_TARGET_PROPERTY(swig_gdcm_fullpath "${SWIG_MODULE_gdcm_REAL_NAME}" LOCATION)
72 TARGET_LINK_LIBRARIES (vtkgdcmPython
76 INSTALL_TARGETS(/lib/gdcm/ vtkgdcmPython)
78 ENDIF (GDCM_WRAP_PYTHON)
81 # generate a setup.py according to VTK installation
82 # put it in subdir in order to not override old one
84 #GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
86 # ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
87 # ${GDCM_BINARY_DIR}/setup.py
90 #-----------------------------------------------------------------------------
91 # Python package configuration
92 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmVersion.py
93 "gdcmVERSION=\"${GDCM_VERSION}\"\n"
96 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
97 "__all__ = [\"core\",\n"
102 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/core.py
103 "from gdcmVersion import *\n"
105 "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
109 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/vtk.py
111 "from gdcmVersion import *\n"
112 "if os.name == 'posix':\n"
113 " from libvtkgdcmPython import *\n"
115 " from vtkgdcmPython import *\n"
116 "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
120 #-----------------------------------------------------------------------------
121 # Python installation
123 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
124 "${GDCM_BINARY_DIR}\n"
125 "${GDCM_BINARY_DIR}/bin/release\n"
128 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
129 "${CMAKE_INSTALL_PREFIX}/lib/gdcm\n"
133 FIND_PATH(PYTHON_DIR "site-packages"
139 STRING(REGEX REPLACE "/usr" "" PYTHON_DIR ${PYTHON_DIR})
141 INSTALL_FILES(${PYTHON_DIR}/site-packages "gdcmPython.pth")
142 INSTALL_FILES(/lib/gdcm/gdcmPython "\\.py$")
143 INSTALL_FILES(/lib/gdcm/gdcmPython FILES "gdcm.py")
145 #-----------------------------------------------------------------------------
146 # Add test from demo subdir: