Example #1
0
def env2MSVS8(env, projname, path, srcs, variant):
    # Create .proj file
    proj_file = open(os.path.join(path, projname + ".vcproj"), "w")

    project = XMLGenerator(proj_file)

    GUID = "{28540DAA-6718-4DE8-8D55-468836F0BE71}"
    project.startElement(
        "VisualStudioProject",
        {
            "ProjectType": "Visual C++",
            "Version": "8,00",
            "Name": projname,
            "ProjectGUID": GUID,
            "SccProjectName": "",
            "SccLocalPath": "",
        },
    )

    project.startElement("Platforms", None)
    project.element("Platform", {"Name": "Win32"})

    project.endElement("Platforms")

    project.startElement("Configurations", {})

    project.startElement(
        "Configuration",
        {
            "Name": variant + "|Win32",
            "OutputDirectory": ".\\" + variant,
            "IntermediateDirectory": ".\\" + variant,
            "ConfigurationType": "1",
            "UseOfMFC": "0",
            "CharacterSet": "2",
        },
    )

    #
    # Compiler
    #

    ppdefs = ""
    for p in env["CPPDEFINES"]:
        ppdefs = ppdefs + p + ";"

    # TODO: parse flags and add correct attributes in compiler tool.
    ccflags = env["CCFLAGS"]

    project.element(
        "Tool",
        {
            "Name": "VCCLCompilerTool",
            "PreprocessorDefinitions": ppdefs,
            "ObjectFile": ".\\" + variant + "/",
            "ProgramDataBaseFileName": ".\\" + variant + "/",
            "SuppressStartupBanner": "TRUE",
            "AdditionalOptions": str(ccflags),
            "Optimization": "0",
            "DebugInformationFormat": "4",
        },
    )

    #
    # Linker
    #
    libs = ""
    for lib in env["LIBS"]:
        libs += str(env["LIBPREFIX"] + lib + env["LIBSUFFIX"]) + " "

    libsdir = ""
    for d in env["LIBPATH"]:
        libsdir = libsdir + d + ";"

    project.element(
        "Tool",
        {
            "Name": "VCLinkerTool",
            "AdditionalDependencies": libs,
            "SuppressStartupBanner": "TRUE",
            "OutputFile": ".\\" + variant + "/" + projname + ".exe",
            "AdditionalLibraryDirectories": libsdir,
            "GenerateDebugInformation": "TRUE",
        },
    )

    project.endElement("Configuration")
    project.endElement("Configurations")

    project.startElement("Files")

    project.startElement("Filter", {"Name": "Source Files", "Filter": "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"})

    srcs.sort()
    for m in srcs:
        module = m[0]
        src_list = m[1]

        project.startElement("Filter", {"Name": module, "Filter": ""})
        for s in src_list:
            incpaths = ""
            for path in s.incpaths:
                incpaths = incpaths + path + ";"

            ppdefs = ""
            for ppdef in s.ppdefs:
                ppdefs = ppdefs + ppdef + ";"

            project.startElement("File", {"RelativePath": s.filepath})
            project.startElement("FileConfiguration", {"Name": variant + "|Win32"})
            project.element(
                "Tool",
                {
                    "Name": "VCCLCompilerTool",
                    "PreprocessorDefinitions": ppdefs,
                    "AdditionalIncludeDirectories": incpaths,
                },
            )
            project.endElement("FileConfiguration")
            project.endElement("File")

        project.endElement("Filter")

    project.endElement("Filter")

    project.endElement("Files")

    project.endElement("VisualStudioProject")

    proj_file.close()
Example #2
0
def make_libvcproj8(
    projectName,
    cflags,
    prepDefs,
    codeModules,
    outLib,
    debug,
    do_tests,
    incPaths,
    vcprojPath,
    platform="Win32",
    fileTitle=None,
    configType="lib",
    additionalDependencies=None,
    additionalLibraryDirectories=None,
):

    import os.path

    vcprojFilePath = str()
    vcprojPath = os.path.abspath(vcprojPath)
    if fileTitle == None:
        fileTitle = projectName

    vcprojFilePath = os.path.join(vcprojPath, fileTitle + ".vcproj")
    vcprojFile = open(vcprojFilePath, "w")
    project = XMLGenerator(vcprojFile)

    # GUID            = str(pywintypes.CreateGuid())
    GUID = "".join(["{", str(uuid.uuid3(uuid.NAMESPACE_URL, "make_libvcproj8" + projectName)).upper(), "}"])

    #
    # Determine exe/lib
    #
    if configType == "lib":
        configurationTypeNbr = "4"
    elif configType == "dll":
        configurationTypeNbr = "2"
    elif configType == "exe":
        configurationTypeNbr = "1"
    else:
        print "Erroneous config type. Using 'lib'"
        configType = "lib"
        configurationTypeNbr = "4"

    #
    # Determine debug/release
    #
    variant = str()
    if debug:
        variant = "Debug"
    else:
        variant = "Release"

    #
    # Determine DebugInformationFormat
    #
    debugInformationFormat = str()
    debugInformationFormat = "0"

    #
    # Prepare proprocessor definitions.
    #
    if type(prepDefs) == list:
        tmp = str()
        for d in prepDefs:
            tmp += d + ";"
        prepDefs = tmp

    project.startElement(
        "VisualStudioProject",
        {
            "ProjectType": "Visual C++",
            "Version": "8,00",
            "Name": projectName,
            "RootNamespace": projectName,
            "ProjectGUID": GUID,
            "SccProjectName": "",
            "SccLocalPath": "",
        },
    )

    project.startElement("Platforms", {})

    project.element("Platform", {"Name": platform})
    project.endElement("Platforms")

    project.startElement("Configurations", {})
    project.startElement(
        "Configuration",
        {
            "Name": variant + "|" + platform,
            "OutputDirectory": "".join([".\\", variant, "\\", projectName]),
            "IntermediateDirectory": "".join([".\\", variant, "\\", projectName]),
            "ConfigurationType": configurationTypeNbr,
            "UseOfMFC": "0",
            "CharacterSet": "1",
        },
    )

    #
    # Compiler
    #

    if type(incPaths) != list:
        incPaths = incPaths.split(";")

    incPaths = [relntpath(path, vcprojPath) for path in incPaths]

    incPaths = ";".join(incPaths)

    compilerTool = {
        "Name": "VCCLCompilerTool",
        "PreprocessorDefinitions": prepDefs,
        "ObjectFile": "".join([".\\", variant, "\\", projectName, "/"]),
        "ProgramDataBaseFileName": "".join([".\\", variant, "\\", projectName, "/"]),
        "SuppressStartupBanner": "TRUE",
        "AdditionalIncludeDirectories": incPaths,
        "Optimization": "0",
        "DebugInformationFormat": debugInformationFormat,
    }

    # Parse flags and add correct attributes in compiler tool.
    # make a duplicate of the list
    mycflags = cflags[:]
    work_cflags = cflags[:]
    if type(mycflags) != list:
        mycflags = mycflags.split(" ")

    if type(work_cflags) != list:
        work_cflags = work_cflags.split(" ")

    vcproj_opts_map = {
        "/Z7": ("DebugInformationFormat", "1"),
        "/Zd": ("DebugInformationFormat", "2"),
        "/Zi": ("DebugInformationFormat", "3"),
        "/ZI": ("DebugInformationFormat", "4"),
        "/W4": ("WarningLevel", "4"),
        "/W3": ("WarningLevel", "3"),
        "/W2": ("WarningLevel", "2"),
        "/W1": ("WarningLevel", "1"),
        "/W0": ("WarningLevel", "0"),
        "/Od": ("Optimization", "0"),
        "/O1": ("Optimization", "1"),
        "/O2": ("Optimization", "2"),
        "/Ox": ("Optimization", "3"),
        "/MT": ("RuntimeLibrary", "0"),
        "/MTd": ("RuntimeLibrary", "1"),
        "/MD": ("RuntimeLibrary", "2"),
        "/MDd": ("RuntimeLibrary", "3"),
        "/MLd": ("RuntimeLibrary", "5"),
        "/ML": ("RuntimeLibrary", "4"),
        "/GZ": ("BasicRuntimeChecks", "1"),
        "/RTCsu": ("BasicRuntimeChecks", "3"),
        "/RTCs": ("BasicRuntimeChecks", "1"),
        "/RTCu": ("BasicRuntimeChecks", "2"),
        "/RTC1": ("BasicRuntimeChecks", "3"),
        "/arch:SSE2": ("EnableEnhancedInstructionSet", "2"),
        "/arch:SSE": ("EnableEnhancedInstructionSet", "1"),
        "/Ot": ("FavorSizeOrSpeed", "1"),
        "/Os": ("FavorSizeOrSpeed", "2"),
        "/TC": ("CompileAs", "1"),
        "/TP": ("CompileAs", "2"),
        "/GB": ("OptimizeForProcessor", "0"),
        "/G5": ("OptimizeForProcessor", "1"),
        "/G6": ("OptimizeForProcessor", "2"),
        "/G7": ("OptimizeForProcessor", "3"),
        "/Ob0": ("InlineFunctionExpansion", "0"),
        "/Ob1": ("InlineFunctionExpansion", "1"),
        "/Ob2": ("InlineFunctionExpansion", "2"),
        "/Zp1": ("StructMemberAlignment", "1"),
        "/Zp2": ("StructMemberAlignment", "2"),
        "/Zp4": ("StructMemberAlignment", "3"),
        "/Zp8": ("StructMemberAlignment", "4"),
        "/Zp16": ("StructMemberAlignment", "5"),
    }

    for opt in work_cflags:
        if vcproj_opts_map.has_key(opt):
            (optionname, numvalue) = vcproj_opts_map[opt]
            compilerTool[optionname] = numvalue
            mycflags.remove(opt)

    # Write the rest of the options as AdditionalOptions
    mycflags = " ".join(mycflags)
    compilerTool["AdditionalOptions"] = mycflags

    # Write compilerTool to project
    project.element("Tool", compilerTool)

    #
    # Archiver
    #

    if configType == "lib":
        project.element("Tool", {"Name": "VCLibrarianTool", "OutputFile": "$(OutDir)/" + outLib})
    elif configType == "exe" or configType == "dll":
        additionalDependencies = " ".join(map(ntpath.basename, additionalDependencies))
        additionalLibraryDirectories = ";".join(additionalLibraryDirectories)
        project.element(
            "Tool",
            {
                "Name": "VCLinkerTool",
                "GenerateDebugInformation": "TRUE",
                "TargetMachine": "1",
                "AdditionalDependencies": additionalDependencies,
                "AdditionalLibraryDirectories": additionalLibraryDirectories,
            },
        )
        project.element("Tool", {"Name": "VCManifestTool"})
        project.element("Tool", {"Name": "VCAppVerifierTool"})
        project.element("Tool", {"Name": "VCWebDeploymentTool"})

    project.endElement("Configuration")
    project.endElement("Configurations")

    # Start module root folder.
    project.startElement("Files")
    project.startElement("Filter", {"Name": "Modules", "Filter": ""})

    # NOTE:
    # codeModules = listof dictionaries: { MODNAME: string, SOURCES: list(paths), PRIVHDRS: list(paths), PUBHDRS: list(paths), PRIVHDRDIR: string, DEPHDRDIRS: set(paths), TESTSOURCES }
    for mod in codeModules:

        # Start module folder (public header goes here also)
        project.startElement("Filter", {"Name": mod["MODNAME"], "Filter": ""})

        # Start source file folder
        project.startElement("Filter", {"Name": "src", "Filter": ""})
        # Add all source files.
        for srcFile in mod["SOURCES"]:
            project.startElement("File", {"RelativePath": relntpath(srcFile, vcprojPath)})
            project.startElement("FileConfiguration", {"Name": "".join([variant, "|", platform])})
            additionalIncludes = relntpath(mod["PRIVHDRDIR"], vcprojPath)
            for hdrdir in mod["DEPHDRDIRS"]:
                additionalIncludes = additionalIncludes + ";" + relntpath(hdrdir, vcprojPath)
            project.element("Tool", {"Name": "VCCLCompilerTool", "AdditionalIncludeDirectories": additionalIncludes})
            project.endElement("FileConfiguration")
            project.endElement("File")
            # project.startElement ('FileConfiguration', {'Name':variant+'|Win32'})
        # End source file folder
        project.endElement("Filter")

        if do_tests:
            # Add test folder.
            project.startElement("Filter", {"Name": "tests", "Filter": ""})
            for src in mod["TESTSOURCES"]:
                # project.characters('testsource:%s vcprojPath: %s'%(src, vcprojPath))
                project.startElement("File", {"RelativePath": relntpath(src, vcprojPath)})
                project.startElement("FileConfiguration", {"Name": "".join([variant, "|", platform])})
                additionalTestIncludes = relntpath(mod["PRIVHDRDIR"], vcprojPath)
                for hdrdir in mod["DEPHDRDIRS"]:
                    additionalTestIncludes = additionalTestIncludes + ";" + relntpath(hdrdir, vcprojPath)
                project.element(
                    "Tool", {"Name": "VCCLCompilerTool", "AdditionalIncludeDirectories": additionalTestIncludes}
                )
                project.endElement("FileConfiguration")
                project.endElement("File")
            for hdr in mod["TESTHDRS"]:
                project.element("File", {"RelativePath": relntpath(hdr, vcprojPath)})

            project.endElement("Filter")

        # Start private include folder
        project.startElement("Filter", {"Name": "inc", "Filter": ""})
        # Add all private headers.
        for hdr in mod["PRIVHDRS"]:

            project.element("File", {"RelativePath": relntpath(hdr, vcprojPath)})

        # End private include folder
        project.endElement("Filter")

        # Add public headers to root.
        for hdr in mod["PUBHDRS"]:
            # project.characters('header:%s vcprojPath: %s'%(hdr, vcprojPath))
            project.startElement("File", {"RelativePath": relntpath(hdr, vcprojPath)})
            project.endElement("File")

        # End module folder
        project.endElement("Filter")

    # End module root folder
    project.endElement("Filter")

    project.endElement("Files")

    project.endElement("VisualStudioProject")

    vcprojFile.close()

    return GUID
Example #3
0
def make_libvcproj8( projectName, cflags, prepDefs, codeModules, outLib,
                    debug, do_tests,  incPaths, vcprojPath, platform = 'Win32',
                    fileTitle = None, configType = 'lib',
                     additionalDependencies = None,
                     additionalLibraryDirectories = None):


    import os.path
    vcprojFilePath = str()
    vcprojPath = os.path.abspath(vcprojPath)
    if fileTitle == None:
        fileTitle = projectName

    vcprojFilePath  = os.path.join( vcprojPath, fileTitle + ".vcproj" )
    vcprojFile      = open( vcprojFilePath, 'w')
    project         = XMLGenerator( vcprojFile )

    #GUID            = str(pywintypes.CreateGuid())
    GUID            = "".join(["{",str(uuid.uuid3(uuid.NAMESPACE_URL,"make_libvcproj8" + projectName)).upper(),"}"])

    #
    # Determine exe/lib
    #
    if configType == 'lib':
        configurationTypeNbr = '4'
    elif configType == 'exe':
        configurationTypeNbr = '1'
    else:
        print "Erroneous config type. Using 'lib'"
        configType = 'lib'
        configurationTypeNbr = '4'

    #
    # Determine debug/release
    #
    variant = str()
    if debug:
        variant = 'Debug'
    else:
        variant = 'Release'

    #
    # Determine DebugInformationFormat
    #
    debugInformationFormat = str()
    if platform == 'Win32':
        debugInformationFormat = '4'
    else:
        debugInformationFormat = '3'

    #
    # Prepare proprocessor definitions.
    #
    if type(prepDefs) == list:
        tmp = str()
        for d in prepDefs:
            tmp += d + ';'
        prepDefs = tmp


    project.startElement ('VisualStudioProject', {'ProjectType':'Visual C++',
                                                  'Version':'8,00',
                                                 'Name':projectName,
                                                 'RootNamespace':projectName,
                                                 'ProjectGUID':GUID,
                                                 'SccProjectName':'',
                                                  'SccLocalPath':''})

    project.startElement ('Platforms', {})

    project.element ('Platform', {'Name':platform})
    project.endElement ('Platforms')

    project.startElement ('Configurations', {})
    project.startElement ('Configuration', {'Name':variant+'|' + platform,
                                            'OutputDirectory':"".join(['.\\',variant,"\\",projectName]),
                                            'IntermediateDirectory':"".join(['.\\',variant,"\\",projectName]),
                                           'ConfigurationType':configurationTypeNbr,
                                           'UseOfMFC':'0',
                                            'CharacterSet':'1'})

    #
    # Compiler
    #

    if type(incPaths) != list:
        incPaths = split(";", incPaths)

    incPaths = [relntpath(path, vcprojPath) for path in incPaths]

    incPaths = ";".join(incPaths)

    compilerTool = {'Name':'VCCLCompilerTool',
                                  'PreprocessorDefinitions': prepDefs,
                                   'ObjectFile':"".join(['.\\',variant,"\\",projectName,'/']),
                                   'ProgramDataBaseFileName':"".join(['.\\',variant,"\\",projectName,'/']),
                                  'SuppressStartupBanner':'TRUE',
                                  'AdditionalIncludeDirectories':incPaths,
                                  'Optimization':'0',
                                   'DebugInformationFormat':debugInformationFormat}

    # Parse flags and add correct attributes in compiler tool.
    mycflags = cflags
    if type(mycflags) != list:
            mycflags = mycflags.split(' ')



    vcproj_opts_map = {
                    '/Zi':('DebugInformationFormat', '3'),
                    '/ZI':('DebugInformationFormat', '4'),
                    '/W4':('WarningLevel', '4'),
                    '/W3':('WarningLevel', '3'),
                    '/W2':('WarningLevel', '2'),
                    '/W1':('WarningLevel', '1'),
                    '/W0':('WarningLevel', '0'),
                    '/Od':('Optimization', '0'),
                    '/O1':('Optimization', '1'),
                    '/O2':('Optimization', '2')}

    # digest, analyse and remove options
    for opt in mycflags:
        try:
            (optionname,  numvalue) = vcproj_opts_map[opt]
            compilerTool[ optionname ] = numvalue
            mycflags.remove(opt)
            #print 'Digested %s'%opt
        except KeyError:
            #print 'Passing %s'%opt
            pass

    # Write the rest of the options as AdditionalOptions
    mycflags = " ".join(mycflags)
    compilerTool['AdditionalOptions'] = mycflags;

    # Write compilerTool to project
    project.element ('Tool',  compilerTool)

    #
    # Archiver
    #

    if configType == 'lib':
        project.element ('Tool', {'Name':'VCLibrarianTool',
                                   'OutputFile': '$(OutDir)/'+outLib})
    elif configType == 'exe':
        additionalDependencies = " ".join(map(ntpath.basename, additionalDependencies))
        additionalLibraryDirectories = " ".join(additionalLibraryDirectories)
        project.element ('Tool', {'Name':'VCLinkerTool',
                                  'GenerateDebugInformation':'TRUE',
                                  'TargetMachine':'1',
                                  'AdditionalDependencies':additionalDependencies,
                                  'AdditionalLibraryDirectories':additionalLibraryDirectories})
        project.element ('Tool', {'Name':'VCManifestTool'})
        project.element ('Tool', {'Name':'VCAppVerifierTool'})
        project.element ('Tool', {'Name':'VCWebDeploymentTool'})


    project.endElement ('Configuration')
    project.endElement ('Configurations')

    # Start module root folder.
    project.startElement ('Files')
    project.startElement ('Filter', {'Name':'Modules', 'Filter':''})


    #NOTE:
    #codeModules = listof dictionaries: { MODNAME: string, SOURCES: list(paths), PRIVHDRS: list(paths), PUBHDRS: list(paths), TESTSOURCES }
    for mod in codeModules:

        # Start module folder (public header goes here also)
        project.startElement ('Filter', {'Name': mod['MODNAME'],'Filter':''})


        # Start source file folder
        project.startElement ('Filter', {'Name': 'src','Filter':''})
        # Add all source files.
        for srcFile in mod['SOURCES']:
            project.startElement ('File', {'RelativePath': relntpath(srcFile, vcprojPath)})
            project.startElement('FileConfiguration',{'Name':"".join([variant,'|',platform])})
            project.element('Tool',{'Name':'VCCLCompilerTool','AdditionalIncludeDirectories':relntpath(mod['PRIVHDRDIR'], vcprojPath)})
            project.endElement ('FileConfiguration')
            project.endElement ('File')
            #project.startElement ('FileConfiguration', {'Name':variant+'|Win32'})
        # End source file folder
        project.endElement ('Filter')

        if do_tests:
            # Add test folder.
            project.startElement ('Filter', {'Name': 'tests','Filter':''})
            for src in mod['TESTSOURCES']:
                #project.characters('testsource:%s vcprojPath: %s'%(src, vcprojPath))
                project.startElement ('File', {'RelativePath':relntpath(src, vcprojPath)} )
                project.startElement('FileConfiguration',{'Name':"".join([variant,'|',platform])})
                project.element('Tool',{'Name':'VCCLCompilerTool','AdditionalIncludeDirectories':relntpath(mod['PRIVHDRDIR'], vcprojPath)})
                project.endElement ('FileConfiguration')
                project.endElement ('File')
            for hdr in mod['TESTHDRS']:
                project.element ('File', {'RelativePath':relntpath(hdr, vcprojPath)})

            project.endElement ('Filter')

        # Start private include folder
        project.startElement ('Filter', {'Name': 'inc','Filter':''})
        # Add all private headers.
        for hdr in mod['PRIVHDRS']:

            project.element ('File', {'RelativePath':relntpath(hdr, vcprojPath)})


        # End private include folder
        project.endElement ('Filter')


        # Add public headers to root.
        for hdr in mod['PUBHDRS']:
            #project.characters('header:%s vcprojPath: %s'%(hdr, vcprojPath))
            project.startElement ('File', {'RelativePath':relntpath(hdr, vcprojPath)} )
            project.endElement ('File')

        # End module folder
        project.endElement ('Filter')


    # End module root folder
    project.endElement ('Filter')

    project.endElement ('Files')

    project.endElement ('VisualStudioProject')

    vcprojFile.close ()

    return GUID
Example #4
0
def env2MSVS8 ( env, projname, path, srcs, variant ):
    # Create .proj file
    proj_file = open (os.path.join (path,projname + '.vcproj'), 'w')

    project = XMLGenerator (proj_file)

    GUID = '{28540DAA-6718-4DE8-8D55-468836F0BE71}'
    project.startElement ('VisualStudioProject', {'ProjectType':'Visual C++',
                                                  'Version':'8,00',
                                                 'Name':projname,
                                                 'ProjectGUID':GUID,
                                                 'SccProjectName':'',
                                                  'SccLocalPath':''})

    project.startElement ('Platforms', None)
    project.element ('Platform', {'Name':'Win32'})

    project.endElement ('Platforms')


    project.startElement ('Configurations', {})

    project.startElement ('Configuration', {'Name':variant+'|Win32',
                                           'OutputDirectory':'.\\'+variant,
                                           'IntermediateDirectory':'.\\'+variant,
                                           'ConfigurationType':'1',
                                           'UseOfMFC':'0',
                                            'CharacterSet':'2'})


    #
    # Compiler
    #

    ppdefs = ''
    for p in env['CPPDEFINES']:
        ppdefs = ppdefs + p + ';'

    # TODO: parse flags and add correct attributes in compiler tool.
    ccflags = env['CCFLAGS']

    project.element ('Tool', {'Name':'VCCLCompilerTool',
                                  'PreprocessorDefinitions':ppdefs,
                                  'ObjectFile':'.\\' + variant + '/',
                                  'ProgramDataBaseFileName':'.\\' + variant + '/',
                                  'SuppressStartupBanner':'TRUE',
                                   'AdditionalOptions':str(ccflags),
                                  'Optimization':'0',
                                   'DebugInformationFormat':'4'})


    #
    # Linker
    #
    libs = ""
    for lib in env['LIBS']:
        libs += str ( env['LIBPREFIX'] + lib + env['LIBSUFFIX'] ) + " "

    libsdir = ''
    for d in env['LIBPATH']:
        libsdir = libsdir + d + ';'

    project.element ('Tool', {'Name':'VCLinkerTool',
                             'AdditionalDependencies':libs,
                             'SuppressStartupBanner':'TRUE',
                             'OutputFile':'.\\' + variant + '/' + projname + '.exe',
                             'AdditionalLibraryDirectories':libsdir,
                              'GenerateDebugInformation':'TRUE'})

    project.endElement ('Configuration')
    project.endElement ('Configurations')

    project.startElement ('Files')

    project.startElement ('Filter', {'Name':'Source Files',
                                     'Filter':'cpp;c;cxx;rc;def;r;odl;idl;hpj;bat'})

    srcs.sort ()
    for m in srcs:
        module = m[0]
        src_list = m[1]

        project.startElement ('Filter', {'Name': module,'Filter':''})
        for s in src_list:
            incpaths = ''
            for path in s.incpaths:
                incpaths = incpaths + path + ';'

            ppdefs = ''
            for ppdef in s.ppdefs:
                ppdefs = ppdefs + ppdef + ';'

            project.startElement ('File', {'RelativePath':s.filepath})
            project.startElement ('FileConfiguration', {'Name':variant+'|Win32'})
            project.element ('Tool', {'Name':'VCCLCompilerTool',
                                 'PreprocessorDefinitions':ppdefs,
                                  'AdditionalIncludeDirectories':incpaths})
            project.endElement ('FileConfiguration')
            project.endElement ('File')

        project.endElement ('Filter')

    project.endElement ('Filter')

    project.endElement ('Files')

    project.endElement ('VisualStudioProject')

    proj_file.close ()
Example #5
0
def make_libvcproj8( projectName, cflags, prepDefs, codeModules, outLib,
                    debug, do_tests,  incPaths, vcprojPath, platform = 'Win32',
                    fileTitle = None, configType = 'lib',
                     additionalDependencies = None,
                     additionalLibraryDirectories = None):


    import os.path
    vcprojFilePath = str()
    vcprojPath = os.path.abspath(vcprojPath)
    if fileTitle == None:
        fileTitle = projectName

    vcprojFilePath  = os.path.join( vcprojPath, fileTitle + ".vcproj" )
    vcprojFile      = open( vcprojFilePath, 'w')
    project         = XMLGenerator( vcprojFile )

    #GUID            = str(pywintypes.CreateGuid())
    GUID            = "".join(["{",str(uuid.uuid3(uuid.NAMESPACE_URL,"make_libvcproj8" + projectName)).upper(),"}"])

    #
    # Determine exe/lib
    #
    if configType == 'lib':
        configurationTypeNbr = '4'
    elif configType == 'dll':
        configurationTypeNbr = '2'
    elif configType == 'exe':
        configurationTypeNbr = '1'
    else:
        print >>sys.stderr, "Erroneous config type. Using 'lib'"
        configType = 'lib'
        configurationTypeNbr = '4'

    #
    # Determine debug/release
    #
    variant = str()
    if debug:
        variant = 'Debug'
    else:
        variant = 'Release'

    #
    # Determine DebugInformationFormat
    #
    debugInformationFormat = str()
    debugInformationFormat = '0'

    #
    # Prepare proprocessor definitions.
    #
    if type(prepDefs) == list:
        tmp = str()
        for d in prepDefs:
            tmp += d + ';'
        prepDefs = tmp


    project.startElement ('VisualStudioProject', {'ProjectType':'Visual C++',
                                                  'Version':'8,00',
                                                 'Name':projectName,
                                                 'RootNamespace':projectName,
                                                 'ProjectGUID':GUID,
                                                 'SccProjectName':'',
                                                  'SccLocalPath':''})

    project.startElement ('Platforms', {})

    project.element ('Platform', {'Name':platform})
    project.endElement ('Platforms')

    project.startElement ('Configurations', {})
    project.startElement ('Configuration', {'Name':variant+'|' + platform,
                                            'OutputDirectory':"".join(['.\\',variant,"\\",projectName]),
                                            'IntermediateDirectory':"".join(['.\\',variant,"\\",projectName]),
                                            'ConfigurationType':configurationTypeNbr,
                                            'UseOfMFC':'0',
                                            'CharacterSet':'1'})

    #
    # Compiler
    #

    if type(incPaths) != list:
        incPaths = incPaths.split(';')

    incPaths = [relntpath(path, vcprojPath) for path in incPaths]

    incPaths = ";".join(incPaths)

    compilerTool = {'Name':'VCCLCompilerTool',
                                  'PreprocessorDefinitions': prepDefs,
                                    'ObjectFile':"".join(['.\\',variant,"\\",projectName,'/']),
                                    'ProgramDataBaseFileName':"".join(['.\\',variant,"\\",projectName,'/']),
                                  'SuppressStartupBanner':'TRUE',
                                  'AdditionalIncludeDirectories':incPaths,
                                  'Optimization':'0',
                                    'DebugInformationFormat':debugInformationFormat}

    # Parse flags and add correct attributes in compiler tool.
    # make a duplicate of the list
    mycflags = cflags[:]
    work_cflags = cflags[:]
    if type(mycflags) != list:
            mycflags = mycflags.split(' ')

    if type(work_cflags) != list:
            work_cflags = work_cflags.split(' ')



    vcproj_opts_map = {
                    '/Z7':('DebugInformationFormat', '1'),
                    '/Zd':('DebugInformationFormat', '2'),
                    '/Zi':('DebugInformationFormat', '3'),
                    '/ZI':('DebugInformationFormat', '4'),
                    '/W4':('WarningLevel', '4'),
                    '/W3':('WarningLevel', '3'),
                    '/W2':('WarningLevel', '2'),
                    '/W1':('WarningLevel', '1'),
                    '/W0':('WarningLevel', '0'),
                    '/Od':('Optimization', '0'),
                    '/O1':('Optimization', '1'),
                    '/O2':('Optimization', '2'),
                    '/Ox':('Optimization', '3'),
                    '/MT': ('RuntimeLibrary', '0'),
                    '/MTd':('RuntimeLibrary', '1'),
                    '/MD': ('RuntimeLibrary', '2'),
                    '/MDd':('RuntimeLibrary', '3'),
                    '/MLd':('RuntimeLibrary', '5'),
                    '/ML': ('RuntimeLibrary', '4'),
                    '/GZ':('BasicRuntimeChecks', '1'),
                    '/RTCsu':('BasicRuntimeChecks', '3'),
                    '/RTCs':('BasicRuntimeChecks', '1'),
                    '/RTCu': ('BasicRuntimeChecks', '2'),
                    '/RTC1':('BasicRuntimeChecks', '3'),
                    '/arch:SSE2':('EnableEnhancedInstructionSet', '2'),
                    '/arch:SSE':('EnableEnhancedInstructionSet', '1'),
                    '/Ot':('FavorSizeOrSpeed', '1'),
                    '/Os':('FavorSizeOrSpeed', '2'),
                    '/TC':('CompileAs', '1'),
                    '/TP':('CompileAs', '2'),
                    '/GB':('OptimizeForProcessor', '0'),
                    '/G5':('OptimizeForProcessor', '1'),
                    '/G6':('OptimizeForProcessor', '2'),
                    '/G7':('OptimizeForProcessor', '3'),
                    '/Ob0':('InlineFunctionExpansion', '0'),
                    '/Ob1':('InlineFunctionExpansion', '1'),
                    '/Ob2':('InlineFunctionExpansion', '2'),
                    '/Zp1':('StructMemberAlignment', '1'),
                    '/Zp2':('StructMemberAlignment', '2'),
                    '/Zp4':('StructMemberAlignment', '3'),
                    '/Zp8':('StructMemberAlignment', '4'),
                    '/Zp16':('StructMemberAlignment', '5')}

    for opt in work_cflags:
        if vcproj_opts_map.has_key(opt):
            (optionname, numvalue) = vcproj_opts_map[opt]
            compilerTool[ optionname ] = numvalue
            mycflags.remove(opt)

    # Write the rest of the options as AdditionalOptions
    mycflags = " ".join(mycflags)
    compilerTool['AdditionalOptions'] = mycflags;

    # Write compilerTool to project
    project.element ('Tool',  compilerTool)

    #
    # Archiver
    #

    if configType == 'lib':
        project.element ('Tool', {'Name':'VCLibrarianTool',
                                    'OutputFile': '$(OutDir)/'+outLib})
    elif configType == 'exe' or configType == 'dll':
        additionalDependencies = " ".join(map(ntpath.basename, additionalDependencies))
        additionalLibraryDirectories = ";".join(additionalLibraryDirectories)
        project.element ('Tool', {'Name':'VCLinkerTool',
                                  'GenerateDebugInformation':'TRUE',
                                  'TargetMachine':'1',
                                  'AdditionalDependencies':additionalDependencies,
                                  'AdditionalLibraryDirectories':additionalLibraryDirectories})
        project.element ('Tool', {'Name':'VCManifestTool'})
        project.element ('Tool', {'Name':'VCAppVerifierTool'})
        project.element ('Tool', {'Name':'VCWebDeploymentTool'})


    project.endElement ('Configuration')
    project.endElement ('Configurations')

    # Start module root folder.
    project.startElement ('Files')
    project.startElement ('Filter', {'Name':'Modules', 'Filter':''})


    #NOTE:
    #codeModules = listof dictionaries: { MODNAME: string, SOURCES: list(paths), PRIVHDRS: list(paths), PUBHDRS: list(paths), PRIVHDRDIR: string, DEPHDRDIRS: set(paths), TESTSOURCES }
    for mod in codeModules:

        # Start module folder (public header goes here also)
        project.startElement ('Filter', {'Name': mod['MODNAME'],'Filter':''})

        # Start source file folder
        project.startElement ('Filter', {'Name': 'src','Filter':''})
        # Add all source files.
        for srcFile in mod['SOURCES']:
            project.startElement ('File', {'RelativePath': relntpath(srcFile, vcprojPath)})
            project.startElement('FileConfiguration',{'Name':"".join([variant,'|',platform])})
            additionalIncludes = relntpath(mod['PRIVHDRDIR'], vcprojPath)
            for hdrdir in mod['DEPHDRDIRS']:
                additionalIncludes = additionalIncludes + ';' + relntpath(hdrdir, vcprojPath)
            project.element('Tool',{'Name':'VCCLCompilerTool','AdditionalIncludeDirectories':additionalIncludes})
            project.endElement ('FileConfiguration')
            project.endElement ('File')
            #project.startElement ('FileConfiguration', {'Name':variant+'|Win32'})
        # End source file folder
        project.endElement ('Filter')

        if do_tests:
            # Add test folder.
            project.startElement ('Filter', {'Name': 'tests','Filter':''})
            for src in mod['TESTSOURCES']:
                #project.characters('testsource:%s vcprojPath: %s'%(src, vcprojPath))
                project.startElement ('File', {'RelativePath':relntpath(src, vcprojPath)} )
                project.startElement('FileConfiguration',{'Name':"".join([variant,'|',platform])})
                additionalTestIncludes = relntpath(mod['PRIVHDRDIR'], vcprojPath)
                for hdrdir in mod['DEPHDRDIRS']:
                    additionalTestIncludes = additionalTestIncludes + ';' + relntpath(hdrdir, vcprojPath)
                project.element('Tool',{'Name':'VCCLCompilerTool','AdditionalIncludeDirectories':additionalTestIncludes})
                project.endElement ('FileConfiguration')
                project.endElement ('File')
            for hdr in mod['TESTHDRS']:
                project.element ('File', {'RelativePath':relntpath(hdr, vcprojPath)})

            project.endElement ('Filter')

        # Start private include folder
        project.startElement ('Filter', {'Name': 'inc','Filter':''})
        # Add all private headers.
        for hdr in mod['PRIVHDRS']:

            project.element ('File', {'RelativePath':relntpath(hdr, vcprojPath)})


        # End private include folder
        project.endElement ('Filter')


        # Add public headers to root.
        for hdr in mod['PUBHDRS']:
            #project.characters('header:%s vcprojPath: %s'%(hdr, vcprojPath))
            project.startElement ('File', {'RelativePath':relntpath(hdr, vcprojPath)} )
            project.endElement ('File')

        # End module folder
        project.endElement ('Filter')


    # End module root folder
    project.endElement ('Filter')

    project.endElement ('Files')

    project.endElement ('VisualStudioProject')

    vcprojFile.close ()

    return GUID