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)
21 INCLUDE(${SWIG_USE_FILE})
23 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON)
24 # Setting SWIG_FLAGS to "-includeall" at the following line looks like
25 # a bad idea since swig tries to recursively include all the referenced
26 # files, "including" the C++ <sstream>, <list>, <map>... Of course swig
27 # has no way of finding the path to those files (unless it is told by
28 # cmake) since they are related to the compiler installation layout.
29 # Anyhow, since this inclusion recursion is not necessary, just don't
31 # Note: apparently the line is required in order to avoid a NOTFOUND
32 # as argument of swig on invocation of make.
33 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "")
34 SWIG_ADD_MODULE(gdcm python gdcm.i) #gdcm_wrap.cxx
35 SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES})
37 # Get rid of -Wall / -W / -pedantic if exist
38 #SET(CMAKE_CXX_FLAGS "")
39 # I guess I need to put them back on the this file:
40 SET_SOURCE_FILES_PROPERTIES(${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
41 PROPERTIES COMPILE_FLAGS "" GENERATED 1)
44 # ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
45 # ${GDCM_SOURCE_DIR}/gdcmConfigure.h
48 INSTALL_TARGETS(/lib/gdcm/ _gdcm)
50 #-----------------------------------------------------------------------------
54 # Include the VTK library
55 INCLUDE(${VTK_USE_FILE})
58 ${GDCM_SOURCE_DIR}/vtk
61 SET(vtkgdcmPython_la_SOURCES
62 ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
63 ${GDCM_SOURCE_DIR}/vtk/vtkGdcmWriter.cxx
65 SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
67 # Configure Python module, which is the plugin itself
69 IF(NOT VTK_WRAP_PYTHON)
70 MESSAGE(FATAL_ERROR "Can't build gdcm python wrapping if VTK_WRAP_PYTHON is OFF" )
71 ENDIF(NOT VTK_WRAP_PYTHON)
72 VTK_WRAP_PYTHON2(vtkgdcmPython gdcmWrapSOURCES
73 ${vtkgdcmPython_la_SOURCES})
74 # The C++ files must be made into a C++ library
75 ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmWrapSOURCES}) #MODULE on apple ?
76 # set the libraries to link against
77 #SET_TARGET_PROPERTIES(${foobar} PROPERTIES PREFIX "")
79 #GET_TARGET_PROPERTY(swig_gdcm_fullpath "${SWIG_MODULE_gdcm_REAL_NAME}" LOCATION)
80 TARGET_LINK_LIBRARIES (vtkgdcmPython
84 INSTALL_TARGETS(/lib/gdcm/ vtkgdcmPython)
86 ENDIF (GDCM_WRAP_PYTHON)
89 # generate a setup.py according to VTK installation
90 # put it in subdir in order to not override old one
92 #GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
94 # ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
95 # ${GDCM_BINARY_DIR}/setup.py
98 #-----------------------------------------------------------------------------
99 # Python package configuration
100 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmVersion.py
101 "gdcmVERSION=\"${GDCM_VERSION}\"\n"
104 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
105 "__all__ = [\"core\",\n"
110 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/core.py
111 "from gdcmVersion import *\n"
113 "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
117 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/vtk.py
119 "from gdcmVersion import *\n"
120 "if os.name == 'posix':\n"
121 " from libvtkgdcmPython import *\n"
123 " from vtkgdcmPython import *\n"
124 "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
128 #-----------------------------------------------------------------------------
129 # Python installation
131 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
132 "${GDCM_BINARY_DIR}\n"
133 "${GDCM_BINARY_DIR}/bin/release\n"
136 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
137 "${CMAKE_INSTALL_PREFIX}/lib/gdcm\n"
140 FIND_PATH(PYTHON_INSTALL "site-packages"
141 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath]
142 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath]
143 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath]
144 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]
145 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]
146 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath]
147 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath]
156 STRING(REGEX REPLACE "/usr(.*)/config.*" "\\1" PYTHON_INSTALL ${PYTHON_LIBRARY})
158 INSTALL_FILES(${PYTHON_INSTALL}/site-packages "\\.pth$")
159 INSTALL_FILES(/lib/gdcm/gdcmPython "\\.py$")
160 INSTALL_FILES(/lib/gdcm/gdcmPython FILES "gdcm.py")
162 #-----------------------------------------------------------------------------
163 # Add test from demo subdir: