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