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

Hi Mathieu,
CDT Developer FAQ can give you some pointers to the code samples.

Thanks,
Andrew

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



Back to the top