def Dep(self, text, node=None): return Dep(text, node)
def export_configuration_options(node, xml, builder): compiler = builder.compiler includes = ['%(AdditionalIncludeDirectories)'] + compiler.includes + compiler.cxxincludes all_defines = compiler.defines + compiler.cxxdefines simple_defines = ['%(PreprocessorDefinitions)'] + [option for option in all_defines if '=' not in option] val_defines = ['/D{0}'.format(option) for option in all_defines if '=' in option] with xml.block('ClCompile'): flags = compiler.cflags + compiler.cxxflags # Filter out options we handle specially. other_flags = val_defines + flags other_flags = [flag for flag in other_flags if not flag.startswith('/O')] other_flags = [flag for flag in other_flags if not flag.startswith('/RTC')] other_flags = [flag for flag in other_flags if not flag.startswith('/EH')] other_flags = [flag for flag in other_flags if not flag.startswith('/MT')] other_flags = [flag for flag in other_flags if not flag.startswith('/MD')] other_flags = [flag for flag in other_flags if not flag.startswith('/W')] other_flags = [flag for flag in other_flags if not flag.startswith('/GR')] if len(other_flags): xml.tag('AdditionalOptions', ' '.join(other_flags)) xml.tag('AdditionalIncludeDirectories', ';'.join(includes)) xml.tag('PreprocessorDefinitions', ';'.join(simple_defines)) if '/Ox' in flags: xml.tag('Optimization', 'Full') elif '/O2' in flags: xml.tag('Optimization', 'MaxSpeed') elif '/O1' in flags: xml.tag('Optimization', 'MinSpace') else: xml.tag('Optimization', 'Disabled') if '/Os' in flags: xml.tag('FavorSizeOrSpeed', 'Size') elif '/Ot' in flags: xml.tag('FavorSizeOrSpeed', 'Speed') xml.tag('MinimalRebuild', 'true') if '/RTC1' in flags or '/RTCsu' in flags: xml.tag('BasicRuntimeChecks', 'EnableFastChecks') elif '/RTCs' in flags: xml.tag('BasicRuntimeChecks', 'StackFrame') elif '/RTCu' in flags: xml.tag('BasicRuntimeChecks', 'UninitVariables') if '/Oy-' in flags: xml.tag('OmitFramePointer', 'true') if '/EHsc' in flags: xml.tag('ExceptionHandling', 'Sync') if '/MT' in flags: xml.tag('RuntimeLibrary', 'MultiThreaded') elif '/MTd' in flags: xml.tag('RuntimeLibrary', 'MultiThreadedDebug') elif '/MD' in flags: xml.tag('RuntimeLibrary', 'MultiThreadedDLL') elif '/MDd' in flags: xml.tag('RuntimeLibrary', 'MultiThreadedDebugDLL') if '/W0' in flags: xml.tag('WarningLevel', 'Level0') elif '/W1' in flags: xml.tag('WarningLevel', 'Level1') elif '/W2' in flags: xml.tag('WarningLevel', 'Level2') elif '/W3' in flags: xml.tag('WarningLevel', 'Level3') elif '/W4' in flags: xml.tag('WarningLevel', 'Level4') if '/Od' in flags: xml.tag('DebugInformationFormat', 'EditAndContinue') else: xml.tag('DebugInformationFormat', 'ProgramDatabase') if '/GR-' in flags: xml.tag('RuntimeTypeInfo', 'false') elif '/GR' in flags: xml.tag('RuntimeTypeInfo', 'true') with xml.block('PrecompiledHeader'): pass xml.tag('MultiProcessorCompilation', 'true') with xml.block('ResourceCompile'): defines = ['%(PreprocessorDefinitions)'] + compiler.defines + compiler.cxxdefines + compiler.rcdefines defines = sanitize_val_defines(defines) xml.tag('PreprocessorDefinitions', ';'.join(defines)) xml.tag('AdditionalIncludeDirectories', ';'.join(includes[1:] + includes[0:1])) with xml.block('Link'): link_flags = compiler.linkflags + compiler.postlink # Parse link flags. libs = ['%(AdditionalDependencies)'] ignore_libs = ['%(IgnoreSpecificDefaultLibraries)'] machine = 'X86' subsystem = 'Windows' for flag in link_flags: if util.IsString(flag): if flag == '/SUBSYSTEM:CONSOLE': subsystem = 'Console' continue if '.lib' in flag: libs.append(flag) continue m = re.match('/NODEFAULTLIB:(.+)', flag) if m is not None: ignore_libs.append(m.group(1)) continue m = re.match('/MACHINE:(.+)', flag) if m is not None: machine = m.group(1) else: libs.append(Dep.resolve(node.context, builder, flag)) if '/WX' in flags: xml.tag('TreatWarningsAsError', 'true') xml.tag('AdditionalDependencies', ';'.join(libs)) xml.tag('OutputFile', '$(OutDir)$(TargetFileName)') xml.tag('IgnoreSpecificDefaultLibraries', ';'.join(ignore_libs)) if compiler.symbol_files is None: xml.tag('GenerateDebugInformation', 'false') else: xml.tag('GenerateDebugInformation', 'true') if '/OPT:REF' in link_flags: xml.tag('OptimizeReferences', 'true') elif '/OPT:NOREF' in link_flags: xml.tag('OptimizeReferences', 'false') if '/OPT:ICF' in link_flags: xml.tag('EnableCOMDATFolding', 'true') elif '/OPT:NOICF' in link_flags: xml.tag('EnableCOMDATFolding', 'true') xml.tag('TargetMachine', 'Machine{0}'.format(machine))
def export_configuration_options(node, xml, builder): compiler = builder.compiler includes = ['%(AdditionalIncludeDirectories)' ] + compiler.includes + compiler.cxxincludes all_defines = compiler.defines + compiler.cxxdefines simple_defines = ['%(PreprocessorDefinitions)'] + [ option for option in all_defines if '=' not in option ] val_defines = [ '/D{0}'.format(option) for option in all_defines if '=' in option ] with xml.block('ClCompile'): flags = compiler.cflags + compiler.cxxflags # Filter out options we handle specially. other_flags = val_defines + flags other_flags = [ flag for flag in other_flags if not flag.startswith('/O') ] other_flags = [ flag for flag in other_flags if not flag.startswith('/RTC') ] other_flags = [ flag for flag in other_flags if not flag.startswith('/EH') ] other_flags = [ flag for flag in other_flags if not flag.startswith('/MT') ] other_flags = [ flag for flag in other_flags if not flag.startswith('/MD') ] other_flags = [ flag for flag in other_flags if not flag.startswith('/W') ] other_flags = [ flag for flag in other_flags if not flag.startswith('/GR') ] if len(other_flags): xml.tag('AdditionalOptions', ' '.join(other_flags)) xml.tag('AdditionalIncludeDirectories', ';'.join(includes)) xml.tag('PreprocessorDefinitions', ';'.join(simple_defines)) if '/Ox' in flags: xml.tag('Optimization', 'Full') elif '/O2' in flags: xml.tag('Optimization', 'MaxSpeed') elif '/O1' in flags: xml.tag('Optimization', 'MinSpace') else: xml.tag('Optimization', 'Disabled') if '/Os' in flags: xml.tag('FavorSizeOrSpeed', 'Size') elif '/Ot' in flags: xml.tag('FavorSizeOrSpeed', 'Speed') xml.tag('MinimalRebuild', 'true') if '/RTC1' in flags or '/RTCsu' in flags: xml.tag('BasicRuntimeChecks', 'EnableFastChecks') elif '/RTCs' in flags: xml.tag('BasicRuntimeChecks', 'StackFrame') elif '/RTCu' in flags: xml.tag('BasicRuntimeChecks', 'UninitVariables') if '/Oy-' in flags: xml.tag('OmitFramePointer', 'true') if '/EHsc' in flags: xml.tag('ExceptionHandling', 'Sync') if '/MT' in flags: xml.tag('RuntimeLibrary', 'MultiThreaded') elif '/MTd' in flags: xml.tag('RuntimeLibrary', 'MultiThreadedDebug') elif '/MD' in flags: xml.tag('RuntimeLibrary', 'MultiThreadedDLL') elif '/MDd' in flags: xml.tag('RuntimeLibrary', 'MultiThreadedDebugDLL') if '/W0' in flags: xml.tag('WarningLevel', 'Level0') elif '/W1' in flags: xml.tag('WarningLevel', 'Level1') elif '/W2' in flags: xml.tag('WarningLevel', 'Level2') elif '/W3' in flags: xml.tag('WarningLevel', 'Level3') elif '/W4' in flags: xml.tag('WarningLevel', 'Level4') if '/Od' in flags: xml.tag('DebugInformationFormat', 'EditAndContinue') else: xml.tag('DebugInformationFormat', 'ProgramDatabase') if '/GR-' in flags: xml.tag('RuntimeTypeInfo', 'false') elif '/GR' in flags: xml.tag('RuntimeTypeInfo', 'true') with xml.block('PrecompiledHeader'): pass xml.tag('MultiProcessorCompilation', 'true') with xml.block('ResourceCompile'): defines = [ '%(PreprocessorDefinitions)' ] + compiler.defines + compiler.cxxdefines + compiler.rcdefines defines = sanitize_val_defines(defines) xml.tag('PreprocessorDefinitions', ';'.join(defines)) xml.tag('AdditionalIncludeDirectories', ';'.join(includes[1:] + includes[0:1])) with xml.block('Link'): link_flags = compiler.linkflags + compiler.postlink # Parse link flags. libs = ['%(AdditionalDependencies)'] ignore_libs = ['%(IgnoreSpecificDefaultLibraries)'] machine = 'X86' subsystem = 'Windows' for flag in link_flags: if util.IsString(flag): if flag == '/SUBSYSTEM:CONSOLE': subsystem = 'Console' continue if '.lib' in flag: libs.append(flag) continue m = re.match('/NODEFAULTLIB:(.+)', flag) if m is not None: ignore_libs.append(m.group(1)) continue m = re.match('/MACHINE:(.+)', flag) if m is not None: machine = m.group(1) else: libs.append(Dep.resolve(node.context, builder, flag)) xml.tag('AdditionalDependencies', ';'.join(libs)) xml.tag('OutputFile', '$(OutDir)$(TargetFileName)') xml.tag('IgnoreSpecificDefaultLibraries', ';'.join(ignore_libs)) if compiler.debuginfo is None: xml.tag('GenerateDebugInformation', 'false') else: xml.tag('GenerateDebugInformation', 'true') if '/OPT:REF' in link_flags: xml.tag('OptimizeReferences', 'true') elif '/OPT:NOREF' in link_flags: xml.tag('OptimizeReferences', 'false') if '/OPT:ICF' in link_flags: xml.tag('EnableCOMDATFolding', 'true') elif '/OPT:NOICF' in link_flags: xml.tag('EnableCOMDATFolding', 'true') xml.tag('TargetMachine', 'Machine{0}'.format(machine))