CMake

From Open Babel
Revision as of 02:58, 11 September 2009 by Baoilleach (Talk | contribs) (Building on Windows: Clash with INSTALL)

Jump to: navigation, search

Open Babel trunk (destined to become openbabel-2.3) will use CMake as its primary build system. CMake works a little differently to autotools. This page will document some of those differences to help you familiarize with it.

Out of Source Builds

The preferred method of building Open Babel with CMake is to use out of source builds. No generated file should be placed in the source directory. This ensures good separation between source and build files. You can use whatever directory structure you prefer, one possible directory layout is

~/src/openbabel
~/build/openbabel

Using this scheme you can configure openbabel using

cd ~/build/openbabel
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr/local/openbabel -DENABLE_TESTS=ON ~/src/openbabel
make -j5 && sudo make install

This would configure openbabel in the build directory, make all files and install them to the specified prefix with all debug symbols. The CMakeCache.txt file contains most stored settings, erasing that will allow you to configure again.

Making Individual Targets

CMake has good dependency tracking, but it uses timestamps (as most build systems do) to indicate a file has changed. As such anytime that the openbabel library is rebuilt all of the plugins/executables that link to it are relinked. This can lead to excessive amounts of time spent waiting for everything to relink, when the ABI has in fact not changed. By making individual parts of the project these relinks can be avoided.

make openbabel       # Rebuild the openbabel libary
make help            # List available build targets

The dependency tracking can also take time when building plugins. CMake adds an additional target that has no dependency tracking, and can be used if working on the CML format for example,

make cmlformat/fast

This can be used for all targets by appending '/fast' to the target name.

Target Naming Conventions

Formats are named after their source files, e.g. cmlformat.[h|cpp] -> cmlformat. The openbabel library target is named openbabel (currently openbabel-2 on Windows). The executable targets are named after the corresponding executable, e.g. babel. Any of these target names can be used as shown above to rebuild specific parts, this can save a lot of time when working on one specific aspect of Open Babel.

Minimal build

On occasion, developers may find it useful to use the option -DMINIMAL_BUILD=ON. This option just compiles the Smiles and SDF formats, and of the tools just babel.

OpenBabel GUI

The OpenBabel GUI is built by default if the wxWidgets development libraries are available (on Ubuntu 9.04, libwxgtk2.8-dev). On Windows, the WXWIN environment variable should be defined.

The GUI build can be explicitly disabled using -DBUILD_GUI=OFF.

Building on Windows

The following command-lines create a MSVC++ 2008 solution file in a 'build' directory, which when compiled will install to an 'installed' directory. We will probably create a batch file to simplify this.

rmdir /s build
mkdir build
cd build
"C:\Program Files\CMake 2.6\bin\cmake.exe" -DCMAKE_INSTALL_PREFIX=..\installed -G "Visual Studio 9 2008" 
   -DLIBXML2_LIBRARIES=..\windows-vc2005\libxml2.lib -DLIBXML2_INCLUDE_DIR=. 
   -DZLIB_LIBRARY=..\windows-vc2005\zlib1.lib -DZLIB_INCLUDE_DIR=. ..