Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Programatically create CDT project

Hi Stephen,

On Fri, Dec 19, 2008 at 1:19 PM, Kennedy, Stephen M (Steve) <stevekennedy@xxxxxxxxxxxxxxxxxx> wrote:

We have a plug-in that relies on the code-browsing capabilities of CDT.  Currently we have a perl script that pre-creates/populates a directory in the workspace and we tell the users to go to the C++ Project wizard, type the project, select our project type and hit Finish.  The users, of course, would like the project creation to be part of the magic script also.

Our project type/tool chain is a stripped down version of the gcc toolchain and simply provides an alternative implementation of the scannerInfoCollector (reads the settings from a file created by the magic script).  We currently don't support "building" with our toolchain.

I can create a CDT project but have had no luck in figuring out how to set the project type/toolchain/configuration to our custom one.  I think I need to do what MBSWizardHandler.createProject() does but there seems to be several internal classes used in that method.

Any ideas or pointers would be welcome.

I just posted a few days ago an example of creating Standard Make
Here is an example for Managed project.  

import org.eclipse.cdt.managedbuilder.testplugin.BuildSystemTestHelper;
import org.eclipse.cdt.managedbuilder.testplugin.CTestPlugin;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;

CoreModel coreModel = CoreModel.getDefault();
ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager();

String pluginProjectTypeId = "";
String projectName = "testExecutableCygwinGcc";

// Create model project and accompanied descriptions
IProject project = BuildSystemTestHelper.createProject(projectName);
// Create project description
ICProjectDescription des = coreModel.createProjectDescription(project, false);
Assert.assertNotNull("createDescription returned null!", des);

// Create one configuration description
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
IProjectType type = ManagedBuildManager.getProjectType(pluginProjectTypeId);
Assert.assertNotNull("project type not found", type);

ManagedProject mProj = new ManagedProject(project, type);

IConfiguration cfgs[] = type.getConfigurations();
Assert.assertNotNull("configurations not found", cfgs);
Assert.assertTrue("no configurations found in the project type",cfgs.length>0);

for (IConfiguration configuration : cfgs) {
String id = ManagedBuildManager.calculateChildId(configuration.getId(), null);
Configuration config = new Configuration(mProj, (Configuration)configuration, id, false, true, false);
CConfigurationData data = "">
Assert.assertNotNull("data is null for created configuration", data);
ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
Assert.assertEquals(2, des.getConfigurations().length);

// Persist project description.
coreModel.setProjectDescription(project, des);


I hope you'll find that instructive.


Steve Kennedy

cdt-dev mailing list

Back to the top