1 Build Instructions for NetCDF-C using CMake {#netCDF-CMake}
2 ===========================================
6 # Overview {#cmake_overview}
8 Starting with netCDF-C 4.3.0, we are happy to announce the inclusion
9 of CMake support. CMake will allow for building netCDF on a wider
10 range of platforms, include Microsoft Windows with Visual Studio.
11 CMake support also provides robust unit and regression testing tools.
12 We will also maintain the standard autotools-based build system in
15 In addition to providing new build options for netCDF-C, we will also
16 provide pre-built binary downloads for the shared versions of netCDF
17 for use with Visual Studio.
20 # Requirements {#cmake_requirements}
21 The following packages are required to build netCDF-C using CMake.
23 * netCDF-C Source Code
24 * CMake version 2.8.12 or greater.
25 * Optional Requirements:
26 * HDF5 Libraries for netCDF4/HDF5 support.
27 * libcurl for DAP support.
30 <img src="deptree.jpg" height="250px" />
33 # The CMake Build Process {#cmake_build}
35 There are four steps in the Build Process when using CMake
37 1. Configuration: Before compiling, the software is configured based on the desired options.
38 2. Building: Once configuration is complete, the libraries are compiled.
39 3. Testing: Post-build, it is possible to run tests to ensure the functionality of the netCDF-C libraries.
40 4. Installation: If all tests pass, the libraries can be installed in the location specified during configuration.
42 For users who prefer pre-built binaries, installation packages are available at \ref winbin
44 ## Configuration {#cmake_configuration}
46 The output of the configuration step is a project file based on the appropriate configurator specified. Common configurators include:
53 ### Common CMake Options {#cmake_common_options}
55 | **Option** | **Autotools** | **CMake** |
56 | :------- | :---- | :----- |
57 Specify Install Location | --prefix=PREFIX | -D"CMAKE\_INSTALL\_PREFIX=PREFIX"
58 Enable/Disable netCDF-4 | --enable-netcdf-4<br>--disable-netcdf-4 | -D"ENABLE\_NETCDF\_4=ON" <br> -D"ENABLE\_NETCDF\_4=OFF"
59 Enable/Disable DAP | --enable-dap <br> --disable-dap | -D"ENABLE\_DAP=ON" <br> -D"ENABLE\_DAP=OFF"
60 Enable/Disable Utilities | --enable-utilities <br> --disable-utilities | -D"BUILD\_UTILITIES=ON" <br> -D"BUILD\_UTILITIES=OFF"
61 Specify shared/Static Libraries | --enable-shared <br> --enable-static | -D"BUILD\_SHARED\_LIBS=ON" <br> -D"BUILD\_SHARED\_LIBS=OFF"
62 Enable/Disable Tests | --enable-testsets <br> --disable-testsets | -D"ENABLE\_TESTS=ON" <br> -D"ENABLE\_TESTS=OFF"
63 Specify a custom library location | Use *CFLAGS* and *LDFLAGS* | -D"CMAKE\_PREFIX\_PATH=/usr/custom_libs/"
65 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`.
67 ### Configuring your build from the command line. {#cmake_command_line}
69 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):
71 > $ cmake [Source Directory]
73 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:
75 > $ cmake [Source Directory] -DCMAKE\_PREFIX\_PATH=/usr/custom_libraries/
77 #### Building with Parallel I/O. {#cmake_parallel_io}
79 NetCDF will build with parallel I/O if the C compiler is an MPI
80 compiler, and HDF5 was built for parallel I/O. To build netcdf-c for
81 parallel I/O, first build HDF5 for parallel I/O, then build netcdf-c
84 > $ CC=mpicc cmake [Source Directory] -DNETCDF\_ENABLE\_PARALLEL_TESTS=ON
86 The parallel I/O tests will only run if the additional configure
87 option is used: NETCDF_ENABLE_PARALLEL_TESTS. Those tests run (by default)
88 with mpiexec, on 4, 16, or 32 processors. If mpiexec cannot be used on
89 your login-nodes, a different command can be used to launch the
90 parallel I/O tests. Used the NETCDF_MPIEXEC option to set a
91 different parallel I/O job launcher:
93 > $ CC=mpicc cmake [Source Directory] -DNETCDF\_ENABLE\_PARALLEL_TESTS=ON -DNETCDF\_MPIEXEC='srun -A account'
95 ## Building {#cmake_building}
97 The compiler can be executed directly with 'make' or the appropriate command for the configurator which was used.
101 Building can also be executed indirectly via cmake:
103 > $ cmake --build [Build Directory]
105 ## Testing {#cmake_testing}
107 Testing can be executed several different ways:
117 > $ cmake --build [Build Directory] --target test
119 ## Installation {#cmake_installation}
121 Once netCDF has been built and tested, it may be installed using the following commands:
127 > $ cmake --build [Build Directory] --target install
129 # See Also {#cmake_see_also}
131 For further information regarding NetCDF and CMake, see \ref cmake_faq