]> Creatis software - gdcm.git/blob - gdcmPython/CMakeLists.txt
BUG: I hate cmake...
[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 # Looks like a bug to me in cmake 2.0.x:
18 SEPARATE_ARGUMENTS(CMAKE_SWIG_FLAGS)
19
20 FIND_PACKAGE(SWIG REQUIRED)
21 INCLUDE(${SWIG_USE_FILE})
22
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
30 # do it.
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})
36
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)
42
43 #ADD_DEPENDENCIES(
44 #  ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
45 #  ${GDCM_SOURCE_DIR}/gdcmConfigure.h
46 #  )
47
48 INSTALL_TARGETS(/lib/gdcm/ _gdcm)
49
50 #-----------------------------------------------------------------------------
51 # VTK Wrapping
52
53 IF(GDCM_VTK)
54   # Include the VTK library
55   INCLUDE(${VTK_USE_FILE})
56
57   INCLUDE_DIRECTORIES(
58     ${GDCM_SOURCE_DIR}/vtk
59   )
60
61   SET(vtkgdcmPython_la_SOURCES
62       ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
63       ${GDCM_SOURCE_DIR}/vtk/vtkGdcmWriter.cxx
64   )
65   SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
66   
67   # Configure Python module, which is the plugin itself
68   IF (GDCM_WRAP_PYTHON)
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 "")
78
79     #GET_TARGET_PROPERTY(swig_gdcm_fullpath "${SWIG_MODULE_gdcm_REAL_NAME}" LOCATION)
80     TARGET_LINK_LIBRARIES (vtkgdcmPython
81                            vtkgdcm
82                            vtkCommonPython
83                            vtkIOPython)
84     INSTALL_TARGETS(/lib/gdcm/ vtkgdcmPython)
85
86   ENDIF (GDCM_WRAP_PYTHON)
87 ENDIF(GDCM_VTK)
88
89 # generate a setup.py according to VTK installation
90 # put it in subdir in order to not override old one
91 #
92 #GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
93 #CONFIGURE_FILE(
94 #    ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
95 #    ${GDCM_BINARY_DIR}/setup.py
96 #)
97
98 #-----------------------------------------------------------------------------
99 # Python package configuration
100 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmVersion.py
101     "gdcmVERSION=\"${GDCM_VERSION}\"\n"
102     )
103
104 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
105     "__all__ = [\"core\",\n"
106     "           \"vtk\",\n"
107     "          ]\n"
108     )
109
110 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/core.py
111     "from gdcmVersion import *\n"
112     "import gdcm\n"
113     "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
114     )
115
116 IF(GDCM_VTK)
117   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/vtk.py
118     "import os\n"
119     "from gdcmVersion import *\n"
120     "if os.name == 'posix':\n"
121     "  from libvtkgdcmPython import *\n"
122     "else:\n"
123     "  from vtkgdcmPython import *\n"
124     "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
125     )
126 ENDIF(GDCM_VTK)
127
128 #-----------------------------------------------------------------------------
129 # Python installation
130 IF(WIN32)
131   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
132        "${GDCM_BINARY_DIR}\n"
133        "${GDCM_BINARY_DIR}/bin/release\n"
134   )
135 ELSE(WIN32)
136   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
137        "${CMAKE_INSTALL_PREFIX}/lib/gdcm\n"
138   )
139 ENDIF(WIN32)
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]
148     /usr/lib/python2.4
149     /usr/lib/python2.3
150     /usr/lib/python2.2
151     /usr/lib/python2.1
152     /usr/lib/python2.0
153     /usr/lib/python1.6
154     /usr/lib/python1.5
155 )
156 STRING(REGEX REPLACE "/usr(.*)/config.*" "\\1" PYTHON_INSTALL ${PYTHON_LIBRARY})
157
158 INSTALL_FILES(${PYTHON_INSTALL}/site-packages "\\.pth$")
159 INSTALL_FILES(/lib/gdcm/gdcmPython "\\.py$")
160 INSTALL_FILES(/lib/gdcm/gdcmPython FILES "gdcm.py")
161
162 #-----------------------------------------------------------------------------
163 # Add test from demo subdir:
164
165 SUBDIRS(demo)