Clone( this C.ICommonCompilerSettings settings, C.ICommonCompilerSettings other) { settings.Bits = other.Bits; foreach (var define in other.PreprocessorDefines) { settings.PreprocessorDefines.Add(define.Key, define.Value); } foreach (var path in other.IncludePaths) { settings.IncludePaths.AddUnique(path); } foreach (var path in other.SystemIncludePaths) { settings.SystemIncludePaths.AddUnique(path); } settings.OutputType = other.OutputType; settings.DebugSymbols = other.DebugSymbols; settings.WarningsAsErrors = other.WarningsAsErrors; settings.Optimization = other.Optimization; settings.TargetLanguage = other.TargetLanguage; settings.OmitFramePointer = other.OmitFramePointer; foreach (var path in other.DisableWarnings) { settings.DisableWarnings.AddUnique(path); } foreach (var path in other.PreprocessorUndefines) { settings.PreprocessorUndefines.AddUnique(path); } }
Empty( this C.ICommonCompilerSettings settings) { settings.DisableWarnings = new Bam.Core.StringArray(); settings.IncludePaths = new Bam.Core.TokenizedStringArray(); settings.PreprocessorDefines = new PreprocessorDefinitions(); settings.PreprocessorUndefines = new Bam.Core.StringArray(); settings.SystemIncludePaths = new Bam.Core.TokenizedStringArray(); }
Intersect( this C.ICommonCompilerSettings shared, C.ICommonCompilerSettings other) { shared.Bits = shared.Bits.Intersect(other.Bits); shared.PreprocessorDefines = shared.PreprocessorDefines.Intersect(other.PreprocessorDefines); shared.IncludePaths = shared.IncludePaths.Intersect(other.IncludePaths); shared.SystemIncludePaths = shared.SystemIncludePaths.Intersect(other.SystemIncludePaths); shared.OutputType = shared.OutputType.Intersect(other.OutputType); shared.DebugSymbols = shared.DebugSymbols.Intersect(other.DebugSymbols); shared.WarningsAsErrors = shared.WarningsAsErrors.Intersect(other.WarningsAsErrors); shared.Optimization = shared.Optimization.Intersect(other.Optimization); shared.TargetLanguage = shared.TargetLanguage.Intersect(other.TargetLanguage); shared.OmitFramePointer = shared.OmitFramePointer.Intersect(other.OmitFramePointer); shared.DisableWarnings = shared.DisableWarnings.Intersect(other.DisableWarnings); shared.PreprocessorUndefines = shared.PreprocessorUndefines.Intersect(other.PreprocessorUndefines); }
Defaults( this C.ICommonCompilerSettings settings, Bam.Core.Module module) { settings.Bits = (module as CModule).BitDepth; settings.DebugSymbols = (0 != (module.BuildEnvironment.Configuration & (Bam.Core.EConfiguration.Debug | Bam.Core.EConfiguration.Profile))); settings.OmitFramePointer = (0 != (module.BuildEnvironment.Configuration & Bam.Core.EConfiguration.NotDebug)); settings.Optimization = (0 != (module.BuildEnvironment.Configuration & Bam.Core.EConfiguration.NotDebug)) ? EOptimization.Speed : EOptimization.Off; settings.OutputType = ECompilerOutput.CompileOnly; settings.PreprocessorDefines.Add(System.String.Format("D_BAM_CONFIGURATION_{0}", module.BuildEnvironment.Configuration.ToString().ToUpper())); if (module.BuildEnvironment.Platform.Includes(Bam.Core.EPlatform.Windows)) { settings.PreprocessorDefines.Add("D_BAM_PLATFORM_WINDOWS"); } else if (module.BuildEnvironment.Platform.Includes(Bam.Core.EPlatform.Linux)) { settings.PreprocessorDefines.Add("D_BAM_PLATFORM_LINUX"); } else if (module.BuildEnvironment.Platform.Includes(Bam.Core.EPlatform.OSX)) { settings.PreprocessorDefines.Add("D_BAM_PLATFORM_OSX"); } else { throw new Bam.Core.Exception("Unknown platform"); } { var is64bit = Bam.Core.OSUtilities.Is64Bit(module.BuildEnvironment.Platform); var bits = (is64bit) ? 64 : 32; settings.PreprocessorDefines.Add("D_BAM_PLATFORM_BITS", bits.ToString()); } { var isLittleEndian = Bam.Core.OSUtilities.IsLittleEndian; if (isLittleEndian) { settings.PreprocessorDefines.Add("D_BAM_PLATFORM_LITTLEENDIAN"); } else { settings.PreprocessorDefines.Add("D_BAM_PLATFORM_BIGENDIAN"); } } settings.TargetLanguage = ETargetLanguage.C; settings.WarningsAsErrors = true; }
Delta( this C.ICommonCompilerSettings delta, C.ICommonCompilerSettings lhs, C.ICommonCompilerSettings rhs) { delta.Bits = (lhs.Bits != rhs.Bits) ? lhs.Bits : null; delta.PreprocessorDefines = new PreprocessorDefinitions(lhs.PreprocessorDefines.Except(rhs.PreprocessorDefines)); delta.IncludePaths = new Bam.Core.TokenizedStringArray(lhs.IncludePaths.Except(rhs.IncludePaths)); delta.SystemIncludePaths = new Bam.Core.TokenizedStringArray(lhs.SystemIncludePaths.Except(rhs.SystemIncludePaths)); delta.OutputType = (lhs.OutputType != rhs.OutputType) ? lhs.OutputType : null; delta.DebugSymbols = (lhs.DebugSymbols != rhs.DebugSymbols) ? lhs.DebugSymbols : null; delta.WarningsAsErrors = (lhs.WarningsAsErrors != rhs.WarningsAsErrors) ? lhs.WarningsAsErrors : null; delta.Optimization = (lhs.Optimization != rhs.Optimization) ? lhs.Optimization : null; delta.TargetLanguage = (lhs.TargetLanguage != rhs.TargetLanguage) ? lhs.TargetLanguage : null; delta.OmitFramePointer = (lhs.OmitFramePointer != rhs.OmitFramePointer) ? lhs.OmitFramePointer : null; delta.DisableWarnings = new Bam.Core.StringArray(lhs.DisableWarnings.Except(rhs.DisableWarnings)); delta.PreprocessorUndefines = new Bam.Core.StringArray(lhs.PreprocessorUndefines.Except(rhs.PreprocessorUndefines)); }
Delta( this C.ICommonCompilerSettings delta, C.ICommonCompilerSettings lhs, C.ICommonCompilerSettings rhs) { delta.Bits = lhs.Bits.Complement(rhs.Bits); delta.PreprocessorDefines = lhs.PreprocessorDefines.Complement(rhs.PreprocessorDefines); delta.IncludePaths = lhs.IncludePaths.Complement(rhs.IncludePaths); delta.SystemIncludePaths = lhs.SystemIncludePaths.Complement(rhs.SystemIncludePaths); delta.OutputType = lhs.OutputType.Complement(rhs.OutputType); delta.DebugSymbols = lhs.DebugSymbols.Complement(rhs.DebugSymbols); delta.WarningsAsErrors = lhs.WarningsAsErrors.Complement(rhs.WarningsAsErrors); delta.Optimization = lhs.Optimization.Complement(rhs.Optimization); delta.TargetLanguage = lhs.TargetLanguage.Complement(rhs.TargetLanguage); delta.OmitFramePointer = lhs.OmitFramePointer.Complement(rhs.OmitFramePointer); delta.DisableWarnings = lhs.DisableWarnings.Complement(rhs.DisableWarnings); delta.PreprocessorUndefines = lhs.PreprocessorUndefines.Complement(rhs.PreprocessorUndefines); }
Intersect( this C.ICommonCompilerSettings shared, C.ICommonCompilerSettings other) { if (shared.Bits != other.Bits) { shared.Bits = null; } shared.PreprocessorDefines = new PreprocessorDefinitions(shared.PreprocessorDefines.Intersect(other.PreprocessorDefines)); shared.IncludePaths = new Bam.Core.TokenizedStringArray(shared.IncludePaths.Intersect(other.IncludePaths)); shared.SystemIncludePaths = new Bam.Core.TokenizedStringArray(shared.SystemIncludePaths.Intersect(other.SystemIncludePaths)); if (shared.OutputType != other.OutputType) { shared.OutputType = null; } if (shared.DebugSymbols != other.DebugSymbols) { shared.DebugSymbols = null; } if (shared.WarningsAsErrors != other.WarningsAsErrors) { shared.WarningsAsErrors = null; } if (shared.Optimization != other.Optimization) { shared.Optimization = null; } if (shared.TargetLanguage != other.TargetLanguage) { shared.TargetLanguage = null; } if (shared.OmitFramePointer != other.OmitFramePointer) { shared.OmitFramePointer = null; } shared.DisableWarnings = new Bam.Core.StringArray(shared.DisableWarnings.Intersect(other.DisableWarnings)); shared.PreprocessorUndefines = new Bam.Core.StringArray(shared.PreprocessorUndefines.Intersect(other.PreprocessorUndefines)); }
Convert( this C.ICommonCompilerSettings settings, Bam.Core.StringArray commandLine) { if (settings.Bits.HasValue) { switch (settings.Bits.Value) { case C.EBit.SixtyFour: commandLine.Add("-m64"); break; case C.EBit.ThirtyTwo: commandLine.Add("-m32"); break; default: throw new Bam.Core.Exception("Unknown machine bit size, {0}", settings.Bits.Value.ToString()); } } if (settings.DebugSymbols.HasValue) { if (settings.DebugSymbols.Value) { commandLine.Add("-g"); } } foreach (var warning in settings.DisableWarnings) { commandLine.Add(System.String.Format("-Wno-{0}", warning)); } foreach (var path in settings.IncludePaths) { commandLine.Add(System.String.Format("-I{0}", path.ParseAndQuoteIfNecessary())); } if (settings.OmitFramePointer.HasValue) { commandLine.Add(settings.OmitFramePointer.Value ? "-fomit-frame-pointer" : "-fno-omit-frame-pointer"); } if (settings.Optimization.HasValue) { switch (settings.Optimization.Value) { case C.EOptimization.Off: commandLine.Add("-O0"); break; case C.EOptimization.Size: commandLine.Add("-Os"); break; case C.EOptimization.Speed: commandLine.Add("-O1"); break; case C.EOptimization.Full: commandLine.Add("-O3"); break; default: throw new Bam.Core.Exception("Unknown optimization level, {0}", settings.Optimization.Value.ToString()); } } foreach (var define in settings.PreprocessorDefines) { if (System.String.IsNullOrEmpty(define.Value)) { commandLine.Add(System.String.Format("-D{0}", define.Key)); } else { var value = define.Value; if (value.Contains("\"")) { value = value.Replace("\"", "\\\""); } commandLine.Add(System.String.Format("-D{0}={1}", define.Key, value)); } } foreach (var undefine in settings.PreprocessorUndefines) { commandLine.Add(System.String.Format("-U{0}", undefine)); } foreach (var path in settings.SystemIncludePaths) { commandLine.Add(System.String.Format("-I{0}", path.ParseAndQuoteIfNecessary())); } if (settings.TargetLanguage.HasValue) { switch (settings.TargetLanguage.Value) { case C.ETargetLanguage.C: commandLine.Add("-x c"); break; case C.ETargetLanguage.Cxx: commandLine.Add("-x c++"); break; case C.ETargetLanguage.ObjectiveC: commandLine.Add("-x objective-c"); break; case C.ETargetLanguage.ObjectiveCxx: commandLine.Add("-x objective-c++"); break; default: throw new Bam.Core.Exception("Unsupported target language, {0}", settings.TargetLanguage.Value.ToString()); } } if (settings.WarningsAsErrors.HasValue) { if (settings.WarningsAsErrors.Value) { commandLine.Add("-Werror"); } else { commandLine.Add("-Wno-error"); } } if (settings.OutputType.HasValue) { var module = (settings as Bam.Core.Settings).Module; switch (settings.OutputType) { case C.ECompilerOutput.CompileOnly: commandLine.Add(System.String.Format("-c -o {0}", module.GeneratedPaths[C.ObjectFile.Key].ToString())); break; case C.ECompilerOutput.Preprocess: commandLine.Add(System.String.Format("-E -o {0}", module.GeneratedPaths[C.ObjectFile.Key].ToString())); break; } } }
Convert( this C.ICommonCompilerSettings settings, Bam.Core.Module module, VSSolutionBuilder.VSSettingsGroup vsSettingsGroup, string condition) { // write nothing for disabled debug symbols, otherwise the source files rebuild continually // and reports a warning that the pdb file does not exist // the IDE can write None into the .vcxproj, but this has the same behaviour // https://connect.microsoft.com/VisualStudio/feedback/details/833494/project-with-debug-information-disabled-always-rebuilds if (settings.DebugSymbols.HasValue) { if (settings.DebugSymbols.Value) { vsSettingsGroup.AddSetting("DebugInformationFormat", "OldStyle", condition); } } if (settings.DisableWarnings.Count > 0) { vsSettingsGroup.AddSetting("DisableSpecificWarnings", settings.DisableWarnings, condition, inheritExisting: true); } if (settings.IncludePaths.Count > 0) { vsSettingsGroup.AddSetting("AdditionalIncludeDirectories", settings.IncludePaths, condition, inheritExisting: true); } if (settings.OmitFramePointer.HasValue) { vsSettingsGroup.AddSetting("OmitFramePointers", settings.OmitFramePointer.Value, condition); } if (settings.Optimization.HasValue) { System.Func <string> optimization = () => { switch (settings.Optimization.Value) { case C.EOptimization.Off: return("Disabled"); case C.EOptimization.Size: return("MinSpace"); case C.EOptimization.Speed: return("MaxSpeed"); case C.EOptimization.Full: return("Full"); default: throw new Bam.Core.Exception("Unknown optimization type, {0}", settings.Optimization.Value.ToString()); } }; vsSettingsGroup.AddSetting("Optimization", optimization(), condition); } if (settings.PreprocessorDefines.Count > 0) { vsSettingsGroup.AddSetting("PreprocessorDefinitions", settings.PreprocessorDefines, condition, inheritExisting: true); } if (settings.PreprocessorUndefines.Count > 0) { vsSettingsGroup.AddSetting("UndefinePreprocessorDefinitions", settings.PreprocessorUndefines, condition, inheritExisting: true); } if (settings.TargetLanguage.HasValue) { System.Func <string> targetLanguage = () => { switch (settings.TargetLanguage.Value) { case C.ETargetLanguage.C: return("CompileAsC"); case C.ETargetLanguage.Cxx: return("CompileAsCpp"); case C.ETargetLanguage.Default: return("Default"); default: throw new Bam.Core.Exception("Unknown target language, {0}", settings.TargetLanguage.Value.ToString()); } }; vsSettingsGroup.AddSetting("CompileAs", targetLanguage(), condition); } if (settings.WarningsAsErrors.HasValue) { vsSettingsGroup.AddSetting("TreatWarningAsError", settings.WarningsAsErrors.Value, condition); } if (settings.OutputType.HasValue) { vsSettingsGroup.AddSetting("PreprocessToFile", settings.OutputType.Value == C.ECompilerOutput.Preprocess, condition); if (module is C.ObjectFile) // rather than ObjectFileCollection { vsSettingsGroup.AddSetting("ObjectFileName", module.GeneratedPaths[C.ObjectFile.Key], condition); } } }
Convert( this C.ICommonCompilerSettings settings, Bam.Core.StringArray commandLine) { var module = (settings as Bam.Core.Settings).Module; if (settings.DebugSymbols.HasValue) { if (settings.DebugSymbols.Value) { commandLine.Add("-Z7"); } } foreach (var warning in settings.DisableWarnings) { commandLine.Add(System.String.Format("-wd{0}", warning)); } foreach (var path in settings.IncludePaths) { commandLine.Add(System.String.Format("-I{0}", path.ParseAndQuoteIfNecessary())); } if (settings.OmitFramePointer.HasValue) { commandLine.Add(settings.OmitFramePointer.Value ? "-Oy" : "-Oy-"); } if (settings.Optimization.HasValue) { switch (settings.Optimization.Value) { case C.EOptimization.Off: commandLine.Add("-Od"); break; case C.EOptimization.Size: commandLine.Add("-Os"); break; case C.EOptimization.Speed: commandLine.Add("-O1"); break; case C.EOptimization.Full: commandLine.Add("-Ox"); break; default: throw new Bam.Core.Exception("Unknown optimization level, {0}", settings.Optimization.Value.ToString()); } } foreach (var define in settings.PreprocessorDefines) { if (System.String.IsNullOrEmpty(define.Value)) { commandLine.Add(System.String.Format("-D{0}", define.Key)); } else { var value = define.Value; if (value.Contains("\"")) { value = value.Replace("\"", "\\\""); } commandLine.Add(System.String.Format("-D{0}={1}", define.Key, value)); } } foreach (var undefine in settings.PreprocessorUndefines) { commandLine.Add(System.String.Format("-U{0}", undefine)); } foreach (var path in settings.SystemIncludePaths) { commandLine.Add(System.String.Format("-I{0}", path.ParseAndQuoteIfNecessary())); } if (settings.TargetLanguage.HasValue) { switch (settings.TargetLanguage.Value) { case C.ETargetLanguage.C: commandLine.Add("-TC"); break; case C.ETargetLanguage.Cxx: commandLine.Add("-TP"); break; default: throw new Bam.Core.Exception("Unsupported target language, {0}", settings.TargetLanguage.Value.ToString()); } } if (settings.WarningsAsErrors.HasValue) { if (settings.WarningsAsErrors.Value) { commandLine.Add("-WX"); } } if (settings.OutputType.HasValue) { switch (settings.OutputType.Value) { case C.ECompilerOutput.CompileOnly: commandLine.Add(System.String.Format("-c -Fo{0}", module.GeneratedPaths[C.ObjectFile.Key].ToString())); break; case C.ECompilerOutput.Preprocess: commandLine.Add(System.String.Format("-E -Fo{0}", module.GeneratedPaths[C.ObjectFile.Key].ToString())); break; default: throw new Bam.Core.Exception("Unknown output type, {0}", settings.OutputType.Value.ToString()); } } }
Convert( this C.ICommonCompilerSettings settings, Bam.Core.Module module, XcodeBuilder.Configuration configuration) { if (settings.Bits.HasValue) { switch (settings.Bits.Value) { case C.EBit.ThirtyTwo: { configuration["VALID_ARCHS"] = new XcodeBuilder.UniqueConfigurationValue("i386"); configuration["ARCHS"] = new XcodeBuilder.UniqueConfigurationValue("$(ARCHS_STANDARD_32_BIT)"); } break; case C.EBit.SixtyFour: { configuration["VALID_ARCHS"] = new XcodeBuilder.UniqueConfigurationValue("x86_64"); configuration["ARCHS"] = new XcodeBuilder.UniqueConfigurationValue("$(ARCHS_STANDARD_64_BIT)"); } break; default: throw new Bam.Core.Exception("Unknown bit depth, {0}", settings.Bits.Value); } } if (settings.DebugSymbols.HasValue) { configuration["GCC_GENERATE_DEBUGGING_SYMBOLS"] = new XcodeBuilder.UniqueConfigurationValue(settings.DebugSymbols.Value ? "YES" : "NO"); } if (settings.DisableWarnings.Count > 0) { var warnings = new XcodeBuilder.MultiConfigurationValue(); foreach (var warning in settings.DisableWarnings) { warnings.Add(System.String.Format("-Wno-{0}", warning)); } configuration["WARNING_CFLAGS"] = warnings; } if (settings.IncludePaths.Count > 0) { var paths = new XcodeBuilder.MultiConfigurationValue(); foreach (var path in settings.IncludePaths.ToEnumerableWithoutDuplicates()) { var fullPath = path.ToString(); var relPath = Bam.Core.RelativePathUtilities.GetPath(fullPath, configuration.Project.SourceRoot); // spaces need to be double escaped if (Bam.Core.RelativePathUtilities.IsPathAbsolute(relPath)) { if (fullPath.Contains(" ")) { fullPath = fullPath.Replace(" ", "\\\\ "); } paths.Add(fullPath); } else { if (relPath.Contains(" ")) { relPath = relPath.Replace(" ", "\\\\ "); } paths.Add(System.String.Format("$(SRCROOT)/{0}", relPath)); } } configuration["USER_HEADER_SEARCH_PATHS"] = paths; } if (settings.Optimization.HasValue) { switch (settings.Optimization.Value) { case C.EOptimization.Off: configuration["GCC_OPTIMIZATION_LEVEL"] = new XcodeBuilder.UniqueConfigurationValue("0"); break; case C.EOptimization.Size: configuration["GCC_OPTIMIZATION_LEVEL"] = new XcodeBuilder.UniqueConfigurationValue("s"); break; case C.EOptimization.Speed: configuration["GCC_OPTIMIZATION_LEVEL"] = new XcodeBuilder.UniqueConfigurationValue("2"); break; case C.EOptimization.Custom: // do nothing - defer to compiler specific optimizations break; default: throw new Bam.Core.Exception("Unsupported optimization, {0}", settings.Optimization.Value); } } if (settings.OmitFramePointer.HasValue) { var arg = settings.OmitFramePointer.Value ? "-fomit-frame-pointer" : "-fno-omit-frame-pointer"; configuration["OTHER_CFLAGS"] = new XcodeBuilder.MultiConfigurationValue(arg); } if (settings.PreprocessorDefines.Count > 0) { var defines = new XcodeBuilder.MultiConfigurationValue(); foreach (var define in settings.PreprocessorDefines) { if (null == define.Value) { defines.Add(define.Key); } else { var defineValue = define.Value.ToString(); if (defineValue.Contains(" ")) { defineValue = defineValue.Replace(" ", "\\\\ "); } if (defineValue.Contains("\"")) { // note the number of back slashes here // required to get \\\" for each " in the original value defineValue = defineValue.Replace("\"", "\\\\\\\""); } defines.Add(System.String.Format("{0}={1}", define.Key, defineValue)); } } configuration["GCC_PREPROCESSOR_DEFINITIONS"] = defines; } if (settings.PreprocessorUndefines.Count > 0) { var undefines = new XcodeBuilder.MultiConfigurationValue(); foreach (var undefine in settings.PreprocessorUndefines) { undefines.Add(System.String.Format("-U{0}", undefine)); } configuration["OTHER_CFLAGS"] = undefines; } if (settings.SystemIncludePaths.Count > 0) { var paths = new XcodeBuilder.MultiConfigurationValue(); foreach (var path in settings.SystemIncludePaths.ToEnumerableWithoutDuplicates()) { var full_path = path.ToString(); if (full_path.Contains(" ")) { full_path = full_path.Replace(" ", "\\\\ "); } paths.Add(full_path); } configuration["HEADER_SEARCH_PATHS"] = paths; } if (settings.TargetLanguage.HasValue) { switch (settings.TargetLanguage.Value) { case C.ETargetLanguage.Default: configuration["GCC_INPUT_FILETYPE"] = new XcodeBuilder.UniqueConfigurationValue("automatic"); break; case C.ETargetLanguage.C: configuration["GCC_INPUT_FILETYPE"] = new XcodeBuilder.UniqueConfigurationValue("sourcecode.c.c"); break; case C.ETargetLanguage.Cxx: configuration["GCC_INPUT_FILETYPE"] = new XcodeBuilder.UniqueConfigurationValue("sourcecode.cpp.cpp"); break; case C.ETargetLanguage.ObjectiveC: configuration["GCC_INPUT_FILETYPE"] = new XcodeBuilder.UniqueConfigurationValue("sourcecode.c.objc"); break; case C.ETargetLanguage.ObjectiveCxx: configuration["GCC_INPUT_FILETYPE"] = new XcodeBuilder.UniqueConfigurationValue("sourcecode.cpp.objcpp"); break; default: throw new Bam.Core.Exception("Unsupported target language, {0}", settings.TargetLanguage.Value); } } if (settings.WarningsAsErrors.HasValue) { configuration["GCC_TREAT_WARNINGS_AS_ERRORS"] = new XcodeBuilder.UniqueConfigurationValue(settings.WarningsAsErrors.Value ? "YES" : "NO"); } if (settings.OutputType.HasValue) { // TODO: anything? } if (settings.NamedHeaders.Count > 0) { var namedHeaders = new XcodeBuilder.MultiConfigurationValue(); foreach (var header in settings.NamedHeaders) { // have to split this into two, or Xcode does not recognise it namedHeaders.Add("-include"); namedHeaders.Add(header); } configuration["OTHER_CFLAGS"] = namedHeaders; } }
Convert( this C.ICommonCompilerSettings settings, Bam.Core.StringArray commandLine) { var module = (settings as Bam.Core.Settings).Module; if (settings.DebugSymbols.HasValue) { if (settings.DebugSymbols.Value) { commandLine.Add("-Z7"); } } foreach (var warning in settings.DisableWarnings) { commandLine.Add(System.String.Format("-wd{0}", warning)); } foreach (var path in settings.IncludePaths.ToEnumerableWithoutDuplicates()) { commandLine.Add(System.String.Format("-I{0}", path.ToStringQuoteIfNecessary())); } if (settings.Optimization.HasValue) { switch (settings.Optimization.Value) { case C.EOptimization.Off: commandLine.Add("-Od"); break; case C.EOptimization.Size: commandLine.Add("-O1"); break; case C.EOptimization.Speed: commandLine.Add("-O2"); break; case C.EOptimization.Custom: // do nothing - deferred to compiler specific optimization settings break; default: throw new Bam.Core.Exception("Unknown optimization level, {0}", settings.Optimization.Value.ToString()); } } if (settings.OmitFramePointer.HasValue) { commandLine.Add(settings.OmitFramePointer.Value ? "-Oy" : "-Oy-"); } foreach (var define in settings.PreprocessorDefines) { if (null == define.Value) { commandLine.Add(System.String.Format("-D{0}", define.Key)); } else { var defineValue = define.Value.ToString(); if (defineValue.Contains("\"")) { defineValue = defineValue.Replace("\"", "\\\""); } defineValue = Bam.Core.IOWrapper.EncloseSpaceContainingPathWithDoubleQuotes(defineValue); commandLine.Add(System.String.Format("-D{0}={1}", define.Key, defineValue)); } } foreach (var undefine in settings.PreprocessorUndefines) { commandLine.Add(System.String.Format("-U{0}", undefine)); } foreach (var path in settings.SystemIncludePaths.ToEnumerableWithoutDuplicates()) { commandLine.Add(System.String.Format("-I{0}", path.ToStringQuoteIfNecessary())); } if (settings.TargetLanguage.HasValue) { switch (settings.TargetLanguage.Value) { case C.ETargetLanguage.C: commandLine.Add("-TC"); break; case C.ETargetLanguage.Cxx: commandLine.Add("-TP"); break; default: throw new Bam.Core.Exception("Unsupported target language, {0}", settings.TargetLanguage.Value.ToString()); } } if (settings.WarningsAsErrors.HasValue) { if (settings.WarningsAsErrors.Value) { commandLine.Add("-WX"); } else { commandLine.Add("-WX-"); } } if (settings.OutputType.HasValue) { switch (settings.OutputType.Value) { case C.ECompilerOutput.CompileOnly: commandLine.Add(System.String.Format("-c -Fo{0}", module.GeneratedPaths[C.ObjectFile.Key].ToStringQuoteIfNecessary())); break; case C.ECompilerOutput.Preprocess: commandLine.Add(System.String.Format("-E -Fo{0}", module.GeneratedPaths[C.ObjectFile.Key].ToStringQuoteIfNecessary())); break; default: throw new Bam.Core.Exception("Unknown output type, {0}", settings.OutputType.Value.ToString()); } } foreach (var header in settings.NamedHeaders) { commandLine.Add(System.String.Format("-FI{0}", header)); } }
Convert( this C.ICommonCompilerSettings settings, Bam.Core.Module module, XcodeBuilder.Configuration configuration) { if (settings.Bits.HasValue) { switch (settings.Bits.Value) { case C.EBit.ThirtyTwo: { configuration["VALID_ARCHS"] = new XcodeBuilder.UniqueConfigurationValue("i386"); configuration["ARCHS"] = new XcodeBuilder.UniqueConfigurationValue("$(ARCHS_STANDARD_32_BIT)"); } break; case C.EBit.SixtyFour: { configuration["VALID_ARCHS"] = new XcodeBuilder.UniqueConfigurationValue("x86_64"); configuration["ARCHS"] = new XcodeBuilder.UniqueConfigurationValue("$(ARCHS_STANDARD_64_BIT)"); } break; default: throw new Bam.Core.Exception("Unknown bit depth, {0}", settings.Bits.Value); } } if (settings.DebugSymbols.HasValue) { configuration["GCC_GENERATE_DEBUGGING_SYMBOLS"] = new XcodeBuilder.UniqueConfigurationValue(settings.DebugSymbols.Value ? "YES" : "NO"); } if (settings.DisableWarnings.Count > 0) { var warnings = new XcodeBuilder.MultiConfigurationValue(); foreach (var warning in settings.DisableWarnings) { warnings.Add(System.String.Format("-Wno-{0}", warning)); } configuration["WARNING_CFLAGS"] = warnings; } if (settings.IncludePaths.Count > 0) { var paths = new XcodeBuilder.MultiConfigurationValue(); foreach (var path in settings.IncludePaths) { paths.Add(path.ToString()); } configuration["USER_HEADER_SEARCH_PATHS"] = paths; } if (settings.OmitFramePointer.HasValue) { var arg = settings.OmitFramePointer.Value ? "-fomit-frame-pointer" : "-fno-omit-frame-pointer"; configuration["OTHER_CFLAGS"] = new XcodeBuilder.MultiConfigurationValue(arg); } if (settings.Optimization.HasValue) { switch (settings.Optimization.Value) { case C.EOptimization.Off: configuration["GCC_OPTIMIZATION_LEVEL"] = new XcodeBuilder.UniqueConfigurationValue("0"); break; case C.EOptimization.Size: configuration["GCC_OPTIMIZATION_LEVEL"] = new XcodeBuilder.UniqueConfigurationValue("s"); break; case C.EOptimization.Speed: configuration["GCC_OPTIMIZATION_LEVEL"] = new XcodeBuilder.UniqueConfigurationValue("1"); break; case C.EOptimization.Full: configuration["GCC_OPTIMIZATION_LEVEL"] = new XcodeBuilder.UniqueConfigurationValue("3"); break; default: throw new Bam.Core.Exception("Unsupported optimization, {0}", settings.Optimization.Value); } } if (settings.PreprocessorDefines.Count > 0) { var defines = new XcodeBuilder.MultiConfigurationValue(); foreach (var define in settings.PreprocessorDefines) { if (System.String.IsNullOrEmpty(define.Value)) { defines.Add(define.Key); } else { var value = define.Value; if (value.Contains("\"")) { // note the number of back slashes here // required to get \\\" for each " in the original value value = value.Replace("\"", "\\\\\\\""); } defines.Add(System.String.Format("{0}={1}", define.Key, value)); } } configuration["GCC_PREPROCESSOR_DEFINITIONS"] = defines; } if (settings.PreprocessorUndefines.Count > 0) { var undefines = new XcodeBuilder.MultiConfigurationValue(); foreach (var undefine in settings.PreprocessorUndefines) { undefines.Add(System.String.Format("-U{0}", undefine)); } configuration["OTHER_CFLAGS"] = undefines; } if (settings.SystemIncludePaths.Count > 0) { var paths = new XcodeBuilder.MultiConfigurationValue(); foreach (var path in settings.SystemIncludePaths) { paths.Add(path.ToString()); } configuration["HEADER_SEARCH_PATHS"] = paths; } if (settings.TargetLanguage.HasValue) { switch (settings.TargetLanguage.Value) { case C.ETargetLanguage.Default: configuration["GCC_INPUT_FILETYPE"] = new XcodeBuilder.UniqueConfigurationValue("automatic"); break; case C.ETargetLanguage.C: configuration["GCC_INPUT_FILETYPE"] = new XcodeBuilder.UniqueConfigurationValue("sourcecode.c.c"); break; case C.ETargetLanguage.Cxx: configuration["GCC_INPUT_FILETYPE"] = new XcodeBuilder.UniqueConfigurationValue("sourcecode.cpp.cpp"); break; case C.ETargetLanguage.ObjectiveC: configuration["GCC_INPUT_FILETYPE"] = new XcodeBuilder.UniqueConfigurationValue("sourcecode.c.objc"); break; case C.ETargetLanguage.ObjectiveCxx: configuration["GCC_INPUT_FILETYPE"] = new XcodeBuilder.UniqueConfigurationValue("sourcecode.cpp.objcpp"); break; default: throw new Bam.Core.Exception("Unsupported target language, {0}", settings.TargetLanguage.Value); } } if (settings.WarningsAsErrors.HasValue) { configuration["GCC_TREAT_WARNINGS_AS_ERRORS"] = new XcodeBuilder.UniqueConfigurationValue(settings.WarningsAsErrors.Value ? "YES" : "NO"); } if (settings.OutputType.HasValue) { // TODO: anything? } }
Convert( this C.ICommonCompilerSettings settings, Bam.Core.StringArray commandLine) { if (settings.Bits.HasValue) { switch (settings.Bits.Value) { case C.EBit.SixtyFour: commandLine.Add("-arch x86_64"); break; case C.EBit.ThirtyTwo: commandLine.Add("-arch i386"); break; default: throw new Bam.Core.Exception("Unknown bit depth, {0}", settings.Bits.Value); } } if (settings.DebugSymbols.HasValue) { if (settings.DebugSymbols.Value) { commandLine.Add("-g"); } } foreach (var warning in settings.DisableWarnings) { commandLine.Add(System.String.Format("-Wno-{0}", warning)); } foreach (var path in settings.IncludePaths.ToEnumerableWithoutDuplicates()) { var quoted_path = path.ToStringQuoteIfNecessary(); if (Bam.Core.Graph.Instance.Mode == "Xcode") { quoted_path = quoted_path.Replace("\"", "\\\""); } commandLine.Add(System.String.Format("-I{0}", quoted_path)); } if (settings.Optimization.HasValue) { switch (settings.Optimization.Value) { case C.EOptimization.Off: commandLine.Add("-O0"); break; case C.EOptimization.Size: commandLine.Add("-Os"); break; case C.EOptimization.Speed: commandLine.Add("-O2"); break; case C.EOptimization.Custom: // do nothing - defer to the compiler specific optimization settings break; default: throw new Bam.Core.Exception("Unsupported optimization, {0}", settings.Optimization.Value); } } if (settings.OmitFramePointer.HasValue) { commandLine.Add(settings.OmitFramePointer.Value ? "-fomit-frame-pointer" : "-fno-omit-frame-pointer"); } foreach (var define in settings.PreprocessorDefines) { if (null == define.Value) { commandLine.Add(System.String.Format("-D{0}", define.Key)); } else { var defineValue = define.Value.ToString(); if (defineValue.Contains("\"")) { if (Bam.Core.Graph.Instance.Mode == "Xcode") { // note the number of back slashes here // required to get \\\" for each " in the original value defineValue = defineValue.Replace("\"", "\\\\\\\""); } else { defineValue = defineValue.Replace("\"", "\\\""); } } defineValue = Bam.Core.IOWrapper.EncloseSpaceContainingPathWithDoubleQuotes(defineValue); commandLine.Add(System.String.Format("-D{0}={1}", define.Key, defineValue)); } } foreach (var undefine in settings.PreprocessorUndefines) { commandLine.Add(System.String.Format("-U{0}", undefine)); } foreach (var path in settings.SystemIncludePaths.ToEnumerableWithoutDuplicates()) { var quoted_path = path.ToStringQuoteIfNecessary(); if (Bam.Core.Graph.Instance.Mode == "Xcode") { quoted_path = quoted_path.Replace("\"", "\\\""); } commandLine.Add(System.String.Format("-I{0}", quoted_path)); } if (settings.TargetLanguage.HasValue) { switch (settings.TargetLanguage.Value) { case C.ETargetLanguage.C: commandLine.Add("-x c"); break; case C.ETargetLanguage.Cxx: commandLine.Add("-x c++"); break; case C.ETargetLanguage.ObjectiveC: commandLine.Add("-x objective-c"); break; case C.ETargetLanguage.ObjectiveCxx: commandLine.Add("-x objective-c++"); break; default: throw new Bam.Core.Exception("Unsupported target language, {0}", settings.TargetLanguage.Value); } } if (settings.WarningsAsErrors.HasValue) { if (settings.WarningsAsErrors.Value) { commandLine.Add("-Werror"); } else { commandLine.Add("-Wno-error"); } } if (settings.OutputType.HasValue) { var module = (settings as Bam.Core.Settings).Module; switch (settings.OutputType.Value) { case C.ECompilerOutput.CompileOnly: commandLine.Add(System.String.Format("-c -o {0}", module.GeneratedPaths[C.ObjectFile.Key].ToStringQuoteIfNecessary())); break; case C.ECompilerOutput.Preprocess: commandLine.Add(System.String.Format("-E -o {0}", module.GeneratedPaths[C.ObjectFile.Key].ToStringQuoteIfNecessary())); break; default: throw new Bam.Core.Exception("Unsupported output type, {0}", settings.OutputType.Value.ToString()); } } foreach (var header in settings.NamedHeaders) { commandLine.Add(System.String.Format("-include {0}", header)); } }