]> Creatis software - gdcm.git/blob - gdcmPython/CMakeLists.txt
ENH: Now gdcmVersion.py is automatically generated
[gdcm.git] / gdcmPython / CMakeLists.txt
1 # TODO
2 # http://www.cmake.org/pipermail/cmake/2003-August/004185.html
3 # http://www.cmake.org/pipermail/cmake/2003-January/001092.html
4
5 INCLUDE_DIRECTORIES(
6   ${GDCM_SOURCE_DIR}/src
7   ${PYTHON_INCLUDE_PATH}
8   ${GDCM_BINARY_DIR}/
9 )
10
11 #-----------------------------------------------------------------------------
12 # Create the gdcmVersion.py file:
13 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmVersion.py
14   "gdcmVERSION=\"${GDCM_VERSION_FULL}\""
15   )
16
17 #-----------------------------------------------------------------------------
18 # SWIG Wrapping
19 #
20
21 # Since the file gdcm_wrap.cxx does not exist, mark it as GENERATED:
22 SET_SOURCE_FILES_PROPERTIES(gdcm_wrap.cxx GENERATED)
23 ADD_LIBRARY(pygdcm gdcm_wrap.cxx)
24
25 TARGET_LINK_LIBRARIES(pygdcm 
26   ${PYTHON_LIBRARY}
27   gdcm
28 )
29 # http://www.cmake.org/pipermail/cmake/2003-August/004190.html
30 # SET_TARGET_PROPERTIES(pygdcm PROPERTIES PREFIX "_")
31
32 #-----------------------------------------------------------------------------
33 # SWIG Wrapping
34 #
35
36 # As of 09/10/2003 there was no FindSWIG.cmake
37 # later we should use SWIG instead of swig
38 # Build our custom command :
39 ADD_CUSTOM_COMMAND(
40   TARGET    pygdcm
41   COMMAND   swig
42   ARGS      -python -c++ -I${GDCM_SOURCE_DIR}/src -o 
43             ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx 
44             ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i 
45   SOURCE    ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i
46   OUTPUTS   ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
47   COMMENT   "Generating gdcm_wrap.cxx/gdcm.py based on gdcm.i"
48 )
49
50 # This swig command will also outputs gdcm.py :
51 SET_SOURCE_FILES_PROPERTIES(gdcm.py GENERATED)
52
53 #-----------------------------------------------------------------------------
54 # VTK Wrapping
55
56 IF(GDCM_VTK)
57   INCLUDE_DIRECTORIES(
58     ${GDCM_SOURCE_DIR}/vtk
59   )
60
61   SET(vtkgdcmPython_la_SOURCES
62       ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
63   )
64   SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
65   
66   # Configure Python module, which is the plugin itself
67   IF (GDCM_WRAP_PYTHON)
68     VTK_WRAP_PYTHON2(vtkgdcmPython gdcmfoo
69                    ${vtkgdcmPython_la_SOURCES})
70     # The C++ files must be made into a C++ library
71     ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmfoo})
72     # set the libraries to link against
73     TARGET_LINK_LIBRARIES (vtkgdcmPython
74                            pygdcm
75                            vtkgdcm
76                            vtkCommonPython
77                            vtkIOPython)
78   ENDIF (GDCM_WRAP_PYTHON)
79   
80   #generate a setup.py according to VTK installation 
81   #put it in subdir in order to not override old one
82   # as it is a pain...override existing file...
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   #MESSAGE(STATUS ${VTKPATH})
90 ENDIF(GDCM_VTK)
91
92 #-----------------------------------------------------------------------------
93 # Install stuff:
94
95 #Should install in path of PYTHON_LIBRARY and not the default CMAKE_INSTALL_PREFIX
96
97 GET_FILENAME_COMPONENT(PYTHON_LIB_INSTALL ${PYTHON_LIBRARY} PATH)
98 GET_FILENAME_COMPONENT(SITEPACKAGE 
99   ${PYTHON_LIB_INSTALL}/../site-packages ABSOLUTE)
100 #MESSAGE(STATUS ${SITEPACKAGE})
101 #INSTALL_FILES(/include "\\.h$")
102 #INSTALL_TARGETS(/lib/ gdcm)
103
104 # gdcm.py is a file generated by swig
105 # then from python you can do import gdcm, and it will load _gdcm.so
106 #INSTALL_TARGETS(/lib/ gdcm.py)
107 #INSTALL_PROGRAMS(/lib/ gdcm.py)
108 #INSTALL_FILES(/lib/ .py gdcm.py)
109
110 # When installing swig-generated python module one should pay attention
111 # to library naming convention, see here for more detail:
112 # http://www.swig.org/Doc1.3/Python.html#n6
113 # even with the $swig -module mylib, there is always a trailing underscore added