Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing a CMake project into Eclipse CDT

I have a native CMake project, and I want to use the Eclipse IDE with it so that it makes my development easier by providing auto-complete and and other features. I can't seem to find how to import the a CMake project in Eclipse.

PS: I am open for suggestions for other IDE's that work well with CMake.

like image 286
rajat Avatar asked Jul 25 '12 08:07

rajat


People also ask

Does eclipse work with CMake?

Starting with version 2.6. 0 CMake includes a generator for Eclipse CDT 4.0 or newer. It works together with the Makefile generators (i.e. "Unix Makefiles", "MinGW Makefiles", "MSYS Makefiles", and maybe "NMake Makefiles").

Does CMake work for C++?

CMake is a collection of open-source and cross-platform tools used to build and distribute software. In recent years it has become a de-facto standard for C and C++ applications, so the time has come for a lightweight introductory article on the subject.


2 Answers

KDevelop is an awesome IDE with great CMake support.

As for Eclipse - run this:

cd <project_dir> cmake -G "Eclipse CDT4 - Unix Makefiles" ./ 

This will produce Eclipse project for you.

like image 139
arrowd Avatar answered Oct 12 '22 07:10

arrowd


Elaborating on arrowd's answer for Eclipse:

First, choose a directory for the CMake files. I prefer to keep my Eclipse workspaces in ~/workspaces and the source code in ~/src. Data which I need to build or test the project goes in subdirs of the project's workspace dir, so I suggest doing the same for CMake.

Assuming both your workspace and source folders are named someproject, do:

cd ~/workspaces/someproject mkdir cmake cd cmake cmake -G "Eclipse CDT4 - Unix Makefiles" ~/src/someproject 

Then, in your Eclipse workspace, do:

File > Import... > General > Existing Projects into Workspace

Check Select root directory and choose ~/workspaces/someproject/cmake. Make sure Copy projects into workspace is NOT checked.

Click Finish and you have a CMake project in your workspace.

Two things to note:

  • I used cmake for the workspace subdir, but you can use a name of your choice.
  • If you make any changes to your build configuration (such as editing Makefile.am), you will need to re-run the last command in order for Eclipse to pick up the changes.
like image 42
user149408 Avatar answered Oct 12 '22 06:10

user149408