File indexing completed on 2024-03-24 16:16:32

0001 #!env python
0002 #     Copyright 2008 Simon Edwards <simon@simonzone.com>
0003 #
0004 # This program is free software; you can redistribute it and/or modify
0005 # it under the terms of the GNU General Public License as published by
0006 # the Free Software Foundation; either version 2 of the License, or
0007 # (at your option) any later version.
0008 #
0009 # This program is distributed in the hope that it will be useful,
0010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012 # GNU General Public License for more details.
0013 #
0014 # You should have received a copy of the GNU General Public License
0015 # along with this program; if not, write to the
0016 # Free Software Foundation, Inc.,
0017 # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018 
0019 import re
0020 import os.path
0021 import glob
0022 import kbindinggenerator.cmakeparser as cmakeparser
0023 
0024 def ExtractInstallFiles(filename=None,input=None,variables=None):
0025     if variables is None:
0026         variables = {}
0027     else:
0028         variables = variables.copy()
0029 
0030     install_list = []
0031 
0032     if filename is not None:
0033         variables['cmake_current_source_dir'] = [os.path.dirname(filename)]
0034 
0035     ExtractInstallFilesWithContext(variables, install_list, filename,input)
0036 #    print(repr(variables))
0037 #    print(repr(install_list))
0038     return install_list
0039 
0040 def ExtractInstallFilesWithContext(variables, install_list, filename=None, input=None, fileprefix=""):
0041     inputstring = ""
0042     currentdir = ""
0043     if input:
0044         inputstring = input
0045     elif filename:
0046         currentdir = os.path.dirname(filename)
0047         fhandle = open(filename)
0048         inputstring=  fhandle.read()
0049         fhandle.close()
0050     parser = cmakeparser.CMakeParser()
0051     command_list = parser.parse(inputstring, filename)
0052     include_dirs = []
0053 
0054     for commandobject in command_list:
0055         command = commandobject.command().lower()
0056         args = [arg.value() for arg in commandobject.arguments()]
0057         if command=="set":
0058             variables[args[0].lower()] = ExpandArgs(variables, args[1:], filename)
0059 
0060         elif command=="install":
0061             install_args = ExpandArgs(variables, args, filename)
0062 
0063             for arg in install_args:
0064                 if arg.endswith('.h'):
0065                     for basepath in [currentdir, fileprefix] + include_dirs:
0066                         fullpath = os.path.join(basepath, arg)
0067                         # print(fullpath)
0068                         if os.path.exists(fullpath):
0069                             install_list.append(fullpath)
0070                             break
0071                         else:
0072                             fullpath = os.path.join(currentdir, basepath, arg)
0073                             if os.path.exists(fullpath):
0074                                 install_list.append(fullpath)
0075                                 break
0076                     else:
0077                         print("Unable to find header file " + arg)
0078 
0079         elif command=="include":
0080             if filename is not None:
0081                 command_args = ExpandArgs(variables, args, filename)
0082                 
0083                 this_dir = os.path.dirname(filename)
0084                 for arg in command_args:
0085                     if len(arg.strip())!=0:
0086                         include_filename = os.path.join(this_dir,arg)
0087                         if os.path.exists(include_filename):
0088                             ExtractInstallFilesWithContext(variables, install_list, include_filename)
0089 
0090         elif command=="add_subdirectory":
0091             if filename is not None:
0092                 command_args = ExpandArgs(variables, args, filename)
0093 
0094                 this_dir = os.path.dirname(filename)
0095                 for arg in command_args:
0096                     if len(arg.strip())!=0:
0097                         include_filename = os.path.join(this_dir,arg,"CMakeLists.txt")
0098                         if os.path.exists(include_filename):
0099                             ExtractInstallFilesWithContext(variables, install_list, include_filename, fileprefix=os.path.join(fileprefix,arg))
0100 
0101         elif command=="file":
0102             # This is just a basic cmake FILE() implementation. It just does GLOB.
0103             command_args = ExpandArgs(variables, args, filename)
0104             varname = None
0105             result = None
0106             try:
0107                 it = iter(command_args)
0108                 arg = it.__next__()
0109                 if arg.lower()=='glob' and filename is not None:
0110                     arg = it.next()
0111                     varname = arg
0112                     arg = it.next()
0113 
0114                     relative_dir = os.path.dirname(filename)
0115                     if arg.lower()=='relative':
0116                         arg = it.next()
0117                         relative_dir = arg
0118                         arg = it.next()
0119                     if not relative_dir.endswith('/'):
0120                         relative_dir += '/'
0121                         
0122                     result = []
0123                     current_dir = variables['cmake_current_source_dir'][0]
0124                     while True:
0125                         for x in glob.iglob(os.path.join(current_dir, arg)):
0126                             if x.startswith(relative_dir):
0127                                 x = x[len(relative_dir):]
0128                             result.append(x)
0129                         arg = it.next()
0130 
0131             except StopIteration:
0132                 if varname is not None and result is not None:
0133                     variables[varname.lower()] = result
0134 
0135         elif command=="ecm_generate_headers":
0136             header_args = ExpandArgs(variables, args, filename)
0137             # print("ecm_generate_headers:"+repr(header_args))
0138 
0139             prefix=""
0140             if "RELATIVE" in header_args:
0141                 prefix = header_args[header_args.index("RELATIVE")+1]
0142 
0143             for item in header_args:
0144                 if item == "REQUIRED_HEADERS" or item == "RELATIVE":
0145                     break
0146                 headername = os.path.join(currentdir, prefix, item.lower() + ".h")
0147                 if os.path.exists(headername):
0148                     install_list.append(headername)
0149 
0150         elif command == "target_include_directories":
0151             include_args = ExpandArgs(variables, args, filename)
0152             if "PUBLIC" in include_args:
0153                 for item in include_args[include_args.index("PUBLIC")+1:]:
0154                     include_dirs.append(item)
0155                 #print("include dirs:",repr(include_dirs))
0156 
0157 def ExpandArgs(variables, args, filename=None):
0158     rex  = re.compile(r'(\$\{[^\}]+\})')
0159     fixed_args = []
0160     for arg in args:
0161         fixed_parts = []
0162 
0163         if arg.startswith("$<BUILD_INTERFACE:"):
0164             arg = arg[len("$<BUILD_INTERFACE:"): -1]
0165 
0166         parts = rex.split(arg)
0167         for part in parts:
0168             if part.startswith("${"):
0169                 name = part[2:-1].lower()
0170                 if name in variables:
0171                     value = variables[name]
0172                     if len(value)==1:
0173                         fixed_parts.append(variables[name][0])
0174                     else:
0175                         fixed_args.extend(value)
0176                 else:
0177                     print("Undefined cmake variable '" + name + "' in " + filename)
0178             else:
0179                 fixed_parts.append(part)
0180         fixed_args.append(''.join(fixed_parts))
0181         
0182     return fixed_args
0183     
0184 def __FetchCommands(lexer):
0185     topmode = True
0186     command_list = []
0187     command = None
0188     args = []
0189     
0190     tok = lexer.token()
0191     while 1:
0192         if not tok:
0193             if command:
0194                 command_list.append( (command,args) )
0195             break   # No more input
0196         if topmode:
0197             if tok.type=="COMMAND":
0198                 command = tok.value
0199                 topmode = False
0200             else:
0201                 print("Fail")
0202                 # Fail
0203                 
0204             tok = lexer.token()
0205         else:
0206             # Grab arguments
0207             if tok.type=="COMMAND":
0208                 if command:
0209                     command_list.append( (command,args) )
0210                 command = None
0211                 args = []
0212             
0213                 topmode = True
0214                 continue
0215             args.append(tok.value)
0216             tok = lexer.token()
0217     return command_list
0218         
0219 if __name__=="__main__":
0220     #print("Testing")
0221     #lexer = cmakelexer.CMakeLexer()
0222 
0223     print(ExtractInstallFiles(filename="/home/sbe/devel/svn/kde/trunk/KDE/kdeedu/marble/src/lib/CMakeLists.txt"))
0224 
0225 def foo():
0226     ExtractInstallFiles(input="""
0227 find_package(KDE4 REQUIRED)
0228 include (KDE4Defaults)
0229 
0230 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${KDEBASE_WORKSPACE_SOURCE_DIR}/libs ${CMAKE_CURRENT_SOURCE_DIR}/.. ${KDE4_INCLUDES} ${OPENGL_INCLUDE_DIR})
0231 
0232 add_subdirectory(tests)
0233 add_definitions(-DKDE_DEFAULT_DEBUG_AREA=1209)
0234 
0235 ########### next target ###############
0236 
0237 set(plasmagik_SRCS
0238     packagemetadata.cpp
0239     packagestructure.cpp
0240     package.cpp
0241     )
0242 
0243 set(plasma_LIB_SRCS
0244     ${plasmagik_SRCS}
0245     abstractrunner.cpp
0246     animationdriver.cpp
0247     animator.cpp
0248     applet.cpp
0249     appletbrowser.cpp
0250     appletbrowser/customdragtreeview.cpp
0251     appletbrowser/kcategorizeditemsview.cpp
0252     appletbrowser/kcategorizeditemsviewdelegate.cpp
0253     appletbrowser/kcategorizeditemsviewmodels.cpp
0254     appletbrowser/openwidgetassistant.cpp
0255     appletbrowser/plasmaappletitemmodel.cpp
0256     configxml.cpp
0257     containment.cpp
0258     corona.cpp
0259     datacontainer.cpp
0260     dataengine.cpp
0261     dataenginemanager.cpp
0262     delegate.cpp
0263     dialog.cpp
0264     extender.cpp
0265     extenderitem.cpp
0266     paintutils.cpp
0267     panelsvg.cpp
0268     plasma.cpp
0269     popupapplet.cpp
0270     private/applethandle.cpp
0271     private/datacontainer_p.cpp
0272     private/desktoptoolbox.cpp
0273     private/nativetabbar.cpp
0274     private/packages.cpp
0275     private/paneltoolbox.cpp
0276     private/toolbox.cpp
0277     private/tooltip.cpp
0278     querymatch.cpp
0279     runnercontext.cpp
0280     runnermanager.cpp
0281     scripting/appletscript.cpp
0282     scripting/dataenginescript.cpp
0283     scripting/runnerscript.cpp
0284     scripting/scriptengine.cpp
0285     service.cpp
0286     servicejob.cpp
0287     svg.cpp
0288     theme.cpp
0289     tooltipmanager.cpp
0290     uiloader.cpp
0291     version.cpp
0292     view.cpp
0293     wallpaper.cpp
0294     widgets/checkbox.cpp
0295     widgets/combobox.cpp
0296     widgets/flash.cpp
0297     widgets/frame.cpp
0298     widgets/groupbox.cpp
0299     widgets/icon.cpp
0300     widgets/label.cpp
0301     widgets/lineedit.cpp
0302     widgets/meter.cpp
0303     widgets/pushbutton.cpp
0304     widgets/radiobutton.cpp
0305     widgets/signalplotter.cpp
0306     widgets/slider.cpp
0307     widgets/tabbar.cpp
0308     widgets/textedit.cpp
0309     widgets/webcontent.cpp
0310 )
0311 
0312 kde4_add_ui_files (
0313     plasma_LIB_SRCS
0314     appletbrowser/kcategorizeditemsviewbase.ui
0315 )
0316 
0317 if(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
0318 MESSAGE(STATUS "Adding support for OpenGL applets to libplasma")
0319 set(plasma_LIB_SRCS
0320     ${plasma_LIB_SRCS}
0321     glapplet.cpp)
0322 endif(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
0323 
0324 kde4_add_library(plasma SHARED ${plasma_LIB_SRCS})
0325 
0326 target_link_libraries(plasma ${KDE4_KIO_LIBS} ${KDE4_KFILE_LIBS} ${KDE4_KNEWSTUFF2_LIBS}
0327                              ${QT_QTUITOOLS_LIBRARY} ${QT_QTWEBKIT_LIBRARY}
0328                              ${KDE4_THREADWEAVER_LIBRARIES} ${KDE4_SOLID_LIBS} ${X11_LIBRARIES})
0329 
0330 if(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
0331     target_link_libraries(plasma ${QT_QTOPENGL_LIBRARY} ${OPENGL_gl_LIBRARY})
0332 endif(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
0333 
0334 set_target_properties(plasma PROPERTIES
0335                              VERSION 3.0.0
0336                              SOVERSION 3
0337                              ${KDE4_DISABLE_PROPERTY_}LINK_INTERFACE_LIBRARIES  "${KDE4_KDEUI_LIBS}"
0338                       )
0339 
0340 install(TARGETS plasma ${INSTALL_TARGETS_DEFAULT_ARGS})
0341 
0342 
0343 ########### install files ###############
0344 
0345 set(plasmagik_HEADERS
0346     packagemetadata.h
0347     packagestructure.h
0348     package.h
0349     )
0350 
0351 install(FILES ${plasmagik_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/ COMPONENT Devel)
0352 
0353 set(plasma_LIB_INCLUDES
0354     abstractrunner.h
0355     animationdriver.h
0356     animator.h
0357     applet.h
0358     appletbrowser.h
0359     configxml.h
0360     containment.h
0361     corona.h
0362     datacontainer.h
0363     dataengine.h
0364     dataenginemanager.h
0365     delegate.h
0366     dialog.h
0367     extender.h
0368     extenderitem.h
0369     paintutils.h
0370     panelsvg.h
0371     plasma.h
0372     plasma_export.h
0373     popupapplet.h
0374     querymatch.h
0375     runnercontext.h
0376     runnermanager.h
0377     service.h
0378     servicejob.h
0379     svg.h
0380     theme.h
0381     tooltipmanager.h
0382     uiloader.h
0383     tooltipmanager.h
0384     version.h
0385     view.h
0386     wallpaper.h)
0387 
0388 if(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
0389 set(plasma_LIB_INCLUDES
0390     ${plasma_LIB_INCLUDES}
0391     glapplet.h)
0392 endif(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
0393 
0394 install(FILES
0395         ${plasma_LIB_INCLUDES}
0396         DESTINATION ${INCLUDE_INSTALL_DIR}/plasma COMPONENT Devel)
0397 
0398 install(FILES
0399     widgets/checkbox.h
0400     widgets/combobox.h
0401     widgets/flash.h
0402     widgets/frame.h
0403     widgets/groupbox.h
0404     widgets/icon.h
0405     widgets/label.h
0406     widgets/lineedit.h
0407     widgets/meter.h
0408     widgets/pushbutton.h
0409     widgets/radiobutton.h
0410     widgets/signalplotter.h
0411     widgets/slider.h
0412     widgets/tabbar.h
0413     widgets/textedit.h
0414     widgets/webcontent.h
0415     DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/widgets COMPONENT Devel)
0416 
0417 install(FILES
0418     scripting/appletscript.h
0419     scripting/dataenginescript.h
0420     scripting/runnerscript.h
0421     scripting/scriptengine.h
0422     DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/scripting COMPONENT Devel)
0423 
0424 
0425 install(FILES
0426 includes/AbstractRunner
0427 includes/AnimationDriver
0428 includes/Animator
0429 includes/Applet
0430 includes/AppletBrowser
0431 includes/AppletScript
0432 includes/CheckBox
0433 includes/ComboBox
0434 includes/ConfigXml
0435 includes/Containment
0436 includes/Corona
0437 includes/DataContainer
0438 includes/DataEngine
0439 includes/DataEngineManager
0440 includes/DataEngineScript
0441 includes/Delegate
0442 includes/Dialog
0443 includes/Extender
0444 includes/ExtenderItem
0445 includes/Flash
0446 includes/GroupBox
0447 includes/Icon
0448 includes/Label
0449 includes/LineEdit
0450 includes/Meter
0451 includes/Package
0452 includes/PackageMetadata
0453 includes/PackageStructure
0454 includes/PaintUtils
0455 includes/PanelSvg
0456 includes/Plasma
0457 includes/PopupApplet
0458 includes/PushButton
0459 includes/QueryMatch
0460 includes/RadioButton
0461 includes/RunnerContext
0462 includes/RunnerManager
0463 includes/RunnerScript
0464 includes/ScriptEngine
0465 includes/Service
0466 includes/ServiceJob
0467 includes/SignalPlotter
0468 includes/Slider
0469 includes/Svg
0470 includes/TabBar
0471 includes/TextEdit
0472 includes/ToolTipManager
0473 includes/Theme
0474 includes/UiLoader
0475 includes/View
0476 includes/Version
0477 includes/Wallpaper
0478 includes/WebContent
0479 DESTINATION ${INCLUDE_INSTALL_DIR}/KDE/Plasma COMPONENT Devel)
0480 
0481 if(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
0482    install(FILES
0483       includes/GLApplet
0484       DESTINATION ${INCLUDE_INSTALL_DIR}/KDE/Plasma COMPONENT Devel)
0485 endif(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
0486 
0487 install(FILES
0488    servicetypes/plasma-animator.desktop
0489    servicetypes/plasma-applet.desktop
0490    servicetypes/plasma-containment.desktop
0491    servicetypes/plasma-dataengine.desktop
0492    servicetypes/plasma-packagestructure.desktop
0493    servicetypes/plasma-runner.desktop
0494    servicetypes/plasma-scriptengine.desktop
0495    servicetypes/plasma-wallpaper.desktop
0496    DESTINATION ${SERVICETYPES_INSTALL_DIR})
0497 
0498 install(FILES scripting/plasmoids.knsrc DESTINATION  ${CONFIG_INSTALL_DIR})   
0499 """)
0500     # Tokenize
0501     
0502     #while 1:
0503     #    tok = lexer.token()
0504     #    if not tok: break      # No more input
0505     #    print tok
0506     
0507     #while 1:
0508     #    tok = cmakelexer.lex.token()
0509     #    if not tok: break      # No more input
0510     #    print tok
0511