Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] How to programmatically create a CPP project

Chris, Andrew,

  Thank you for pointing me out to this tutorial, it was helpfull.

  Although I am now able to create a project, I fail to link to  source directory. Here is the code I try.

                IProject project = ResourceHelper.createCDTProject("ProjectHelperCreated");
           
                ICProjectDescription projectDescription = CCorePlugin.getDefault().getProjectDescription(project);
                ICConfigurationDescription activeConfiguration = projectDescription.getActiveConfiguration();
                ICSourceEntry[] newSources = new ICSourceEntry[1];
                newSources[0] = new CSourceEntry("ABSOLUTE_PATH", null, 0);
                activeConfiguration.setSourceEntries(newSources);
                projectDescription.setActiveConfiguration(activeConfiguration);
                CoreModel.getDefault().setProjectDescription(project,projectDescription);

It fails getting the project description which is null, I beleive I have to configure it but I am clueless.

  Is there by chance a more detailed tutorial, that explain how to create a real project with source compilation chain, external tool and so on, or at least could you point me to the source code that manage the New Project creation wizzard and the import from existing Makefile C++ project.

Thanks for your patience.
Mathieu


Date: Mon, 9 May 2011 10:05:50 -0400
From: consultchris@xxxxxxxxx
To: cdt-dev@xxxxxxxxxxx
Subject: Re: [cdt-dev] How to programmatically create a CPP project

 
HTH

Chris
 
On Mon, May 9, 2011 at 9:53 AM, Mathieu fourticq <mfourticq2@xxxxxxxxxxx> wrote:
Hi,

  I would like to use the CDT plugin within eclipse, but my C++ project is hudge and needs to be splitted in subproject.
  I need to integrate a dedicated build chain which I manage to do manually using the configuration menus.
  I also need to integrate google test plugin within it. I also managed to do it manually thru the configuration menu

  At that stage I want that all this configuration is done automatically. As a result, I would like to write an eclipse plugin that automatically create within a dedicated workspace my 30 or more necessary projects with the build and test execution configured.
  I made some quick try and manage to list my projects and so on thru an eclipse plugin  but I failed to find which class I must instantiate to create a new CPP project.
 
  I know that your time is precious, but would you be kind enough to give me which class I need to instantiate to create  a C++ project.
 
  Here is the proto I managed to write based on a JDT example I found in the web :
 
 
  // 1. Get the root workspace
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot rootWorkspace = workspace.getRoot();
        
        // 2. create the project
        IProgressMonitor monitor = new IProgressMonitor() {

            @Override
            public void beginTask(String name, int totalWork) {
                System.out.println("beginTask("+ name + ", " + + totalWork + ")");
            }

            @Override
            public void done() {
                System.out.println("done()");
            }

            @Override
            public void internalWorked(double work) {
                System.out.println("internalWorked("+ work + ")");
            }

            @Override
            public boolean isCanceled() {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public void setCanceled(boolean value) {
                // TODO Auto-generated method stub
                
            }

            @Override
            public void setTaskName(String name) {
                // TODO Auto-generated method stub
                
            }

            @Override
            public void subTask(String name) {
                // TODO Auto-generated method stub
                
            }

            @Override
            public void worked(int work) {
                System.out.println("worked("+ work + ")");
                
            }
            
        };
        
        IProject project = rootWorkspace.getProject("MyFirstProject");
        try {
            project.create(monitor);
            project.open(monitor);
        } catch (CoreException e) {
            System.out.println("Failed to create and open project.");
            e.printStackTrace();
        }
        
        IProjectDescription description = project.getDescription();
        String[] natures = description.getNatureIds();
        String[] newNatures = new String[natures.length + 1];
        System.arraycopy(natures, 0, newNatures, 0, natures.length);
        newNatures[natures.length] = CCProjectNature.CC_NATURE_ID;
        description.setNatureIds(newNatures);
        project.setDescription(description, monitor);
        
        
        But at that stage I do not know how to create the C++ project. In JAVA the example is :
        IJavaProject javaProject = JavaCore.create(project);
        What is the equivalent for C++ project.
                   
        If you think there is a nicer way to do it than thru a dedicated plugin, then do not hesitate to point me to another solution.
        
        Thanks for your time and help.

Cheers,
Mathieu Fourticq

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev




--
Chris Andrews

_______________________________________________ cdt-dev mailing list cdt-dev@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/cdt-dev

Back to the top