Skip to main content

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


  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() {

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

            public void done() {

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

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

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

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

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

            public void worked(int work) {
                System.out.println("worked("+ work + ")");
        IProject project = rootWorkspace.getProject("MyFirstProject");
        try {
        } catch (CoreException e) {
            System.out.println("Failed to create and open project.");
        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;
        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.

Mathieu Fourticq

Back to the top