Difference between revisions of "CMake"
Baoilleach (Talk | contribs) m (→Building on Windows) |
Baoilleach (Talk | contribs) (Separate content for casual builders from that for developers) |
||
Line 1: | Line 1: | ||
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. | 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. | ||
− | = | + | = Building OpenBabel = |
− | The preferred method of building Open Babel with CMake is to use out of source builds. | + | The preferred method of building Open Babel with CMake is to use "out of source" builds. This means that no generated files are 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: |
<pre>~/src/openbabel | <pre>~/src/openbabel | ||
~/build/openbabel</pre> | ~/build/openbabel</pre> | ||
− | Using this scheme you can | + | Using this scheme you can build OpenBabel as follows: |
<pre>cd ~/build/openbabel | <pre>cd ~/build/openbabel | ||
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr/local/openbabel -DENABLE_TESTS=ON ~/src/openbabel | cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr/local/openbabel -DENABLE_TESTS=ON ~/src/openbabel | ||
− | make | + | make && sudo make install</pre> |
− | This would configure | + | This would configure OpenBabel in the build directory, make all files and install them to the specified prefix. The CMakeCache.txt file contains most stored settings, erasing that will allow you to configure again. |
− | == | + | === Building the Python bindings === |
+ | |||
+ | If you have swig installed and on the PATH, then the Python bindings will be built automatically. The install directory can be set using "-DPYTHON_PREFIX=/my/path". | ||
+ | |||
+ | = Notes for developers = | ||
+ | |||
+ | === Make 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. | 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. | ||
Line 29: | Line 35: | ||
This can be used for all targets by appending '/fast' to the target name. | This can be used for all targets by appending '/fast' to the target name. | ||
− | == Target Naming Conventions == | + | === 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. | 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. | ||
− | == | + | === Useful Cmake Options === |
− | 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. | + | * To see the actual commands used to compile the code (on Linux), run 'make VERBOSE=1' |
+ | * You can build in debug mode with "-DCMAKE_BUILD_TYPE=Debug". | ||
+ | * 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 == | + | === OpenBabel GUI === |
The OpenBabel GUI is built by default if the wxWidgets development libraries are available (on Ubuntu 9.04, libwxgtk2.8-dev; Fedora, wxGTK-devel). On Windows, the WXWIN environment variable should be defined. | The OpenBabel GUI is built by default if the wxWidgets development libraries are available (on Ubuntu 9.04, libwxgtk2.8-dev; Fedora, wxGTK-devel). On Windows, the WXWIN environment variable should be defined. | ||
Line 43: | Line 51: | ||
The GUI build can be explicitly disabled using -DBUILD_GUI=OFF. | The GUI build can be explicitly disabled using -DBUILD_GUI=OFF. | ||
− | == Building on Windows == | + | === Building on Windows === |
There is a batch file, default_build.bat, in the windows-vc2008 folder that runs cmake. Other .bat files called default_build with additional options, e.g. to enable the tests. | There is a batch file, default_build.bat, in the windows-vc2008 folder that runs cmake. Other .bat files called default_build with additional options, e.g. to enable the tests. | ||
− | |||
− | |||
− | |||
− |
Revision as of 03:06, 17 February 2010
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.
Contents
Building OpenBabel
The preferred method of building Open Babel with CMake is to use "out of source" builds. This means that no generated files are 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 build OpenBabel as follows:
cd ~/build/openbabel cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr/local/openbabel -DENABLE_TESTS=ON ~/src/openbabel make && sudo make install
This would configure OpenBabel in the build directory, make all files and install them to the specified prefix. The CMakeCache.txt file contains most stored settings, erasing that will allow you to configure again.
Building the Python bindings
If you have swig installed and on the PATH, then the Python bindings will be built automatically. The install directory can be set using "-DPYTHON_PREFIX=/my/path".
Notes for developers
Make 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.
Useful Cmake Options
- To see the actual commands used to compile the code (on Linux), run 'make VERBOSE=1'
- You can build in debug mode with "-DCMAKE_BUILD_TYPE=Debug".
- 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; Fedora, wxGTK-devel). On Windows, the WXWIN environment variable should be defined.
The GUI build can be explicitly disabled using -DBUILD_GUI=OFF.
Building on Windows
There is a batch file, default_build.bat, in the windows-vc2008 folder that runs cmake. Other .bat files called default_build with additional options, e.g. to enable the tests.