Eclipse CDT Project Template - Setting Drop-Down O

2019-02-26 22:23发布

问题:

I'm trying to create a New Project template for Eclipse CDT in order to address my question asked here. @Jonah Graham provided a very detailed walk-through in his answer to 1 and this has gotten me most of the way.

However, I can't figure out how to set an option that is specified via a drop-down; e.g. Dialect / Language Standard to ISO C++11 (-std=c++01) on the Settings / Tool Settings / GCC C++ Compiler / Dialect tab. The same issue would arise if I wanted to change the default Optimization or Debug levels, etc.

I thought perhaps this could be accomplished via something like

<process
    type="org.eclipse.cdt.managedbuilder.core.SetMBSStringListOptionValues">
    <simple name="projectName" value="$(projectName)" />
    <complex-array name="resourcePaths">
        <element>
            <simple name="id" value=".*cpp\.compiler\.option\.dialect\.std." />
            <simple-array name="values">
              <element value="gnu.cpp.compiler.dialect.c++11" />
            </simple-array>
            <simple name="path" value="" />
        </element>
    </complex-array>
</process>

Unfortunately, this doesn't seem to have any effect (no errors, but nothing in the resulting .cproject file either).

I can work around this by setting the "Other Dialect" flag, which is just a string, but I'd like to know how to do this via a drop-down since these come up in other places.

回答1:

The way to do this option is to treat it as a string and the internals with change the string value to the enum value. I tested it with C99 (i.e. not C++), for which I used this:

<!--  Set -std=c99 by selecting the enum in the settings -->
<process
    type="org.eclipse.cdt.managedbuilder.core.SetMBSStringOptionValue">
    <simple name="projectName" value="$(projectName)" />
    <complex-array name="resourcePaths">
        <element>
            <simple name="id" value=".*compiler\.option\.dialect\.std.*" />
            <simple name="value" value="ISO C99 (-std=c99)" />
            <simple name="path" value="" />
        </element>
    </complex-array>
</process>

So for your solution I expect this will work. Note that the value is whatever is displayed to the user:

<process
    type="org.eclipse.cdt.managedbuilder.core.SetMBSStringOptionValue">
    <simple name="projectName" value="$(projectName)" />
    <complex-array name="resourcePaths">
        <element>
            <simple name="id" value=".*cpp\.compiler\.option\.dialect\.std." />
            <simple name="value" value="gnu.cpp.compiler.dialect.c++11" />
            <simple name="path" value="" />
        </element>
    </complex-array>
</process>

Compared to your version, I changed the process type and the whole name="value" element (from simple-array to simple plus internal name to display name).