Eclipse CDT Project Template - Setting Drop-Down Options
Asked Answered
S

1

2

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.

Seppala answered 21/10, 2015 at 16:7 Comment(0)
B
3

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).

Barbiebarbieri answered 21/10, 2015 at 18:36 Comment(9)
I updated github.com/jonahkichwacoders/example_cdt_template to incorporate this setting if it helps.Barbiebarbieri
This isn't working for me - I don't get anything set. I copied the above and double checked that the value is what is displayed on the drop-down. I also tried it using a value of "gnu.cpp.compiler.dialect.c++11", which is what gets saved in the .cproject, but neither of these work for me.Seppala
Oops - I take that back. What I did above didn't work but when I changed what you recommended to use "gnu.cpp.compiler.dialect.c++11", it worked.Seppala
Now there's just the minor issue that this only works when I launch eclipse with Run As.... Exporting the plugin doesn't seem to be working.Seppala
@Seppala anything in the workspace log? Btw I was missing the inclusion of template/ in build.properties, have a look at GitHub change. If something else, kindly ask another question.Barbiebarbieri
Can you edit the answer to what actually worked if there is a mistake in my example?Barbiebarbieri
It was the missing template/. Also discovered that the '/' is important. I just edited build.properties by hand as template doesn't show up in the list in the eclipse editor. Not sure why but its not in the project at all, which seems a bit odd.Seppala
@Seppala Can you say a little bit more about where were you missing template/ ? I'm trying to follow these instructions and create a template, but for now my CProject (#33093246) works, but C++ does not..Insectivore
In the build.properties file. See github.com/jonahkichwacoders/example_cdt_template/blob/master/…Seppala

© 2022 - 2024 — McMap. All rights reserved.