YAC 3.21.0
Yet Another Coupler
Loading...
Searching...
No Matches
CMake

YAC includes experimental CMake support as an alternative to the Autotools build system. The CMake build system supports all features including:

  • Building all YAC libraries (core, utils, MCI) with C and Fortran interfaces
  • Python bindings
  • Tools
  • Examples and tests
  • All configuration options (NetCDF, OpenMP, LAPACK, etc.)

The CMake build system requires CMake version 3.18 or later.

YAC's version has the form MAJOR.MINOR.PATCH (e.g. 3.18.0). Between regular releases, an interim fix may add a tweak number, shown as e.g. 3.18.0p1 when built with Autotools or CMake, or as 3.18.0.post1 if installed via pip (following Python's versioning convention). Regular releases always report a plain MAJOR.MINOR.PATCH, no matter which build system or installation method you used.

Basic CMake Usage

Create a build directory and configure:

cd <yac_repo_dir>
mkdir build_cmake
cd build_cmake
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_TESTING=ON \
-DYAC_ENABLE_PYTHON=ON \
-Dyaxt_ROOT=<yaxt_inst_dir> \
-DCMAKE_INSTALL_PREFIX=<yac_inst_dir> \
..

Build and test:

cmake --build . --parallel 8
ctest --output-on-failure --parallel 8

Install:

cmake --install .
Note
cmake --install installs the YAC libraries, headers and tools, but not the Python bindings. If they were enabled with -DYAC_ENABLE_PYTHON=ON, they are assembled in the python subdirectory of the build directory and can be installed into a Python environment of your choice with pip install <yac_build_dir>/python. See Installation from a YAC build directory for details. If you only need the Python bindings, consider installing YAC with pip directly, see Installation.

CMake Configuration Options

The most important configure options are:

  • BUILD_SHARED_LIBS - Build shared libraries (default: ON)
  • BUILD_TESTING - Enable tests (default: OFF)
  • YAC_ENABLE_MCI - Enable Model Coupling Interface (default: ON)
  • YAC_ENABLE_TOOLS - Enable tools (default: ON, requires MCI)
  • YAC_ENABLE_FORTRAN - Enable Fortran bindings (default: ON)
  • YAC_ENABLE_PYTHON - Enable Python bindings (default: OFF)
  • YAC_ENABLE_NETCDF - Enable NetCDF support (default: ON)

For a full list of options run cmake -LH or use ccmake.

Specifying Dependency Locations

If dependencies are not in standard locations, you can specify their paths via

cmake -Dyaxt_ROOT=<yaxt_inst_dir> \
-DNetCDF_ROOT=<netcdf_dir> \
-Dlibfyaml_ROOT=<libfyaml_dir> \
..

or by defining the respective environment variables before executing cmake ...

Using YAC in Downstream CMake Projects

YAC provides a CMake configuration file that can be used with find_package:

find_package(YAC REQUIRED)
target_link_libraries(your_target YAC::yac_mci)

YAC also supports optional COMPONENTS to require specific libraries or build-time features:

find_package(YAC REQUIRED COMPONENTS mci Fortran)
target_link_libraries(your_target YAC::yac_mci)

If a requested component is unavailable (e.g. YAC was built with YAC_ENABLE_FORTRAN=OFF), find_package fails with an error naming the missing component(s). Components can also be requested without REQUIRED, in which case YAC_<Component>_FOUND can be checked manually:

find_package(YAC COMPONENTS Fortran)
if(YAC_Fortran_FOUND)
# ...
endif()

Available components:

  • Libraries (map to an exported target YAC::yac_<name>): utils, mci
  • Features (map to a YAC_ENABLE_<NAME> build option, no dedicated target): Fortran, NetCDF, OpenMP, Python, Tools

To guide CMake to find YAC set YAC_ROOT to the build or install directory.

If you encounter any issues with the CMake build system, please consider reporting them.