2014-03-01 08:12:34 +08:00
Build Instructions for NetCDF-C using CMake {#netCDF-CMake}
===========================================
2013-02-13 06:22:54 +08:00
2014-02-25 07:06:09 +08:00
[TOC]
2013-08-30 07:04:26 +08:00
2014-02-25 07:06:09 +08:00
# Overview {#cmake_overview}
2013-02-13 06:22:54 +08:00
2013-08-10 01:14:07 +08:00
Starting with netCDF-C 4.3.0, we are happy to announce the inclusion of CMake support. CMake will allow for building netCDF on a wider range of platforms, include Microsoft Windows with Visual Studio. CMake support also provides robust unit and regression testing tools. We will also maintain the standard autotools-based build system in parallel.
2013-02-13 06:22:54 +08:00
In addition to providing new build options for netCDF-C, we will also provide pre-built binary downloads for the shared versions of netCDF for use with Visual Studio.
2013-05-09 05:59:11 +08:00
2014-02-25 07:06:09 +08:00
# Requirements {#cmake_requirements}
2013-02-13 06:22:54 +08:00
The following packages are required to build netCDF-C using CMake.
* netCDF-C Source Code
2014-07-30 04:53:12 +08:00
* CMake version 2.8.12 or greater.
2013-02-13 06:22:54 +08:00
* Optional Requirements:
* HDF5 Libraries for netCDF4/HDF5 support.
* libcurl for DAP support.
< center >
2013-02-21 07:28:28 +08:00
< img src = "deptree.jpg" height = "250px" / >
2013-02-13 06:22:54 +08:00
< / center >
2014-02-25 07:06:09 +08:00
# The CMake Build Process {#cmake_build}
2013-02-13 06:22:54 +08:00
There are four steps in the Build Process when using CMake
1. Configuration: Before compiling, the software is configured based on the desired options.
2. Building: Once configuration is complete, the libraries are compiled.
3. Testing: Post-build, it is possible to run tests to ensure the functionality of the netCDF-C libraries.
4. Installation: If all tests pass, the libraries can be installed in the location specified during configuration.
For users who prefer pre-built binaries, installation packages are available at \ref winbin
2014-02-25 07:06:09 +08:00
## Configuration {#cmake_configuration}
2013-02-13 06:22:54 +08:00
The output of the configuration step is a project file based on the appropriate configurator specified. Common configurators include:
* Unix Makefiles
* Visual Studio
* CodeBlocks
* ... and others
2014-02-25 07:06:09 +08:00
### Common CMake Options {#cmake_common_options}
2013-02-13 06:22:54 +08:00
| **Option** | **Autotools** | **CMake** |
2013-06-05 01:33:21 +08:00
| :------- | :---- | :----- |
2013-02-13 06:22:54 +08:00
Specify Install Location | --prefix=PREFIX | -D"CMAKE\_INSTALL\_PREFIX=PREFIX"
Enable/Disable netCDF-4 | --enable-netcdf-4< br > --disable-netcdf-4 | -D"ENABLE\_NETCDF\_4=ON" < br > -D"ENABLE\_NETCDF\_4=OFF"
Enable/Disable DAP | --enable-dap < br > --disable-dap | -D"ENABLE\_DAP=ON" < br > -D"ENABLE\_DAP=OFF"
Enable/Disable Utilities | --enable-utilities < br > --disable-utilities | -D"BUILD\_UTILITIES=ON" < br > -D"BUILD\_UTILITIES=OFF"
Specify shared/Static Libraries | --enable-shared < br > --enable-static | -D"BUILD\_SHARED\_LIBS=ON" < br > -D"BUILD\_SHARED\_LIBS=OFF"
Enable/Disable Tests | --enable-testsets < br > --disable-testsets | -D"ENABLE\_TESTS=ON" < br > -D"ENABLE\_TESTS=OFF"
2013-06-05 01:33:21 +08:00
Specify a custom library location | Use *CFLAGS* and *LDFLAGS* | -D"CMAKE\_PREFIX\_PATH=/usr/custom_libs/"
A full list of *basic* options can be found by invoking `cmake [Source Directory] -L` . To enable a list of *basic* and *advanced* options, one would invoke `cmake [Source Directory] -LA` .
2014-02-25 07:06:09 +08:00
### Configuring your build from the command line. {#cmake_command_line}
2013-06-05 01:33:21 +08:00
The easiest configuration case would be one in which all of the dependent libraries are installed on the system path (in either Unix/Linux or Windows) and all the default options are desired. From the build directory (often, but not required to be located within the source directory):
2014-02-06 04:19:00 +08:00
> $ cmake [Source Directory]
2013-06-05 01:33:21 +08:00
If you have libraries installed in a custom directory, you may need to specify the **CMAKE\_PREFIX_PATH** variable to tell cmake where the libraries are installed. For example:
2014-02-06 04:19:00 +08:00
> $ cmake [Source Directory] -DCMAKE\_PREFIX\_PATH=/usr/custom_libraries/
2013-06-05 01:33:21 +08:00
2014-02-25 07:06:09 +08:00
## Building {#cmake_building}
2013-02-13 06:22:54 +08:00
The compiler can be executed directly with 'make' or the appropriate command for the configurator which was used.
2014-02-06 04:19:00 +08:00
> $ make
2013-02-13 06:22:54 +08:00
Building can also be executed indirectly via cmake:
2014-02-06 04:19:00 +08:00
> $ cmake --build [Build Directory]
2013-02-13 06:22:54 +08:00
2014-02-25 07:06:09 +08:00
## Testing {#cmake_testing}
2013-02-13 06:22:54 +08:00
Testing can be executed several different ways:
2014-02-06 04:19:00 +08:00
> $ make test
2013-05-09 05:59:11 +08:00
2013-02-13 06:22:54 +08:00
or
2013-05-09 05:59:11 +08:00
2014-02-06 04:19:00 +08:00
> $ ctest
2013-05-09 05:59:11 +08:00
2013-02-13 06:22:54 +08:00
or
2013-05-09 05:59:11 +08:00
2014-02-06 04:19:00 +08:00
> $ cmake --build [Build Directory] --target test
2013-02-13 06:22:54 +08:00
2014-02-25 07:06:09 +08:00
## Installation {#cmake_installation}
2013-02-13 06:22:54 +08:00
Once netCDF has been built and tested, it may be installed using the following commands:
2014-02-06 04:19:00 +08:00
> $ make install
2013-05-09 05:59:11 +08:00
2014-02-06 04:19:00 +08:00
or
2013-05-09 05:59:11 +08:00
2014-02-06 04:19:00 +08:00
> $ cmake --build [Build Directory] --target install
2013-05-09 05:59:11 +08:00
2014-02-25 07:06:09 +08:00
# See Also {#cmake_see_also}
2013-08-10 01:14:07 +08:00
2014-03-01 08:12:34 +08:00
For further information regarding NetCDF and CMake, see \ref cmake_faq