]> Creatis software - gdcm.git/blob - gdcmPython/CMakeLists.txt
* Fix the unix installation for the python part
[gdcm.git] / gdcmPython / CMakeLists.txt
1 # gdcm Python wrapping stuff:
2
3 INCLUDE_DIRECTORIES(
4   ${GDCM_SOURCE_DIR}/src
5   ${PYTHON_INCLUDE_PATH}
6   ${GDCM_BINARY_DIR}/
7 )
8
9 #-----------------------------------------------------------------------------
10 # SWIG Wrapping
11 #
12
13 # CMake 2.0 will fully support Swig wrapping so split based on cmake version:
14
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)
20
21 FIND_PACKAGE(SWIG REQUIRED)
22 IF(SWIG_FOUND)
23   INCLUDE(${SWIG_USE_FILE})
24 ENDIF(SWIG_FOUND)
25
26
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 "")
30 # END OF BUG
31 SWIG_ADD_MODULE(gdcm python gdcm.i)  #gdcm_wrap.cxx, or gdcmPYTHON_wrap.cxx
32 SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES})
33
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 "")
40
41 INSTALL_TARGETS(/lib/gdcm/ _gdcm)
42
43 #-----------------------------------------------------------------------------
44 # VTK Wrapping
45
46 IF(GDCM_VTK)
47   # Include the VTK library
48   INCLUDE(${VTK_USE_FILE})
49
50   INCLUDE_DIRECTORIES(
51     ${GDCM_SOURCE_DIR}/vtk
52   )
53
54   SET(vtkgdcmPython_la_SOURCES
55       ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
56       ${GDCM_SOURCE_DIR}/vtk/vtkGdcmWriter.cxx
57   )
58   SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
59   
60   # Configure Python module, which is the plugin itself
61   IF (GDCM_WRAP_PYTHON)
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 "")
71
72     #GET_TARGET_PROPERTY(swig_gdcm_fullpath "${SWIG_MODULE_gdcm_REAL_NAME}" LOCATION)
73     TARGET_LINK_LIBRARIES (vtkgdcmPython
74                            vtkgdcm
75                            vtkCommonPython
76                            vtkIOPython)
77     INSTALL_TARGETS(/lib/gdcm/ vtkgdcmPython)
78
79   ENDIF (GDCM_WRAP_PYTHON)
80 ENDIF(GDCM_VTK)
81
82 # generate a setup.py according to VTK installation
83 # put it in subdir in order to not override old one
84 #
85 #GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
86 #CONFIGURE_FILE(
87 #    ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
88 #    ${GDCM_BINARY_DIR}/setup.py
89 #)
90
91 #-----------------------------------------------------------------------------
92 # Python package configuration
93 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmVersion.py
94     "gdcmVERSION=\"${GDCM_VERSION}\"\n"
95     )
96
97 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
98     "__all__ = [\"core\",\n"
99     "           \"vtk\",\n"
100     "          ]\n"
101     )
102
103 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/core.py
104     "from gdcmVersion import *\n"
105     "import gdcm\n"
106     "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
107     )
108
109 IF(GDCM_VTK)
110   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/vtk.py
111     "import os\n"
112     "from gdcmVersion import *\n"
113     "if os.name == 'posix':\n"
114     "  from libvtkgdcmPython import *\n"
115     "else:\n"
116     "  from vtkgdcmPython import *\n"
117     "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
118     )
119 ENDIF(GDCM_VTK)
120
121 #-----------------------------------------------------------------------------
122 # Python installation
123 IF(WIN32)
124   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
125        "${GDCM_BINARY_DIR}\n"
126        "${GDCM_BINARY_DIR}/bin/release\n"
127   )
128 ELSE(WIN32)
129   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
130        "${CMAKE_INSTALL_PREFIX}/lib/gdcm\n"
131   )
132 ENDIF(WIN32)
133
134 # Install a python path file in site-packages that tells
135 # python where to find the gdcmPython module
136 IF(UNIX)
137   FIND_PATH(PYTHON_DIR "site-packages"
138      /usr/lib/python2.4
139      /usr/lib/python2.3
140      /usr/lib/python2.2
141      /usr/lib/python2.1
142   ) 
143   STRING(REGEX REPLACE "/usr" "" PYTHON_DIR ${PYTHON_DIR})
144
145   INSTALL_FILES(${PYTHON_DIR}/site-packages FILES 
146     "${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth"
147   )
148   INSTALL_FILES(/lib/gdcm/gdcmPython FILES 
149     "gdcm.py" 
150     "__init__.py" 
151     "gdcmVersion.py" 
152     "core.py" 
153     "vtk.py"
154   )
155 ENDIF(UNIX)
156
157 #-----------------------------------------------------------------------------
158 # Add test from demo subdir:
159
160 SUBDIRS(demo)