CMake + Visual Studio Installation for Sundials-2.4.0

This document provides step-by-step instructions on building and installing the Sundials libraries on a Windows machine using CMake and Visual Studio.

The setup used here is as follows:

  • Sundials v. 2.4.0
  • CMake v. 2.6.4
  • Visual Studio 2008 v. 9
  • Windows Vista 64-bit Service Pack 1

Obtaining CMake

If CMake is not already available on your system, you can obtain it from cmake.org. Both source and binary distributions are available. The latest version is 2.6.4, released on May 5, 2009.

Preparing the files and directories

The Sundials suite is distributed as a tarball, sundials-2.4.0.tar.gz. Uncompressing it will create the directory sundials-2.4.0 containing the source tree. Next, we create three more directories:

  • sundials-2.4.0-build: a temporary work directory where all intermediate CMake files will be created;
  • sundials-2.4.0-install: this is the directory where the final Sundials exported header files and libraries will be installed (you are, of course, free to install Sundials anywhere else on your system);
  • sundials-2.4.0-examples: this is the directory where the sources, sample output files, and configuration files for the examples distributed with Sundials will be installed. Installing these files is optional; if enabled, the default location is a subdirectory examples/ of the Sundials install directory (i.e.; sundials-2.4.0/examples/ in our case). Here however we opt for installing the examples outside the Sundials install tree.

After these steps, we will therefore have the following directories:

directories-1.png

CMake configuration

After starting CMake the first step is to specify the location of the source files and the directory where the binaries will be built (the directory sundials-2.4.0-build created above) after which you press the Configure button. You may be prompted to select/confirm the target build system.

cmake-1.png

After selecting the target build system ("Visual Studio 9 2008" in this example) CMake will present you with the first set of configuration options:

cmake-2.png

As you can see, all current options are highlighted in red, indicating that we have yet to accept them by pressing Configure a second time. In our case, we will accept all the options as suggested, except for the following two:

  • CMAKE_INSTALL_PATH which we modify to point to the directory where we wish to install Sundials (the directory sundials-2.4.0-install that we created previously);
  • EXAMPLES_ENABLE which we change to ON, indicating that we also want the examples to be built, in addition to the Sundials libraries.

Note that by accepting most of the default option values we will build static libraries for all Sundials solvers with no parallel support and no Lapack support!

Pressing Configure now will result in all current option fields to be grayed-out (indicating that we have accepted them). However, by enabling compilation of the Sundials examples we have activated a couple more configuration options which are now highlighted in red:

cmake-3.png

The new options allow us to indicate whether we wish to install the example files or not (note that in the previous step we only indicated that we want them to be compiled and built) and if yes, where they should be installed. In this example, we decide to also install the example files in the directory sundials-2.4.0-example that we created previously.

Pressing Configure a final time will now finalize the iterative CMake configuration process. No new options will be presented and the OK button is now activated:

cmake-4.png

After pressing OK CMake will complete the configuration and quit.

Building the Sundials libraries

Note that CMake does not build the Sundials libraries, but only creates the configuration files for the target build system, Visual Studio in our case. Indeed, the result of the configuration performed in the previous steps is a VS solution file located in the sundials-2.4.0-build directory:

directories-2.png

Opening the sundials.sln solution file with VS will reveal a plethora of projects, one for each Sundials solver library and one for every single example (if, as in our case, building the examples was enabled at configuration time). In addition there are two special VS projects that were included in this VS solution by CMake:

  • ALL_BUILD: building this VS project will build the Sundials libraries and examples;
  • INSTALL: building this VS project will build and install the Sundials libraries and examples.
vs-1.png

Note: Before actually building Sundials we need to take care of a minor bug: the IDAS example idasRoberts_FSA_dns is not ANSI-C compliant (it contains a variable declaration that is not located at the beginning of the function) and, by default, Visual Studio is quite strict in this regard. Instead of modifying the source, we opt for setting-up VS to compile this one file as a C++ code (which allows declarations placed anywhere within the code block).

After building the VS project INSTALL we get:

vs-2.png

We can now quit VS and verify the installation of the Sundials libraries and header files:

directories-3.png

and of the example sources and sample output files:

directories-4.png

Building an example using the installed libraries

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.