[CMake] CMake with Eclipse CDT (Was: No Subject)

Mike Jackson mike.jackson at imts.us
Mon Feb 26 08:30:52 EST 2007


Yep. Do it all the time. It isn't as integrated as I would like but  
it does work and work pretty good at that.

Here is how I set up my dev env:
   CMake usually likes "out of source" builds BUT Eclipse has some  
problems if your build products are outside the project directory. I  
get around this by creating a "Build" Directory inside my top level  
project directory. This still basically protects the source code from  
contamination from all the build products.
    Next, run cmake or CMakeSetup (Depending what Platform you are  
on) at least once to boot strap the process. This will do the normal  
cmake things.

    Now, back in Eclipse setup a new "Standard C/C++ Make" Project  
using the top level folder as the Project folder. While you are go  
through the "New Project Wizard" there will be a dialog with a bunch  
of tabs, one of those tabs you can control the "Make" command. You do  
NOT want the default command as it will look for a Makefile at the  
top level of the project directory. Your Makefile is in  
"ProjectLocation/Build/Makefile" and so you want to put in your own  
make command that points to that location. The easiest and most  
general way to do this is with the following command:

make -C ${project_loc}/Build

The ${project_loc} is an eclipse variable that will find the absolute  
path to the project.

Basically that is all that is needed. Finish with the New Project  
wizard and then try "Building" your project. It should all just work.

You can add some more integration by creating a new "External Tool"  
that reruns cmake on your source directory. Again, go to the "Run"  
menu, select "External Tools" then "External Tools..." and a new  
dialog pops up. In the "Location" text field, put the full path to  
the "cmake" command. On my OS X box this happens to be /usr/local/bin/ 
cmake. In the "Working Directory" Text field put ${project_loc}/Build  
and in the "Arguments" section put "../". You can make selections in  
the other tabs as you see fit. If you go to the "Common" tab there is  
a check box that will make the command always available in the  
"External Tools" toolbar item.

So, now when you change your CMakeLists.txt file, you can run this  
external tool which will rerun cmake. There is a way to have cmake  
run _every_ time you compile which would obviate the need to manually  
run cmake each time, but I didn't really like it running for no  
reason every time. Once I had settled on a cmakelists.txt file I no  
longer needed it to run every time.

When I want to really "Clean" a project I usually jump to a terminal  
and do the cleaning and rerunning of ccmake from there. Again, you  
can setup an "external tool" to do this for you if you wanted. I have  
never taken the time.

Lastly, The latest official Eclipse (3.2) and CDT (3.2.1) are pretty  
good and recent hardware (Intel dual cores are great but anything in  
the last few years is good) but if you have a large C/C++ project the  
code index can become quite large when dealing with projects like Qt,  
VTK and ITK. Your project folder will grow to over a gigabyte and the  
code completion will slow down after a while. You have two choices:
    Look for files that end with ".pdom" and delete them. This is  
where Eclipse stores the code completion index. The next time Eclipse  
starts up your project the files will be rebuilt. This will drop the  
size but eventually you will have to do this again.
    The other is to try the bleeding edge eclipse/cdt downloads. I am  
currently using Eclipse 3.3M5 and CDT 4.0M5 and the code completion  
is very fast now, the index is reasonably small and the syntax  
highlighting is just awesome. There are some bugs though as these are  
not stable releases but I have found them stable enough for everyday  
use.

Hope all this helps.
-- 
Mike Jackson   Senior Research Engineer
Innovative Management & Technology Services

PS: I have aspirations of writing a CMake syntax highlighting plugin  
for Eclipse but I lack the know how to do such a thing. Instead I  
wrote one for TextMate if you happen to be running OS X....


On Feb 26, 2007, at 7:54 AM, Alexander Ivash wrote:

> Hello, cmake.
>
> Is it possible to use cmake with eclipse for c++ projects ?
>
> -- 
> Best regards,
>  Alexander                          mailto:alexander.ivash at psa- 
> software.com
>
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake




More information about the CMake mailing list