Eclipse CDT: how to programmatically (permanently) save project environment variables

I can programmatically create project environment variables for the properties Project -> C / C ++ Build -> Environment. However, when I restart the workspace, the environment variables disappear.

The code I'm using to add new project environment variables is below:

Global Variables:

private ICConfigurationDescription cfgd = null;
private final MultiCfgContributedEnvironment ce = new MultiCfgContributedEnvironment();

Internal Method:

ICConfigurationDescription[] cfgs;
    cfgs = new ICConfigurationDescription[] {cfgd};
    for (ICConfigurationDescription cfg : cfgs) { 
        ce.addVariable("PKG_CONFIG_LIBDIR", dir, 
        EnvironmentVariable.ENVVAR_APPEND, SEPARATOR, cfg);
    }

I'm looking for a way to save environment variables on the Environment page after restarting the workspace.

+3
source share
2 answers

Another solution not using inner classes / APIs is the following:

IContributedEnvironment environment = CCorePlugin.getDefault().getBuildEnvironmentManager().getContributedEnvironment();
ICProjectDescription projectDescription = CoreModel.getDefault().getProjectDescription(project, true);
ICConfigurationDescription config = projectDescription.getActiveConfiguration(); // or any other configuration...

// Add variable to project configuration
environment.addVariable("PKG_CONFIG_LIBDIR", dir, IEnvironmentVariable.ENVVAR_APPEND, null, config);

// Update project (description)
CoreModel.getDefault().setProjectDescription(project, projectDescription);

, null config / .

"", IEnvironmentVariable.

+3

. , - .

StorableEnvironment, env. vars XML.

UserDefinedEnvironmentSupplier fUserSupplier = EnvironmentVariableManager.fUserSupplier;
StorableEnvironment vars = fUserSupplier.getWorkspaceEnvironmentCopy();
vars.createVariable("PKG_CONFIG_LIBDIR", dir);
fUserSupplier.setWorkspaceEnvironment(vars);

,

org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager;
org.eclipse.cdt.internal.core.envvar.UserDefinedEnvironmentSupplier;

API, , .

+3

All Articles