]> Creatis software - gdcm.git/blob - setup.py
For the Linux part of the Packaging
[gdcm.git] / setup.py
1 from distutils.core import setup
2 import glob, os, sys, shutil
3 from distutilsWrapping import *
4 from WrapSwig import *
5 from WrapVTK import *
6
7 ThisModule='gdcmPython'
8 gdcmPythonSrcDir=ThisModule
9 gdcmSrcDir      ="src"
10 gdcmJpeg8SrcDir  =os.path.join('src', 'jpeg', 'libijg8')
11 gdcmvtkSrcDir   ="vtk"
12 gdcmDictsDir    ="Dicts"
13 gdcmTestDir     ="Test"
14
15 # Due to a disutil oddity on Unices : see
16 # http://aspn.activestate.com/ASPN/Mail/Message/distutils-sig/588325
17 if(os.name=='posix'):
18         targetDir=os.path.join('lib','python'+sys.version[:3],'site-packages')
19         libraries=["stdc++"]
20         macros   =[('__STDC_LIMIT_MACROS', '1')]
21
22         VTKPATH="/usr"
23         vtkWrapper="vtkWrapPython"
24 else:
25         targetDir=os.path.join('lib','site-packages')
26         libraries=["WSOCK32"]
27         macros   =[]
28
29         try:
30                 VTKPATH=os.environ['VTKPATH']
31         except KeyError,e:
32                 err=str(e)
33                 print "Environment variable",err[err.rfind(':')+1:],'not defined, '\
34                        'please fix it!'
35                 VTKPATH="c:\\Creatis\\vtkDistrib"
36         vtkWrapper=os.path.join(VTKPATH,"bin","vtkWrapPython")
37
38 targetDir=os.path.join(targetDir, ThisModule)
39
40 ### Sources section: determination of sources for the extensions:
41 # Sources 1a/ The kernel of gdcm itself (which wrapped with Swig)
42 #             defines the first extension
43 Sources = []
44 Sources.extend(glob.glob(os.path.join(gdcmSrcDir,"*.cxx")))
45 Sources.append(os.path.join(gdcmPythonSrcDir,"gdcm.i"))
46 # Sources 1b/ The kernel of gdcm depends on a jpeg library whose sources are
47 #             contained in subdir gdcmJpeg8SrcDir. But within this subdir
48 #             some of the C files should not be compiled (refer to
49 #             gdcmJpeg8SrcDir/Makefile.am) !
50
51 Jpeg8Sources = glob.glob(os.path.join(gdcmJpeg8SrcDir,"j*.c"))
52 Jpeg8SourcesToRemove = ['jmemansi.c', 'jmemname.c', 'jmemdos.c', 'jmemmac.c']
53 for Remove in Jpeg8SourcesToRemove:
54    ### Because setup.py is a multiple pass process we need to trap
55    ### the case were the files were allready wed out on a previous pass.
56    try:
57       Jpeg8Sources.remove(os.path.join(gdcmJpeg8SrcDir, Remove))
58    except ValueError:
59       continue
60 Sources.extend(Jpeg8Sources)
61
62 Jpeg12Sources = glob.glob(os.path.join(gdcmJpeg12SrcDir,"j*.c"))
63 Jpeg12SourcesToRemove = ['jmemansi12.c', 'jmemname12.c', 'jmemdos12.c', 'jmemmac12.c']
64 for Remove in Jpeg12SourcesToRemove:
65    ### Because setup.py is a multiple pass process we need to trap
66    ### the case were the files were allready wed out on a previous pass.
67    try:
68       Jpeg12Sources.remove(os.path.join(gdcmJpeg12SrcDir, Remove))
69    except ValueError:
70       continue
71 Sources.extend(Jpeg12Sources)
72
73 # Sources 2/ The second extension contains the VTK classes (which we wrap
74 #            with the vtk wrappers):
75 VTK_INCLUDE_DIR=os.path.join(VTKPATH,"include","vtk")
76 VTK_LIB_DIR=os.path.join(VTKPATH,"lib","vtk")
77 vtkSources = []
78 vtkSources.extend(glob.glob(os.path.join(gdcmvtkSrcDir,"vtk*.cxx")))
79 vtkSources.extend(glob.glob(os.path.join(gdcmSrcDir,"*.cxx")))
80 vtkSources.extend(Jpeg8Sources)
81 vtkSources.extend(Jpeg12ources)
82 vtkLibraries=["vtkCommon","vtkCommonPython",
83               "vtkIO","vtkIOPython",
84               "vtkFiltering","vtkFilteringPython"]
85
86 ##### 
87 setup(name=ThisModule,
88       version="0.3",
89       description="...",
90       author="frog",
91       author_email="frog@creatis.insa-lyon.fr",
92       url="http://www.creatis.insa-lyon.fr/",
93       packages=[ '.',
94                  gdcmPythonSrcDir,
95                  gdcmPythonSrcDir + '.demo' ],
96       cmdclass={'build_ext':build_extWrap}, # redirects default build_ext
97       ext_modules=[SwigExtension(name='_gdcm',
98                                  sources=Sources,
99                                  include_dirs=[gdcmSrcDir,gdcmJpeg8SrcDir],[gdcmSrcDir,gdcmJpeg12SrcDir],
100                                  libraries=libraries,
101                                  define_macros=macros,
102                                  swig_cpp=1,
103                                  swig_include=[gdcmSrcDir]
104                                 ),
105                    VTKExtension(name='gdcmPython.vtkgdcmPython',
106                                 sources=vtkSources,
107                                 include_dirs=[gdcmSrcDir,gdcmvtkSrcDir,
108                                               VTK_INCLUDE_DIR],
109                                 libraries=libraries+vtkLibraries,
110                                 define_macros=macros,
111                                 library_dirs=[VTK_LIB_DIR],
112                                 vtkWrapper=vtkWrapper,
113                                ),
114                                                 ],
115       data_files=[(os.path.join(targetDir,gdcmTestDir),
116                    glob.glob(os.path.join(gdcmTestDir,"*.acr"))),
117                   (os.path.join(targetDir,"Dicts"),
118                    glob.glob(os.path.join(gdcmDictsDir,"*.*"))),
119                 ]
120      )