]> Creatis software - gdcm.git/blob - gdcmPython/CMakeLists.txt
STYLE: typo
[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 IF(SWIG_FOUND)
22   INCLUDE(${SWIG_USE_FILE})
23 ENDIF(SWIG_FOUND)
24
25
26 SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON)
27 SWIG_ADD_MODULE(gdcm python gdcm.i)  #gdcm_wrap.cxx, or gdcmPYTHON_wrap.cxx
28 SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES})
29
30 # Get rid of -Wall / -W / -pedantic if exist
31 SET(CMAKE_CXX_FLAGS "")
32 # I guess I need to put them back on this file:
33 SET_SOURCE_FILES_PROPERTIES(
34   ${swig_generated_file_fullname}
35   PROPERTIES COMPILE_FLAGS "")
36
37 INSTALL_TARGETS(/lib/gdcm/ _gdcm)
38
39 #-----------------------------------------------------------------------------
40 # VTK Wrapping
41
42 IF(GDCM_VTK)
43   # Include the VTK library
44   INCLUDE(${VTK_USE_FILE})
45
46   INCLUDE_DIRECTORIES(
47     ${GDCM_SOURCE_DIR}/vtk
48   )
49
50   SET(vtkgdcmPython_la_SOURCES
51       ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
52       ${GDCM_SOURCE_DIR}/vtk/vtkGdcmWriter.cxx
53   )
54   SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
55   
56   # Configure Python module, which is the plugin itself
57   IF (GDCM_WRAP_PYTHON)
58     IF(NOT VTK_WRAP_PYTHON)
59       MESSAGE(FATAL_ERROR "Can't build gdcm python wrapping if VTK_WRAP_PYTHON is OFF" )
60     ENDIF(NOT VTK_WRAP_PYTHON)
61     VTK_WRAP_PYTHON2(vtkgdcmPython gdcmWrapSOURCES
62                    ${vtkgdcmPython_la_SOURCES})
63     # The C++ files must be made into a C++ library
64     ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmWrapSOURCES})  #MODULE on apple ?
65     # set the libraries to link against
66     #SET_TARGET_PROPERTIES(${foobar} PROPERTIES PREFIX "")
67
68     #GET_TARGET_PROPERTY(swig_gdcm_fullpath "${SWIG_MODULE_gdcm_REAL_NAME}" LOCATION)
69     TARGET_LINK_LIBRARIES (vtkgdcmPython
70                            vtkgdcm
71                            vtkCommonPython
72                            vtkIOPython)
73     INSTALL_TARGETS(/lib/gdcm/ vtkgdcmPython)
74
75   ENDIF (GDCM_WRAP_PYTHON)
76 ENDIF(GDCM_VTK)
77
78 # generate a setup.py according to VTK installation
79 # put it in subdir in order to not override old one
80 #
81 #GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
82 #CONFIGURE_FILE(
83 #    ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
84 #    ${GDCM_BINARY_DIR}/setup.py
85 #)
86
87 #-----------------------------------------------------------------------------
88 # Python package configuration
89 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmVersion.py
90     "gdcmVERSION=\"${GDCM_VERSION}\"\n"
91     )
92
93 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
94     "__all__ = [\"core\",\n"
95     "           \"vtk\",\n"
96     "          ]\n"
97     )
98
99 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/core.py
100     "from gdcmVersion import *\n"
101     "import gdcm\n"
102     "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
103     )
104
105 IF(GDCM_VTK)
106   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/vtk.py
107     "import os\n"
108     "from gdcmVersion import *\n"
109     "if os.name == 'posix':\n"
110     "  from libvtkgdcmPython import *\n"
111     "else:\n"
112     "  from vtkgdcmPython import *\n"
113     "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n"
114     )
115 ENDIF(GDCM_VTK)
116
117 #-----------------------------------------------------------------------------
118 # Python installation
119 IF(WIN32)
120   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
121        "${GDCM_BINARY_DIR}\n"
122        "${GDCM_BINARY_DIR}/bin/release\n"
123   )
124 ELSE(WIN32)
125   FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth
126        "${CMAKE_INSTALL_PREFIX}/lib/gdcm\n"
127   )
128 ENDIF(WIN32)
129 FIND_PATH(PYTHON_INSTALL "site-packages"
130     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath]
131     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath]
132     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath]
133     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]
134     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]
135     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath]
136     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath]
137     /usr/lib/python2.4
138     /usr/lib/python2.3
139     /usr/lib/python2.2
140     /usr/lib/python2.1
141     /usr/lib/python2.0
142     /usr/lib/python1.6
143     /usr/lib/python1.5
144 )
145 STRING(REGEX REPLACE "/usr(.*)/config.*" "\\1" PYTHON_INSTALL ${PYTHON_LIBRARY})
146
147 INSTALL_FILES(${PYTHON_INSTALL}/site-packages "\\.pth$")
148 INSTALL_FILES(/lib/gdcm/gdcmPython "\\.py$")
149 INSTALL_FILES(/lib/gdcm/gdcmPython FILES "gdcm.py")
150
151 #-----------------------------------------------------------------------------
152 # Add test from demo subdir:
153
154 SUBDIRS(demo)