Build from source (CMake)
SWAT+ is built out-of-source. All intermediate and final files go into a separate build directory so the source tree stays clean. The same source tree can host multiple build flavors (different compilers, debug vs release) at the same time.
The build is driven by CMakeLists.txt at the repository root. It globs every .f90 under src/ and links a single executable.
Generate the build files¶
Make swatplus your current working directory.
Configure the build. This processes CMakeLists.txt and writes a build system into build/. It does not compile yet.
The short form is equivalent.
Pick a compiler¶
Default is gfortran. To force it explicitly:
For Intel Fortran, ifort was deprecated in 2024 and removed from the 2025 Intel oneAPI release. Use ifx instead.
On Windows, the Intel compilers need a generator toolset:
cmake -B build -D CMAKE_GENERATOR_TOOLSET=fortran=ifx
cmake -B build -G "Ninja" -D CMAKE_Fortran_COMPILER=gfortran
Note: on Windows, use the default cmd shell, not PowerShell, for the command-line build.
Debug vs release¶
For a debug build with symbols:
For a release build:
Compile and link¶
From the swatplus directory:
Parallelize across CPU cores with -j. Eight is a reasonable default on most laptops.
The executable lands in build/ as swatplus-<version>-<arch>.exe on Windows and without an extension on Linux and macOS. The version part comes from git describe --tags. See Tagging and releases.
To remove all build artifacts and start over:
On Windows cmd:
To clean just the object files and module files while keeping the build configuration:
Install¶
Copy the built executable to a directory of your choice with cmake --install. The --prefix flag sets the base directory.
If you omit --prefix, CMake installs to the system default binary location. You can also skip this step and copy the executable yourself.
Linux note on libgfortran¶
If your Linux distribution does not ship the static libgfortran.a, remove the link_libraries("static") line from CMakeLists.txt and build against the dynamic libgfortran.so. The resulting binary then needs the dynamic libraries present at runtime. Use ldd <binary> to list them.
If you hit a platform-specific compile failure, open an issue on GitHub with your OS, the error output, and any fix you found.