root/branches/Carsten_PtrWork2/Tools/scons-build/LibraryUtils.py

Revision 495, 5.9 kB (checked in by aronb, 2 years ago)

Fix various problems with osg2-config on windows.

  • Add support for library extentions (.lib)
  • Correctly excape '/'s in windows paths.
  • Property svn:eol-style set to native
Line 
1 import copy
2
3 class LibraryInfo(object):
4    """ Helper class for capturing all the files that we are finding in source tree.
5        This class is used internally by the build and by the osg-config script.
6    """
7    def __init__(self, name=""):
8       self.name = name
9       self.source_files = []         # List of source files for this library
10       self.header_files = []         # List of header files for this library
11       self.test_files = []           # list of source files for tests
12       self.osg_dep_libs = []         # Names of OpenSG libraries we depend on
13       self.libs = []                 # Names of other libraries we depend on
14       self.libpath = []              # Paths to dependent libs
15       self.frameworks = []           # Names of other frameworks we depend on
16       self.frameworkpath = []        # Paths to dependent frameworks
17       self.cpppath = []              # List of extra paths we need to compile
18       self.osg_test_libs = []        # Names of OSG libraries the tests depend on
19       self.other_test_libs = []      # Names of non-OSG libraries the tests depend on
20       self.test_cpppath = []         # Includedirs of libraries the tests depend on
21       self.test_libpath = []         # Libpaths of libraries the tests depend on
22       self.unittest_files = []       # list of source files for unit tests
23
24    def dump(self):
25       """ Dump contained data to a dictionary that could be pprinted. """
26       ret_dict = {}
27       for i in self.__dict__.keys():
28          if i not in ["source_files","header_files","test_files"]:
29             ret_dict[i] = self.__dict__[i]               
30       return ret_dict
31
32    def load(self, dumpDict):
33       """ Load status from a dumped dictionary."""
34       for i in self.__dict__.keys():
35          if dumpDict.has_key(i):
36             self.__dict__[i] = dumpDict[i]
37            
38    def merge(self, other):
39       """ Merge our library information with another library info object. """
40       # Merge the lists but only merge in new unique entries
41       for a in ["source_files","header_files","test_files","osg_dep_libs",
42                 "libs","libpath","frameworks","frameworkpath","cpppath",
43                 "osg_test_libs","other_test_libs","test_cpppath","test_libpath","unittest_files"]:
44          getattr(self,a).extend([i for i in getattr(other,a) if not i in getattr(self,a)])
45  
46
47    def getLibDepList(self, knownList, libMap):
48       """ Return list of all OSG libraries that we depend upon (and that they depend upon).
49           Get full list of dependent libraries based on libMap and existing known list.
50       """     
51       dep_list = []
52       dep_list.extend([l for l in self.osg_dep_libs if not (l in knownList)])
53       for l in dep_list[:]:
54          if libMap.has_key(l):
55             sub_deps = libMap[l].getLibDepList(knownList + dep_list, libMap)           
56             dep_list.extend(sub_deps)           
57       return dep_list
58    
59    def createMergedDepLibrary(self, libMap):
60       """ Return a new library object with all of the options
61           merged for the dependencies of this library.
62           This is used to combine all the options for a library and
63           it's dependencies into a single object
64           osg_dep_libs will be filled with all OSG libs (not just dep libs)
65       """     
66       dep_list = self.getLibDepList([], libMap)
67       if not self.name in dep_list:
68          dep_list.insert(0,self.name)
69      
70       #print "Deps for lib: %s  are: %s"%(self.name, dep_list)   
71       
72       dep_lib_list = [libMap[l] for l in dep_list]   
73       merged_lib = LibraryInfo()
74       merged_lib.osg_dep_libs = dep_list[:]   # Add on the OSG libraries
75       
76       for lib in dep_lib_list:
77          merged_lib.merge(lib)         
78          
79       return merged_lib
80
81 class ConfigInfoAdapter(object):
82    """ Class to adapt a LibraryInfo object into something that returns config info
83        type data.  (flags, paths, etc)
84       
85        libs: List or single library. (string name of class)
86        libMap: Map from string library name to library object.
87        osg_lib_suffix: Suffix to use for names of OSG libraries.
88    """
89    def __init__(self, libs, libMap, defaultMergedLib=None,
90                 incprefix="-I", libprefix="-l", libpathprefix="-L",
91                 osg_lib_suffix="", osg_lib_ext=""):
92      
93       libraries = copy.copy(libs)    # Make a copy so we don't modify the original
94       
95       # Make sure we have a list of library objects
96       if not type(libraries) == list:
97          libraries = [libraries]
98       for i in range(len(libraries)):
99          if type(libraries[i]) == str:
100             libraries[i] = libMap[libraries[i]]
101      
102       self.merged_lib = LibraryInfo()
103       if defaultMergedLib:
104          self.merged_lib = copy.copy(defaultMergedLib)   
105    
106       for lib in libraries:
107          if not self.merged_lib:
108             self.merged_lib = lib.createMergedDepLibrary(libMap)                             
109          else:           
110             self.merged_lib.merge(lib.createMergedDepLibrary(libMap))
111      
112       self.incprefix = incprefix
113       self.libprefix = libprefix
114       self.libpathprefix = libpathprefix
115       self.osg_lib_suffix = osg_lib_suffix
116       self.osg_lib_ext = osg_lib_ext
117
118    def getIncPath(self):
119       return self.merged_lib.cpppath
120    def getIncPathStr(self):
121       return " ".join(["%s%s"%(self.incprefix,p) for p in self.merged_lib.cpppath])
122    def getLibs(self):
123       osg_lib_list = ["%s%s%s"%(l,self.osg_lib_suffix, self.osg_lib_ext) for l in self.merged_lib.osg_dep_libs]
124       deps_lib_list = ["%s%s"%(l,self.osg_lib_ext) for l in self.merged_lib.libs]
125       return osg_lib_list + deps_lib_list
126    def getLibsStr(self):
127       return " ".join(["%s%s"%(self.libprefix,l) for l in self.getLibs()])
128    def getLibPath(self):
129       return self.merged_lib.libpath
130    def getLibPathStr(self):
131       return " ".join(["%s%s"%(self.libpathprefix,p) for p in self.merged_lib.libpath])
132    def getFrameworks(self):
133       return self.merged_lib.frameworks
134    def getFrameworkPath(self):
135       return self.merged_lib.frameworkpath
136  
137
Note: See TracBrowser for help on using the browser.