Building Source Code#

This guide has been updated to include detailed instructions for compiling Avogadro on each major operating system and has been verified to work for the 2.0 release on all of them.

However, Avogadro is a large project with many pieces, resulting in a somewhat complex build process that also varies from platform to platform. If you encounter difficulties you are encouraged to reach out on the forum for help.

The Avogadro desktop application brings together several of the Open Chemistry subprojects (see Project Structure). The easiest way to build Avogadro is to use the openchemistry repository as a basis, as it will automatically download and build many of the dependencies (including third-party ones) for you.

It is also entirely possible to build each project individually without using the “superbuild” approach, but you will need to ensure all dependencies are built and can be found by the project.

For simplicity, this guide will focus on the first approach.

The instructions in this guide assume that you know how to execute commands in a terminal.

Tip

Platform-specific instructions, guidance, and information is provided in expandable callouts marked by the respective icons .

System#

Only 64-bit operating systems are supported.

The primary supported operating systems are those for which binaries are distributed:

  • Windows 10+ (x64 only)

  • macOS (Intel and Apple Silicon)

  • Linux (x64 only)

Others may work, but this guide will not cover them.

Dependencies and prerequisites#

Development tools#

The Open Chemistry project uses Git for version control, so the first step is to ensure that you have it installed and set up on your system.

Compiler and build system#

Tip

For those unfamiliar with compiling programs from source, or C++ ones in particular, building a modern C++ program typically uses three critical components:

  • a compiler, which turns source code files into “object” files containing machine code

  • a build tool, which automates the compilation and makes sure all compiler commands are run in the right order

  • a build-system generator, which creates configuration files for a build tool based on a set of instructions; this makes building complex projects on multiple platforms with potentially different build tools and compilers much easier

Broadly, you will need a C/C++ compiler that supports C++17, a build tool such as Ninja, and CMake.

Python and Perl#

To compile Avogadro you will need to have both Python and Perl on your system.

It is important that Python is in the PATH so that Avogadro can find it.

Libraries#

Qt#

Avogadro is built using the open-source Qt framework.

Avogadro is in the process of moving to Qt6, which will be hopefully complete by the release of Avogadro 2.0 – see the forum tracking thread for progress. For now though, you will probably need to obtain Qt5.

Other libraries#

Necessary#

Optional

Many dependencies that Avogadro needs will be automatically downloaded and built during the build process. This means you do not need to install them in advance, and versions will be used that the Avogadro team has determined are compatible.

However, if you would prefer to use versions of these libraries that are installed on your system, you can build Avogadro with CMake flags of the style -DUSE_SYSTEM_EIGEN. For some of them it is also possible to do without them altogether by telling Avogadro to build without the features that require it.

This list includes:

  • glew

  • eigen

  • OpenBabel

  • spglib

  • libarchive

  • msgpackc

  • mmtf-cpp

  • libmsym

Warning

If these libraries are not available on your machine, internet access will be required during the build step.

See Building offline for assistance in circumventing the need for an internet connection.

Getting the source code#

All further instructions will assume you are using git on the command line.

As mentioned above, by far the easiest way to build Avogadro is to use the Open Chemistry repository as a basis, which contains the other projects as submodules. Though building each submodule separately is possible, this “superbuild” approach is the only option we explicitly recommend and support.

The submodules of the main repo can be cloned all in one go, or manually for finer control over which ones are downloaded.

Recursive clone#

You can clone the main repo and all submodules automatically using:

git clone --recursive https://github.com/OpenChemistry/openchemistry.git
git submodule update --init --recursive

You can then later easily update all modules at once using:

git submodule update --remote

See the git submodule documentation for further help.

Manual clone#

You may prefer to only clone some of the submodules, or you may encounter problems with the recursive clone. In this case, you are still recommended to clone the main repo, but take the following manual approach instead:

git clone https://github.com/OpenChemistry/openchemistry.git
cd openchemistry
git clone https://github.com/OpenChemistry/avogadrolibs.git
git clone https://github.com/OpenChemistry/avogadroapp.git

This will overwrite each git submodule with a new normal git repository, and can be continued for as many submodules as desired.

Required and optional submodules#

To build the Avogadro desktop program, only the main Open Chemistry repo and the following submodules are strictly required:

The following submodules are optional and add extra functionality to Avogadro:

More information on the contents of each can be found at Project Structure.

Building Avogadro#

The Open Chemistry project uses CMake to direct builds, so builds are configured and started using the cmake command. This is done in two individual steps.

Again, the following instructions assume you are using the “superbuild” approach.

Configuring CMake#

It is recommended that you create the build tree outside of the source tree.

To set up the build tree, first navigate to the directory containing the cloned openchemistry repository, then run the following command:

cmake -DQT_VERSION=5 -DBUILD_MOLEQUEUE=OFF -S ./openchemistry -B ./build

This will create a new directory, build, in the current directory next to openchemistry, then construct the build tree within it.

To configure the build to build against Qt 6, use -DQT_VERSION=6 instead.

To use a different compiler (such as clang on Linux when the default is gcc), add the flags -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++.

To use a different build tool than whatever the default is on your system, add e.g. -G Ninja.

Build types#

By default, Avogadro will be built in “Debug” mode, which, as the name hints, makes it easier to track down bugs, but at the cost of an increased package size and less optimized (read: slower) code in comparison to “Release” mode.

To change the build type used, use the corresponding flag for cmake during the configuration step, e.g.:

cmake -DQT_VERSION=5 -DBUILD_MOLEQUEUE=OFF -DCMAKE_BUILD_TYPE=Release -S ./openchemistry -B ./build

Possible build types for Avogadro are “Debug”, “Release”, “MinSizeRel” and “RelWithDebInfo”.

Avogadro-specific CMake flags#

Avogadro’s build process can be configured in a variety of ways by passing extra flags to the above cmake command. In particular this is a good way to add extra functionality or to keep the build slim. Here is a non-exhaustive list of some useful ones, with a short explanation and the default.

BUILD_SHARED_LIBS "Build with shared libraries" ON
DOWNLOAD_TO_SOURCE_DIR "Download external dependency source archives to CMAKE_CURRENT_SOURCE_DIR/Downloads" OFF
DOWNLOAD_TO_BINARY_DIR "Download external dependency source archives to CMAKE_CURRENT_BINARY_DIR/Downloads" ON
# If both the above are set to `ON` then the SOURCE directory will be used
# If both the above are set to `OFF` then the user's personal Downloads folder will be used
USE_VTK "Enable libraries that use VTK in Avogadro" OFF
USE_HDF5 "Enable functionality that requires HDF5" OFF
USE_PYTHON "Enable functionality that requires Python" OFF
USE_YAEHMOP "Enable functionality that requires Yaehmop" OFF
USE_SYSTEM_{Dependency} "Use a system installation of {Dependency}" OFF
BUILD_MOLEQUEUE "Build the MoleQueue application" # Default depends on the Qt version
BUILD_AVOGADRO "Build the Avogadro 2 application" ON
BUILD_GPL_PLUGINS "Build GPL plugins, i.e. QTAIM in Avogadro" OFF
BUILD_DOCUMENTATION "Build documentation (Doxygen)" OFF
ENABLE_TESTING "Enable testing for Open Chemistry projects" OFF

To use them, prefix them with -D. For example, to build with the VTK functionality and the automatically generated API documentation, you might run:

cmake -DQT_VERSION=6 -DBUILD_MOLEQUEUE=OFF -DUSE_VTK=ON -DBUILD_DOCUMENTATION=ON -S ./openchemistry -B ./build

The following should, when used, also be passed on to avogadrolibs to configure its build. If the desktop application is being built, they are not particularly useful.

USE_OPENGL "Enable libraries that use OpenGL" ON
USE_LIBARCHIVE "Enable optional Libarchive features" ON
USE_LIBMSYM "Enable optional features using libmsym" ON
USE_SPGLIB "Enable optional features using spglib" ON
USE_MMTF "Enable optional features using mmtf" ON

Likewise, the following should be passed on to avogadroapp when given.

Avogadro_ENABLE_RPC "Enable RPC server" ON

For all available flags, see the CMakeLists.txt file in the top level of each project.

Building offline#

In some situations it may not be possible or desirable to have the build process download the source code for the third-party dependencies during the build itself.

One way to do this is to download the source code manually in advance and place the compressed archives in the source directory under openchemistry/Downloads. This needs to be done for all the dependencies listed as optional dependencies.

Then, when running the above cmake configure step, pass -DDOWNLOAD_TO_SOURCE_DIR=ON as one of the flags.

For this to work, you need to download the exact versions specified in openchemistry/cmake/projects.cmake, in the archive format expected.

The alternative is to turn off the use of each of these dependencies (see above for the necessary flags).

Starting the build#

Once everything is configured, actually building is a simple matter of running:

cmake --build ./build

Layout of the build directory#

Each submodule and project will initially be built within its own directories within the build directory, mirroring the source tree.

When using the “superbuild” strategy detailed here, all compiled libraries, objects, and binaries, as well as all supporting resources such as icons and metadata, are additionally installed to the prefix directory within the build directory, so that everything can be found in one convenient location.

prefix contains the normal include, bin, share and lib subdirectories.

Tip

This can be used to inject an additional prefix in CMAKE_PREFIX_PATH to ensure that projects built by the superbuild are found by each other.

It keeps the sub-projects relatively simple as they either find stuff in the prefix, or normal system paths.

Running executables#

It is recommended that you run the binaries from within the prefix directory in the build directory, e.g.:

./build/prefix/bin/avogadro2

or on Windows:

./build/prefix/bin/avogadro2.exe

On Mac on the other hand it might be:

open /Users/your-user/openchemistry-build/avogadroapp/bin/Avogadro2.app

Building installers#

avogadroapp can build installers for Avogadro.

In order to do this, move into the cd into the appropriate subdirectory within the build tree and call make package. So, to build the Avogadro 2 package:

cd build/avogadroapp
make package

You may need to run cmake-gui, toggle advanced variables and enable/disable packages you are interested in. They are prefixed by CPACK, and can be toggled before calling make package. A binary installer will be created in the build directory.