WinGammaPlatformVC10.java 14.9 KB
Newer Older
1 2 3 4 5
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
N
neliasso 已提交
6
import java.nio.file.FileSystems;
7
import java.util.Iterator;
N
neliasso 已提交
8
import java.util.LinkedList;
9 10 11 12 13
import java.util.UUID;
import java.util.Vector;

public class WinGammaPlatformVC10 extends WinGammaPlatformVC7 {

N
neliasso 已提交
14 15 16 17

   LinkedList <String>filters = new LinkedList<String>();
   LinkedList <String[]>filterDeps = new LinkedList<String[]>();

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    @Override
    protected String getProjectExt() {
        return ".vcxproj";
    }

    @Override
    public void writeProjectFile(String projectFileName, String projectName,
            Vector<BuildConfig> allConfigs) throws IOException {
        System.out.println();
        System.out.print("    Writing .vcxproj file: " + projectFileName);

        String projDir = Util.normalize(new File(projectFileName).getParent());

        printWriter = new PrintWriter(projectFileName, "UTF-8");
        printWriter.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        startTag("Project",
                "DefaultTargets", "Build",
                "ToolsVersion", "4.0",
                "xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
        startTag("ItemGroup",
                "Label", "ProjectConfigurations");
        for (BuildConfig cfg : allConfigs) {
            startTag("ProjectConfiguration",
                    "Include", cfg.get("Name"));
            tagData("Configuration", cfg.get("Id"));
            tagData("Platform", cfg.get("PlatformName"));
N
neliasso 已提交
44
            endTag();
45
        }
N
neliasso 已提交
46
        endTag();
47 48 49 50 51

        startTag("PropertyGroup", "Label", "Globals");
        tagData("ProjectGuid", "{8822CB5C-1C41-41C2-8493-9F6E1994338B}");
        tag("SccProjectName");
        tag("SccLocalPath");
N
neliasso 已提交
52
        endTag();
53 54 55 56 57 58 59

        tag("Import", "Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");

        for (BuildConfig cfg : allConfigs) {
            startTag(cfg, "PropertyGroup", "Label", "Configuration");
            tagData("ConfigurationType", "DynamicLibrary");
            tagData("UseOfMfc", "false");
N
neliasso 已提交
60
            endTag();
61 62 63 64
        }

        tag("Import", "Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
        startTag("ImportGroup", "Label", "ExtensionSettings");
N
neliasso 已提交
65
        endTag();
66 67 68 69 70 71
        for (BuildConfig cfg : allConfigs) {
            startTag(cfg, "ImportGroup", "Label", "PropertySheets");
            tag("Import",
                    "Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props",
                    "Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')",
                    "Label", "LocalAppDataPlatform");
N
neliasso 已提交
72
            endTag();
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
        }

        tag("PropertyGroup", "Label", "UserMacros");

        startTag("PropertyGroup");
        tagData("_ProjectFileVersion", "10.0.30319.1");
        for (BuildConfig cfg : allConfigs) {
            tagData(cfg, "OutDir", cfg.get("OutputDir") + Util.sep);
            tagData(cfg, "IntDir", cfg.get("OutputDir") + Util.sep);
            tagData(cfg, "LinkIncremental", "false");
        }
        for (BuildConfig cfg : allConfigs) {
            tagData(cfg, "CodeAnalysisRuleSet", "AllRules.ruleset");
            tag(cfg, "CodeAnalysisRules");
            tag(cfg, "CodeAnalysisRuleAssemblies");
        }
N
neliasso 已提交
89
        endTag();
90 91 92 93 94

        for (BuildConfig cfg : allConfigs) {
            startTag(cfg, "ItemDefinitionGroup");
            startTag("ClCompile");
            tagV(cfg.getV("CompilerFlags"));
N
neliasso 已提交
95
            endTag();
96 97 98

            startTag("Link");
            tagV(cfg.getV("LinkerFlags"));
N
neliasso 已提交
99
            endTag();
100 101 102 103

            startTag("PreLinkEvent");
            tagData("Message", BuildConfig.getFieldString(null, "PrelinkDescription"));
            tagData("Command", cfg.expandFormat(BuildConfig.getFieldString(null, "PrelinkCommand").replace("\t", "\r\n")));
N
neliasso 已提交
104
            endTag();
105

N
neliasso 已提交
106
            endTag();
107 108 109 110 111 112
        }

        writeFiles(allConfigs, projDir);

        tag("Import", "Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
        startTag("ImportGroup", "Label", "ExtensionTargets");
N
neliasso 已提交
113
        endTag();
114

N
neliasso 已提交
115
        endTag();
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
        printWriter.close();
        System.out.println("    Done.");

        writeFilterFile(projectFileName, projectName, allConfigs, projDir);
        writeUserFile(projectFileName, allConfigs);
    }


    private void writeUserFile(String projectFileName, Vector<BuildConfig> allConfigs) throws FileNotFoundException, UnsupportedEncodingException {
        String userFileName = projectFileName + ".user";
        if (new File(userFileName).exists()) {
            return;
        }
        System.out.print("    Writing .vcxproj.user file: " + userFileName);
        printWriter = new PrintWriter(userFileName, "UTF-8");

        printWriter.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        startTag("Project",
                "ToolsVersion", "4.0",
                "xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");

        for (BuildConfig cfg : allConfigs) {
            startTag(cfg, "PropertyGroup");
T
twisti 已提交
139 140 141
            tagData("LocalDebuggerCommand", cfg.get("JdkTargetRoot") + "\\bin\\java.exe");
            tagData("LocalDebuggerCommandArguments", "-XXaltjvm=$(TargetDir) -Dsun.java.launcher=gamma");
            tagData("LocalDebuggerEnvironment", "JAVA_HOME=" + cfg.get("JdkTargetRoot"));
N
neliasso 已提交
142
            endTag();
143 144
        }

N
neliasso 已提交
145
        endTag();
146 147 148 149
        printWriter.close();
        System.out.println("    Done.");
    }

N
neliasso 已提交
150 151 152 153 154 155 156 157
    public void addFilter(String rPath) {
       filters.add(rPath);
    }

    public void addFilterDependency(String fileLoc, String filter) {
      filterDeps.add(new String[] {fileLoc, filter});
    }

158 159 160 161 162 163 164 165 166 167 168 169
    private void writeFilterFile(String projectFileName, String projectName,
            Vector<BuildConfig> allConfigs, String base) throws FileNotFoundException, UnsupportedEncodingException {
        String filterFileName = projectFileName + ".filters";
        System.out.print("    Writing .vcxproj.filters file: " + filterFileName);
        printWriter = new PrintWriter(filterFileName, "UTF-8");

        printWriter.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        startTag("Project",
                "ToolsVersion", "4.0",
                "xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");

        startTag("ItemGroup");
N
neliasso 已提交
170 171 172 173 174
        for (String filter : filters) {
           startTag("Filter", "Include",filter);
           UUID uuid = UUID.randomUUID();
           tagData("UniqueIdentifier", "{" + uuid.toString() + "}");
           endTag();
175 176 177 178 179
        }
        startTag("Filter", "Include", "Resource Files");
        UUID uuid = UUID.randomUUID();
        tagData("UniqueIdentifier", "{" + uuid.toString() + "}");
        tagData("Extensions", "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe");
N
neliasso 已提交
180 181
        endTag();
        endTag();
182

N
neliasso 已提交
183
        //TODO - do I need to split cpp and hpp files?
184

N
neliasso 已提交
185
        // then all files
186
        startTag("ItemGroup");
N
neliasso 已提交
187 188
        for (String[] dep : filterDeps) {
           String tagName = getFileTagFromSuffix(dep[0]);
189

N
neliasso 已提交
190 191 192
           startTag(tagName, "Include", dep[0]);
           tagData("Filter", dep[1]);
           endTag();
193
        }
N
neliasso 已提交
194
        endTag();
195

N
neliasso 已提交
196
        endTag();
197 198 199 200
        printWriter.close();
        System.out.println("    Done.");
    }

N
neliasso 已提交
201 202 203 204 205 206 207 208 209 210 211 212
    public String getFileTagFromSuffix(String fileName) {
       if (fileName.endsWith(".cpp")) {
          return"ClCompile";
       } else if (fileName.endsWith(".c")) {
          return "ClCompile";
       } else if (fileName.endsWith(".hpp")) {
          return"ClInclude";
       } else if (fileName.endsWith(".h")) {
          return "ClInclude";
       } else {
          return"None";
       }
213 214 215
    }

    void writeFiles(Vector<BuildConfig> allConfigs, String projDir) {
N
neliasso 已提交
216 217
       // This code assummes there are no config specific includes.
       startTag("ItemGroup");
218

N
neliasso 已提交
219
       String sourceBase = BuildConfig.getFieldString(null, "SourceBase");
220

N
neliasso 已提交
221 222 223
       // Use first config for all global absolute includes.
       BuildConfig baseConfig = allConfigs.firstElement();
       Vector<String> rv = new Vector<String>();
224

N
neliasso 已提交
225 226 227 228 229 230
       // Then use first config for all relative includes
       Vector<String> ri = new Vector<String>();
       baseConfig.collectRelevantVectors(ri, "RelativeSrcInclude");
       for (String f : ri) {
          rv.add(sourceBase + Util.sep + f);
       }
231

N
neliasso 已提交
232
       baseConfig.collectRelevantVectors(rv, "AbsoluteSrcInclude");
233

N
neliasso 已提交
234
       handleIncludes(rv, allConfigs);
235

N
neliasso 已提交
236
       endTag();
237 238
    }

N
neliasso 已提交
239 240 241 242 243 244 245 246 247 248
    // Will visit file tree for each include
    private void handleIncludes(Vector<String> includes, Vector<BuildConfig> allConfigs) {
       for (String path : includes)  {
          FileTreeCreatorVC10 ftc = new FileTreeCreatorVC10(FileSystems.getDefault().getPath(path) , allConfigs, this);
          try {
             ftc.writeFileTree();
          } catch (IOException e) {
             e.printStackTrace();
          }
       }
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
    }

    String buildCond(BuildConfig cfg) {
        return "'$(Configuration)|$(Platform)'=='"+cfg.get("Name")+"'";
    }

    void tagV(Vector<String> v) {
        Iterator<String> i = v.iterator();
        while(i.hasNext()) {
            String name = i.next();
            String data = i.next();
            tagData(name, data);
        }
    }

    void tagData(BuildConfig cfg, String name, String data) {
        tagData(name, data, "Condition", buildCond(cfg));
    }

    void tag(BuildConfig cfg, String name, String... attrs) {
        String[] ss = new String[attrs.length + 2];
        ss[0] = "Condition";
        ss[1] = buildCond(cfg);
        System.arraycopy(attrs, 0, ss, 2, attrs.length);

        tag(name, ss);
    }

    void startTag(BuildConfig cfg, String name, String... attrs) {
        String[] ss = new String[attrs.length + 2];
        ss[0] = "Condition";
        ss[1] = buildCond(cfg);
        System.arraycopy(attrs, 0, ss, 2, attrs.length);

        startTag(name, ss);
    }
N
neliasso 已提交
285

286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
}

class CompilerInterfaceVC10 extends CompilerInterface {

    @Override
    Vector getBaseCompilerFlags(Vector defines, Vector includes, String outDir) {
        Vector rv = new Vector();

        addAttr(rv, "AdditionalIncludeDirectories", Util.join(";", includes));
        addAttr(rv, "PreprocessorDefinitions",
                Util.join(";", defines).replace("\\\"", "\""));
        addAttr(rv, "PrecompiledHeaderFile", "precompiled.hpp");
        addAttr(rv, "PrecompiledHeaderOutputFile", outDir+Util.sep+"vm.pch");
        addAttr(rv, "AssemblerListingLocation", outDir);
        addAttr(rv, "ObjectFileName", outDir+Util.sep);
        addAttr(rv, "ProgramDataBaseFileName", outDir+Util.sep+"jvm.pdb");
        // Set /nologo option
        addAttr(rv, "SuppressStartupBanner", "true");
        // Surpass the default /Tc or /Tp.
        addAttr(rv, "CompileAs", "Default");
        // Set /W3 option.
        addAttr(rv, "WarningLevel", "Level3");
        // Set /WX option,
        addAttr(rv, "TreatWarningAsError", "true");
        // Set /GS option
        addAttr(rv, "BufferSecurityCheck", "false");
        // Set /Zi option.
        addAttr(rv, "DebugInformationFormat", "ProgramDatabase");
        // Set /Yu option.
        addAttr(rv, "PrecompiledHeader", "Use");
        // Set /EHsc- option
        addAttr(rv, "ExceptionHandling", "");

        addAttr(rv, "MultiProcessorCompilation", "true");

        return rv;
    }

    @Override
    Vector getDebugCompilerFlags(String opt) {
        Vector rv = new Vector();

        // Set /On option
        addAttr(rv, "Optimization", opt);
        // Set /FR option.
        addAttr(rv, "BrowseInformation", "true");
        addAttr(rv, "BrowseInformationFile", "$(IntDir)");
        // Set /MD option.
        addAttr(rv, "RuntimeLibrary", "MultiThreadedDLL");
        // Set /Oy- option
        addAttr(rv, "OmitFramePointers", "false");

        return rv;
    }

    @Override
    Vector getProductCompilerFlags() {
        Vector rv = new Vector();

        // Set /O2 option.
        addAttr(rv, "Optimization", "MaxSpeed");
        // Set /Oy- option
        addAttr(rv, "OmitFramePointers", "false");
        // Set /Ob option.  1 is expandOnlyInline
        addAttr(rv, "InlineFunctionExpansion", "OnlyExplicitInline");
        // Set /GF option.
        addAttr(rv, "StringPooling", "true");
        // Set /MD option. 2 is rtMultiThreadedDLL
        addAttr(rv, "RuntimeLibrary", "MultiThreadedDLL");
        // Set /Gy option
        addAttr(rv, "FunctionLevelLinking", "true");

        return rv;
    }

    @Override
    Vector getBaseLinkerFlags(String outDir, String outDll, String platformName) {
        Vector rv = new Vector();

        addAttr(rv, "AdditionalOptions",
                "/export:JNI_GetDefaultJavaVMInitArgs " +
                "/export:JNI_CreateJavaVM " +
                "/export:JVM_FindClassFromBootLoader "+
                "/export:JNI_GetCreatedJavaVMs "+
                "/export:jio_snprintf /export:jio_printf "+
                "/export:jio_fprintf /export:jio_vfprintf "+
                "/export:jio_vsnprintf "+
                "/export:JVM_GetVersionInfo "+
                "/export:JVM_GetThreadStateNames "+
                "/export:JVM_GetThreadStateValues "+
                "/export:JVM_InitAgentProperties");
377
        addAttr(rv, "AdditionalDependencies", "kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;Wsock32.lib;winmm.lib;psapi.lib");
378 379 380 381 382 383 384 385 386 387 388 389 390 391
        addAttr(rv, "OutputFile", outDll);
        addAttr(rv, "SuppressStartupBanner", "true");
        addAttr(rv, "ModuleDefinitionFile", outDir+Util.sep+"vm.def");
        addAttr(rv, "ProgramDatabaseFile", outDir+Util.sep+"jvm.pdb");
        addAttr(rv, "SubSystem", "Windows");
        addAttr(rv, "BaseAddress", "0x8000000");
        addAttr(rv, "ImportLibrary", outDir+Util.sep+"jvm.lib");

        if(platformName.equals("Win32")) {
            addAttr(rv, "TargetMachine", "MachineX86");
        } else {
            addAttr(rv, "TargetMachine", "MachineX64");
        }

392 393 394
        // We always want the /DEBUG option to get full symbol information in the pdb files
        addAttr(rv, "GenerateDebugInformation", "true");

395 396 397 398 399 400 401
        return rv;
    }

    @Override
    Vector getDebugLinkerFlags() {
        Vector rv = new Vector();

402
        // Empty now that /DEBUG option is used by all configs
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439

        return rv;
    }

    @Override
    Vector getProductLinkerFlags() {
        Vector rv = new Vector();

        // Set /OPT:REF option.
        addAttr(rv, "OptimizeReferences", "true");
        // Set /OPT:ICF option.
        addAttr(rv, "EnableCOMDATFolding", "true");

        return rv;
    }

    @Override
    void getAdditionalNonKernelLinkerFlags(Vector rv) {
        extAttr(rv, "AdditionalOptions", " /export:AsyncGetCallTrace");
    }

    @Override
    String getOptFlag() {
        return "MaxSpeed";
    }

    @Override
    String getNoOptFlag() {
        return "Disabled";
    }

    @Override
    String makeCfgName(String flavourBuild, String platform) {
        return  flavourBuild + "|" + platform;
    }

}