00001 """
00002 genCMake is simple script that is able to generate the CMakeLists.tst file required for a CMT package.
00003 usage:
00004 ---for a single package----
00005 cd <mypackage>/cmt
00006 python genCMake
00007
00008 ---for a complete project---
00009 cd <project>/XXXXSys/cmt
00010 cmt br "python genCMake > ../CMakeLists.txt"
00011 """
00012
00013 import os, pickle, copy
00014
00015
00016 package = os.getcwd().split(os.sep)[-2]
00017 project = os.popen('cmt show macro_value project').readlines()[0].strip()
00018 project_home = os.popen('cmt show macro_value %s_home' % project ).readlines()[0].strip()
00019 picklefile = '/tmp/%s/%s_libraries.pkl'% (os.environ['USER'], '%s')
00020 root = os.path.dirname(os.getcwd())+'/'
00021
00022
00023 ignorelibs = []
00024 def getlibs(library):
00025 libs = []
00026 linkopts = os.popen('cmt show macro_value %s_use_linkopts' % library).readlines()[0][:-1]
00027 for opt in linkopts.split():
00028 if opt[:2] == '-l':
00029 if opt[2:] not in ignorelibs and opt[2:] not in libs: libs.append(opt[2:])
00030 return libs
00031
00032 replacetable = [('boost_system', '${Boost_LIBRARIES}'),
00033 ('boost_filesystem', ''),
00034 ('boost_regex', '${Boost_regex_LIBRARY}'),
00035 ('boost_thread', ''),
00036 ('boost_program_options', ''),
00037 ('boost_date_time', '${Boost_date_time_LIBRARY}'),
00038 ('=Core', '${ROOT_LIBRARIES}'),
00039 ('=Cint', ''),
00040 ('=Reflex', ''),
00041 ('=dl', ''),
00042 ('=Tree', '${ROOT_Tree_LIBRARY}'),
00043 ('=RIO', ' ${ROOT_RIO_LIBRARY}'),
00044 ('=Matrix','${ROOT_Matrix_LIBRARY}'),
00045 ('=MathCore', '${ROOT_MathCore_LIBRARY}'),
00046 ('=MathMore', '${ROOT_MathMore_LIBRARY}'),
00047 ('=GenVector', '${ROOT_GenVector_LIBRARY}'),
00048 ('=Hist', '${ROOT_Hist_LIBRARY}'),
00049 ('=util', ''),
00050 ('=xerces-c', '${XercesC_LIBRARIES}'),
00051 ('=uuid', '${uuid_LIBRARIES}'),
00052 ('=pthread', ''),
00053 ('=gslcblas', '${GSL_LIBRARIES}'),
00054 ('=gsl', ''),
00055 ('=CLHEP-Cast-1.9.4.4', '${CLHEP_LIBRARIES}'),
00056 ('CLHEP', ''),
00057 ('=python2.5', '${Python_LIBRARIES}'),
00058 ('=fftw3', '${fftw_LIBRARIES}'),
00059 ('=HepPDT', '${HepPDT_LIBRARIES}'),
00060 ('=HepPID', '')
00061 ]
00062
00063 def prettylibs(libraries):
00064 libs = []
00065 for lib in libraries:
00066 for p,v in replacetable:
00067 if p[0] == '=' :
00068 if p[1:] == lib :
00069 lib = v
00070 break
00071 else :
00072 if p in lib :
00073 lib = v
00074 break
00075 if lib: libs.append(lib)
00076 return ' '.join(libs)
00077
00078
00079 projects = []
00080 gbl_libraries = {}
00081 loc_libraries = {}
00082 for l in os.popen('cmt show projects').readlines():
00083 p = l.split()[0]
00084 if p not in projects : projects.append(p)
00085 for p in projects:
00086
00087 if os.path.exists(picklefile % p):
00088 input = open(picklefile % p, 'rb')
00089 libs = pickle.load(input)
00090 gbl_libraries.update(libs)
00091 if p == project : loc_libraries.update(libs)
00092 input.close()
00093
00094 print """############################################################################
00095 # CMakeLists.txt file for building %s
00096 # @author Pere Mato, CERN (semi-automaticaly generated)
00097 ############################################################################""" % package
00098
00099
00100
00101 gaudipackages = ['GaudiPolicy', 'GaudiPython', 'GaudiPoolDb', 'RootHistCnv',
00102 'GaudiKernel', 'GaudiAlg', 'GaudiUtils', 'GaudiObjDesc',
00103 'GaudiSvc']
00104
00105
00106
00107
00108 outsidepackages = []
00109
00110 ignorepackages = ['GaudiPolicy', 'LCG_Interfaces/Reflex', 'LCG_Interfaces/oracle',
00111 'LCG_Interfaces/lfc','LCG_Interfaces/sqlite', 'LCG_Interfaces/mysql',
00112 'LCG_Interfaces/pyqt', 'Det/SQLDDDB', 'FieldMap']
00113
00114 dependentpackages = []
00115 lines = os.popen('cmt show uses').readlines()
00116
00117 for l in lines:
00118 if l[:4] == 'use ':
00119 items = l[4:].split()
00120 p = items[0]
00121 if items[2][0] != '(' :p = items[2]+'/'+p
00122 if items[2] == 'LCG_Interfaces' :
00123 if not 'no_auto_imports' in l and not p in ignorepackages:
00124 dependentpackages.append(p)
00125 continue
00126 if project_home in l : continue
00127 outsidepackages.append(p)
00128
00129 for l in lines:
00130 if l[:5] == '# use':
00131 p = l[5:].split()[0]
00132 if l[5:].split()[2][0] != '(': p = l[5:].split()[2]+'/'+p
00133 if p in outsidepackages :
00134 pass
00135 elif p in ignorepackages :
00136 pass
00137 elif p in dependentpackages :
00138 pass
00139 else :
00140 dependentpackages.append(p)
00141
00142 for p in dependentpackages:
00143 print 'GAUDI_USE_PACKAGE(%s)' % p.replace('LCG_Interfaces/','')
00144
00145
00146 dirs = os.popen('cmt show include_dirs').readlines()[0]
00147 for d in dirs.split():
00148 if root in d:
00149 print 'include_directories(${CMAKE_CURRENT_SOURCE_DIR}/%s)' % d.replace(root,'')
00150
00151
00152
00153 reflex_dictionaries = []
00154 install_python = False
00155 install_scripts = False
00156 install_headers = []
00157 install_joboptions = []
00158 libraries = {}
00159 executables = {}
00160 genconfig = []
00161 god_headers = []
00162 god_dictionaries = []
00163 god_customdicts = []
00164
00165 lines = os.popen('cmt show constituents').readlines()
00166 for l in lines:
00167 t = l.split()
00168 if t[0] == 'document' :
00169 if t[1] == 'install_python':
00170 if os.path.exists('python') : install_python = True
00171 elif t[1] == 'install_scripts':
00172 if os.path.exists('scripts') : install_scripts = True
00173 elif t[1] == 'data_installer'and t[2] == 'install_joboptions':
00174 for f in t[3:] :
00175 if f.find('prefix=') != 0 : install_joboptions.append(f.replace('../',''))
00176 elif t[1] == 'reflex_dictionary_generator' :
00177 name = t[2][:-3]
00178 sel = os.popen('cmt show macro_value %s_reflex_selection_file' % name).readlines()[0][:-1]
00179 if t[3][0] == '-' : hfile = t[4]
00180 else : hfile = t[3]
00181 reflex_dictionaries.append([name, hfile.replace(root,'').replace('../',''), sel.replace(root,'').replace('../','') ])
00182 elif t[1] == 'genconfig' :
00183 genconfig.append(t[2][:-4])
00184 elif t[1] == 'install_more_includes':
00185 dir1 = t[3].replace('more=','')
00186 dir2 = t[4].replace('offset=','')
00187 dirs = []
00188 if dir1 and os.path.exists('../'+dir1) : dirs.append(dir1)
00189 if dir2 and os.path.exists('../'+dir2) : dirs.append(dir2)
00190 if dirs : install_headers.append(dirs)
00191 elif t[1] == 'obj2doth' :
00192 god_headers.append([t[3].replace('../','')])
00193 elif t[1] == 'obj2dict' :
00194 god_dictionaries.append([t[3].replace('../','')])
00195 elif t[1] == 'customdict' :
00196 god_customdicts.append([t[2], t[3].replace('../','')])
00197 elif t[0] == 'library' :
00198 sources = []
00199 test = False
00200 for s in t[2:]:
00201 if s[0] != '-' : sources.append(s)
00202 if s == '-group=tests' : test = True
00203 libraries[t[1]] = [sources, getlibs(t[1]), test]
00204 elif t[0] == 'application' :
00205 sources = []
00206 test = False
00207 for s in t[2:]:
00208 if s[0] != '-' : sources.append(s)
00209 if s == '-group=tests' : test = True
00210 executables[t[1]] = [sources, getlibs(t[1]), test]
00211 else :
00212 print 'ERROR ---- constituents unknown', t[0]
00213
00214
00215 for k, l in libraries.items():
00216 if k[-4:] == 'Dict' : continue
00217 if k not in genconfig : loc_libraries[k] = copy.deepcopy(l)
00218
00219 for i, iv in libraries.items() + executables.items() :
00220 for j, jv in gbl_libraries.items() :
00221 if i is not j :
00222 if j in iv[1]:
00223 for k in jv[1]:
00224 if k in iv[1] : iv[1].remove(k)
00225
00226 if god_headers:
00227 print '\nINCLUDE(GaudiObjDesc)'
00228 print '\n#---GOD Headers-------------------------------------------------------------'
00229 dest = ''
00230 lines = os.popen('cmt show macro_value %sObj2Doth_GODflags' % package).readlines()
00231 if lines:
00232 option = lines[0].strip()
00233 if '-s' in option :
00234 dest = option[option.find('../')+3:]
00235 if dest[-1] == '/' : dest = dest[:-1]
00236 for h in god_headers :
00237 if dest :
00238 print 'GOD_BUILD_HEADERS(%s %s)'%(h[0],dest)
00239 else :
00240 print 'GOD_BUILD_HEADERS(%s)'%(h[0],)
00241
00242
00243 if libraries:
00244 print '\n#---Libraries---------------------------------------------------------------'
00245 for k,l in libraries.items():
00246 if k[-4:] == 'Dict' : continue
00247 if len(l[0]) > 1:
00248 sources = ' \n'.join([s.replace('../src/','') for s in l[0]])
00249 print 'SET( %s_srcs %s )' % (k, sources)
00250 srcs = '${%s_srcs}' % k
00251 else:
00252 srcs = l[0][0].replace('../src/','')
00253 if l[2] : print 'if(BUILD_TESTS)\n ',
00254 if k in genconfig :
00255 print 'GAUDI_COMPONENT_LIBRARY(%s %s LIBRARIES %s)'%(k, srcs, prettylibs(l[1]))
00256 else :
00257 print 'GAUDI_LINKER_LIBRARY(%s %s LIBRARIES %s)'%(k, srcs, prettylibs(l[1]))
00258 if l[2] : print 'endif()'
00259
00260 if executables:
00261 print '\n#---Executables-------------------------------------------------------------'
00262 for k,l in executables.items():
00263 if len(l[0]) > 1:
00264 sources = ' \n'.join([s.replace('../src/','') for s in l[0]])
00265 print 'SET( %s_srcs %s )' % (k, sources)
00266 srcs = '${%s_srcs}' % k
00267 else:
00268 srcs = l[0][0].replace('../src/','')
00269 if l[2] :
00270 print 'GAUDI_UNIT_TEST(%s %s LIBRARIES %s)'%(k, srcs, prettylibs(l[1]))
00271 else :
00272 print 'GAUDI_EXECUTABLE(%s %s LIBRARIES %s)'%(k, srcs, prettylibs(l[1]))
00273
00274
00275 if god_customdicts or god_dictionaries:
00276 print '\n#---GOD Dictionary----------------------------------------------------------'
00277 dest = ''
00278 lines = os.popen('cmt show macro_value %sObj2Dict_GODflags' % package).readlines()
00279 if lines:
00280 option = lines[0].strip()
00281 if '-s' in option :
00282 dest = option[option.find('../')+3:]
00283 if dest[-1] == '/' : dest = dest[:-1]
00284 for d in god_customdicts :
00285 print 'GOD_CUSTOM_DICTIONARY(%s %s)'%(d[1], 'xml/lcgdict/lcg_selection.xml')
00286 for d in god_dictionaries :
00287 if dest :
00288 print 'GOD_BUILD_DICTIONARY(%s %s)'%(d[0], dest)
00289 else :
00290 print 'GOD_BUILD_DICTIONARY(%s)'%(d[0],)
00291 libs = []
00292 for i in libraries[package+'Dict'][1]:
00293 if i != package : libs.append(i)
00294 if libs :
00295 print 'target_link_libraries(%s %s)'%(package+'Dict',prettylibs(libs))
00296
00297
00298 if not god_dictionaries and reflex_dictionaries:
00299 print '\n#---Dictionaries------------------------------------------------------------'
00300 for d in reflex_dictionaries:
00301 libs = ''
00302 for k,l in libraries.items() :
00303 if k == d[0]+'Dict' : libs = prettylibs(l[1])
00304 print 'REFLEX_BUILD_DICTIONARY(%s %s %s LIBRARIES %s)'% (d[0],d[1],d[2], libs)
00305
00306 print '\n#---Installation------------------------------------------------------------'
00307
00308 for lst in install_headers:
00309 print 'GAUDI_INSTALL_HEADERS(%s)' % ' '.join(lst)
00310
00311 if install_python:
00312 print 'GAUDI_INSTALL_PYTHON_MODULES()'
00313
00314 if install_scripts:
00315 print 'GAUDI_INSTALL_SCRIPTS()'
00316
00317 if install_joboptions:
00318 print 'GAUDI_INSTALL_JOBOPTIONS(%s)' % ' '.join(install_joboptions)
00319
00320
00321 output = open(picklefile % project, 'wb')
00322 pickle.dump(loc_libraries, output)
00323 output.close()
00324
00325