Example importing an enterprise c++ cmake project

We wish to present an example of porting an enterprise level c++ project with a cmake build system to an Eclipse project.  By "enterprise level", we mean hundreds or thousands of files with directory tree depth greater than four; unit testing; in-house, 3rd party and system libraries; version control; multiple build and deploy configurations.

The specifics used here will be mercurial for source control, cppunit for unit testing.  If possible, we will add gmock mock framework.  The cmake project is currently configured for an in-source build.  This is generally frowned upon, but is currently more supported by eclipse.  An added bonus would be redesigning the cmake project and eclipse import to allow for either in-source and out of source build. 

This example will be presented by following the tutorials available on-line, discovering the issues related to each, developing workarounds and concluding with recommendations for improvements for improved c++/cmake project support in Eclipse.  The code base builds on macs with the clang toolchain and on linux with gcc.  As time permits, I will try to expand on these specifics using virtual machines to test the process and configurations more generally.  If you wish to expand any of the sections for other platforms/tools just request permission to contribute to this site (contact me link).


Get the llvm-clang toolchain

Following stackoverflow : (If you’re on Xcode 4.3+) start Xcode, go to Preferences, then to the Downloads section, then the Components tab. Choose to install the Command Line Tools.

Cmake docs
The website for cmake doesn't have any front door access to documentation.  It took a while to find some decent documentation for cmake 2.6.  It looks like, if you download the source and build it yourself with cmake --help-html you can generate your own for more current version.

Although cppunit is very prevelant, it is no longer under active development and seems to be waning in support with eclipse in favor of GoogleTest and Boost frameworks.  If you are starting a new project, you may want to consider one of them.  I am using cppunit because our project is already heavily integrated with it.  This tutorial may be helpful to get started. 
My specs:
MacBook Pro, Mountain Lion, cmake, Eclipse Juno

Let's get started!

The kitware website lists three ways to import a C++/cmake project.  Option 3 uses CMakeBuilder plugin.  I found few resources and it seems to be abandonware.  If there isn't a forum or email list with active participation, I usually avoid that tool. 

Option 1 sounds the simplest.  If you are other than gcc or intel compiler, you will definitely want cmake 2.8.1 or greater as prior to that major functionality of the plugin had a guard for that and failed silently if not.

Option 2 has the most votes (greater than 0!) on stack-overflow for a production system.

We will begin with Option 1.

I add the following to my ~/.bash_profile . 

alias repoeclipsecmake='cmake -D CMAKE_ECLIPSE_VERSION=4.2 -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug -D MACOSX=1 -D CMAKE_C_COMPILER=/usr/bin/cc -D CMAKE_CXX_COMPILER=/usr/bin/c++ -D CMAKE_Fortran_COMPILER=/usr/local/bin/gfortran -j8 .'

The CMAKE_CXX_COMPILER points to /usr/bin/c++ which is the clang compiler
The CMAKE_ECLIPSE_VERSION options doesn't seem to do anything (looking at the source)
-j8 is for 8 core parallel compiling which is much faster.  Adjust to the number of cores on your box.
-G"Eclipse CDT4 - Unix Makefiles" is the flag to generate the .project and .cproject files used by eclipse.

$ source ~/.bash_profile
repository $ repoeclipsecmake
-- runs cmake with the options above

See the slideshow of troubleshooting attempts to get files included correctly.
See video1 and video2 of the existing state of affairs.

Option 2:  This is very similar to the official instructions