]> Creatis software - gdcm.git/blob - gdcmPython/CMakeLists.txt
Swig should be found on win32 now, some cosmetic cleanup too
[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 # CMake 2.0 will fully support Swig wrapping so split based on cmake version:
22
23 IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
24
25   FIND_PACKAGE(SWIG REQUIRED)
26   INCLUDE(${SWIG_USE_FILE})
27
28   #INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
29
30   #SET(CMAKE_SWIG_FLAGS "")
31
32   SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON)
33   SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "-includeall")
34   SWIG_ADD_MODULE(gdcm python
35     gdcm.i gdcm_wrap.cxx)
36   SWIG_LINK_LIBRARIES(gdcm ${PYTHON_LIBRARIES})
37   TARGET_LINK_LIBRARIES(_gdcm gdcm)
38
39 ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)   
40
41   # As of 09/10/2003 there was no FindSWIG.cmake
42   # later we should use SWIG instead of swig
43   FIND_PROGRAM(SWIG_EXECUTABLE
44     NAMES swig-1.3 swig
45   )
46   
47   IF(NOT SWIG_EXECUTABLE)
48     MESSAGE(FATAL_ERROR "Swig could not be found wrapping is impossible")
49   ENDIF(NOT SWIG_EXECUTABLE)
50   
51   # Build our custom command :
52   ADD_CUSTOM_COMMAND(
53     TARGET    pygdcm
54     COMMAND   ${SWIG_EXECUTABLE}
55     ARGS      -python -c++ -I${GDCM_SOURCE_DIR}/src -o 
56               ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx 
57               ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i 
58     SOURCE    ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i
59     OUTPUTS   ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx
60     COMMENT   "Generating gdcm_wrap.cxx/gdcm.py based on gdcm.i"
61   )
62   # This swig command will also outputs gdcm.py :
63   SET_SOURCE_FILES_PROPERTIES(gdcm.py GENERATED)
64   # Since the file gdcm_wrap.cxx does not exist, mark it as GENERATED:
65   SET_SOURCE_FILES_PROPERTIES(gdcm_wrap.cxx GENERATED)
66
67   ADD_LIBRARY(pygdcm gdcm_wrap.cxx)
68   TARGET_LINK_LIBRARIES(pygdcm
69     ${PYTHON_LIBRARY}
70     gdcm
71   )
72   # http://www.cmake.org/pipermail/cmake/2003-August/004190.html
73   SET_TARGET_PROPERTIES(pygdcm PROPERTIES PREFIX "_")
74
75 ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)   
76
77
78 #-----------------------------------------------------------------------------
79 # VTK Wrapping
80
81 IF(GDCM_VTK)
82   INCLUDE_DIRECTORIES(
83     ${GDCM_SOURCE_DIR}/vtk
84   )
85
86   SET(vtkgdcmPython_la_SOURCES
87       ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx
88   )
89   SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED)
90   
91   # Configure Python module, which is the plugin itself
92   IF (GDCM_WRAP_PYTHON)
93     VTK_WRAP_PYTHON2(vtkgdcmPython gdcmfoo
94                    ${vtkgdcmPython_la_SOURCES})
95     # The C++ files must be made into a C++ library
96     ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmfoo})
97     # set the libraries to link against
98     TARGET_LINK_LIBRARIES (vtkgdcmPython
99                            #_pygdcm
100                            vtkgdcm
101                            vtkCommonPython
102                            vtkIOPython)
103   ENDIF (GDCM_WRAP_PYTHON)
104   
105   #generate a setup.py according to VTK installation 
106   #put it in subdir in order to not override old one
107   # as it is a pain...override existing file...
108   
109   GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE)
110   CONFIGURE_FILE(
111       ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in
112       ${GDCM_BINARY_DIR}/setup.py
113   )
114   #MESSAGE(STATUS ${VTKPATH})
115 ENDIF(GDCM_VTK)
116
117 #-----------------------------------------------------------------------------
118 # Install stuff:
119
120 #Should install in path of PYTHON_LIBRARY and not the default CMAKE_INSTALL_PREFIX
121
122 GET_FILENAME_COMPONENT(PYTHON_LIB_INSTALL ${PYTHON_LIBRARY} PATH)
123 GET_FILENAME_COMPONENT(SITEPACKAGE 
124   ${PYTHON_LIB_INSTALL}/../site-packages ABSOLUTE)
125 #MESSAGE(STATUS ${SITEPACKAGE})
126 #INSTALL_FILES(/include "\\.h$")
127 #INSTALL_TARGETS(/lib/ gdcm)
128
129 # gdcm.py is a file generated by swig
130 # then from python you can do import gdcm, and it will load _gdcm.so
131 #INSTALL_TARGETS(/lib/ gdcm.py)
132 #INSTALL_PROGRAMS(/lib/ gdcm.py)
133 #INSTALL_FILES(/lib/ .py gdcm.py)
134
135 # When installing swig-generated python module one should pay attention
136 # to library naming convention, see here for more detail:
137 # http://www.swig.org/Doc1.3/Python.html#n6
138 # even with the $swig -module mylib, there is always a trailing underscore added