Eclipse CDT4 Generator: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
Line 74: Line 74:
This linked resource isn't created if the build directory is a subdirectory of the source directory, because Eclipse doesn't allow to load projects which have linked resources pointing to a parent directory.
This linked resource isn't created if the build directory is a subdirectory of the source directory, because Eclipse doesn't allow to load projects which have linked resources pointing to a parent directory.
So we recommend to create your build directories not as children, but e.g. as siblings to the source directory.
So we recommend to create your build directories not as children, but e.g. as siblings to the source directory.
# One project for version management. This one may be obtained by a normal ''checkout'' using new project from CVS/Subversion/etc. .
# One or more projects for building, resulting from the imported CMake generated project(s) obtained by the previously described procedure.


==Discussion about Eclipse CDT4 Generator limitations==
==Discussion about Eclipse CDT4 Generator limitations==

Revision as of 22:19, 19 February 2008

Overview

Eclipse opens CMake project file

Starting with version 2.6.0 CMake includes an Eclipse CDT 4.0 generator. It works together with the Makefile generators (i.e. "Unix Makefiles", "MinGW Makefiles", "MSYS Makefiles", and maybe "NMake Makefiles"). This generator creates a set of .project/.cproject files that can be imported in Eclipse as an "Existing Eclipse project".

Note that CMake 2.4.x users may follow instructions provided here CMake:Eclipse in order to setup an Eclipse+CMake usage manually.


Using Eclipse CDT4 Generator

Using the Eclipse CDT4 generator is not different as using another CMake generator, it works for in-source and out-of-source builds. In this example I assume the source tree of my project is /home/eric/certi_src

  1. Create a build directory, go there and run CMake:
    mkdir /home/eric/certi_build 
    cd /home/eric/certi_build
    cmake -G"Eclipse CDT4 - Unix Makefiles" ../certi_src

    After that you will find two Eclipse files in your build tree:

    1. certi_build/.project
    2. certi_build/.cproject
  2. Import the created project file into Eclipse:
    1. Launch eclipse
    2. Import project using Menu File->Import
      Eclipse Menu->File->Import
    3. Select General->Existing projects into workspace:
      Existing Projects into Workspace
    4. Browse where your build tree is and select the root build tree directory. Keep "Copy projects into workspace" unchecked.
      Eclipse Import after build tree selection
    5. You get a fully functional eclipse project
      Eclipse Imported CERTI project

In-Source Builds

In-Source builds are fully supported by the Eclipse project generator.

Out-Of-Source Builds

Eclipse has two issues with out-of-source builds, the project generator tries to work around them as good as possible. The details are described below.

Version Control Integration in Eclipse

Eclipse supports version control systems, e.g. cvs and svn, but for them to work the project files must be at the root of the source tree. This is not the case with out-of-source builds. The only way to get version control for your project in Eclipse is to have a separate project in the source tree for this purpose. You can create this project either manually (screen cast showing how to do this: File:CMakeEclipseCDT4andCVS-2.ogg), or you can tell CMake to do it for when creating your project files:

cmake -G"Eclipse CDT4 - Unix Makefiles" -DECLIPSE_CDT4_GENERATE_SOURCE_PROJECT ../certi_src

This will create your normal project in the build tree and additionally an extra project in the source tree, we call it the "source-project". In Eclipse you can then import this source-project the same way as you import the normal project. This way you'll have two (or more) projects, one for browsing the sources and doing version control, the other for building your project.

Accessing the Source and Advanced Editing Features

Eclipse has advanced support for editing C/C++ sources, including code navigation, autocompletion etc. For that to work the sources must be inside the project (the additional source-project from above is not inside the project). The Eclipse project generator therefor creates a linked resource to the source tree in the Eclipse project. This makes the C/C++ features work.

This linked resource isn't created if the build directory is a subdirectory of the source directory, because Eclipse doesn't allow to load projects which have linked resources pointing to a parent directory. So we recommend to create your build directories not as children, but e.g. as siblings to the source directory.

Discussion about Eclipse CDT4 Generator limitations

If you would like to monitor the changes to the EclipseCDT4 support, you can view the following links which contain the cvs history log for changes to the two main files:


Eclipse assumes project files (i.e. .project and .cproject) must be at the root of the project tree and a project may be handled by a versioning system (CVS, SVN, ...) iff the root project tree is.

This assumption clashes with the fact that CMake generated files should stay in the build tree whereas source files (which are usually those handled by a versioning system) reside in the source tree.

There has been a fair amount of discussion regarding this problem of the Eclipse CDT4 Generator:

  1. Trouble with CMake + Eclipse + SVN/CVS
  2. *Updated* Eclipse CDT4 CMake Generator - Pre-Alpha version
  3. Partially Shared project using Eclipse CDT (cdt-dev ML)



CMake: [Welcome | Site Map]