Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » adding toolchain to c project created by plugin(Unable to add toolchain to c project created by plugin)
adding toolchain to c project created by plugin [message #872701] Wed, 16 May 2012 16:21
tony burton is currently offline tony burton
Messages: 26
Registered: April 2012
Location: France
Junior Member
Hi,
I am trying to create a cproject programmatically and my plugin works, except that I cannot specify the toolchain to be used. My code is the following:

public static IProject createCDTProject(String projectName, String pathInWorkspace, String[] configurationIds) throws OperationCanceledException, CoreException {
		CCorePlugin cdtCorePlugin = CCorePlugin.getDefault();
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
		IWorkspaceRoot root = workspace.getRoot();

		IProject project = root.getProject(projectName);
		IndexerPreferences.set(project, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER);
		resourcesCreated.add(project);

		IProjectDescription prjDescription = workspace.newProjectDescription(projectName);
	
		IPath absoluteLocation = root.getLocation().append(pathInWorkspace);
		//IPath absoluteLocation = URIUtil.toPath(pathInWorkspace);
		prjDescription.setLocation(absoluteLocation);
		
		if (configurationIds!=null && configurationIds.length>0) {
			ICProjectDescriptionManager prjDescManager = cdtCorePlugin.getProjectDescriptionManager();

			project.create(null);
			project.open(null);

			ICProjectDescription icPrjDescription = prjDescManager.createProjectDescription(project, false);
			ICConfigurationDescription baseConfiguration = cdtCorePlugin.getPreferenceConfiguration("org.eclipse.cdt.managedbuilder.core.configurationDataProvider");
			
			for (String cfgId : configurationIds) {
				icPrjDescription.createConfiguration(cfgId, cfgId+" Name", baseConfiguration);
			}
			prjDescManager.setProjectDescription(project, icPrjDescription);
		}
		
		project = cdtCorePlugin.createCDTProject(prjDescription, project, new NullProgressMonitor());
		
		IToolChain[] tcs = ManagedBuildManager.getRealToolChains();
		ToolChain tc=null;
		for (int i=0; i<tcs.length; i++) {
			String str = tcs[i].getName();
			if(str.contains("Cross GCC")) {
				tc = (ToolChain) tcs[i];
				break;
			}
		}
		
		 // Create configuration description
		ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
		IProjectType type = ManagedBuildManager.getProjectType("cdt.managedbuild.target.gnu.cross.exe");
		Assert.isNotNull(type);

		ManagedProject mProj = new ManagedProject(project, type);
		info.setManagedProject(mProj);
//here I try to specify the toolchain:
		IConfiguration cfg = new Configuration(mProj, tc, "cdt.managedbuild.config.gnu.cross.exe", "GNU Toolchain");
		
		waitForProjectRefreshToFinish();
		Assert.isNotNull(project);

		project.open(null);
		Assert.isTrue(project.isOpen());
		
		// add C Nature...
    CProjectNature.addCNature(project, null);
    ICProjectDescription des = CoreModel.getDefault().createProjectDescription(project, false);

		return project;
	}


Could anybody please point out what is going wrong?

Thanks in advance,

Antony
Previous Topic:HELP: Debugger often unresponsive - came from nowhere
Next Topic:Need Eclipse CDT to Implement Interface
Goto Forum:
  


Current Time: Thu Oct 23 12:30:16 GMT 2014

Powered by FUDForum. Page generated in 0.01660 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software