# The SC Library

This is the `README` file for `libsc`.

The SC Library provides support for parallel scientific applications.

    Copyright (C) 2010 The University of Texas System
    Additional copyright (C) 2011 individual authors

`libsc` is written by Carsten Burstedde, Lucas C. Wilcox, Tobin Isaac, and
others.  `libsc` is free software released under the GNU Lesser General
Public Licence version 2.1.

Please see `doc/release_notes.txt` for the latest updates.

The official web page for source code and documentation is
[p4est.org](https://www.p4est.org/).
Please send bug reports and ideas for contribution to `p4est@ins.uni-bonn.de`.
You are also welcome to post issues on
[github](https://www.github.com/cburstedde/libsc.git).
Please see the `CONTRIBUTING` file and
our [coding standards](doc/coding_standards.txt) for details.

## Building `libsc`

The build instructions for `p4est` also apply to standalone builds of `libsc`.
Dependencies (Debian):

 - `zlib1g-dev` activates functionality for compression and checksums.
 - `libjansson-dev` activates parsing of JSON configuration files.

### Autotools

The autotools build chain is fully supported.

In a fresh checkout, you may run `./bootstrap` to create the `configure`
script.  Calling `make` will regenerate the tools configuration as needed.
Only in rare cases `./bootstrap` will have to be run again.  The script depends
on existing `autoconf`, `automake`, `libtool` and `pkg-config` tools.

Calling `bootstrap` is *not* required for unpacked `tar` archives, or after
pulling fresh code.  It *is* required before running `make distcheck`.

We recommend running `configure` with a relative path from an empty build
directory.  Try

    ./configure --help

for options and switches.  For development with MPI:

    cd empty/build/directory
    ../relative/path/to/configure --enable-mpi --enable-debug \
        CFLAGS="-O0 -g -Wall -Wextra -Wno-unused-parameter"
    make -j8

Setting the `V=1` environment variable would re-activate make echo, the
spelling out of all bulid commands by `make`.
To run tests in parallel, run (the `-j` switch is optional)

    make -j4 check

### Create a tarball

To pack a distribution tarball, call `./bootstrap` and e.g.

    mkdir -p build && cd build && ../configure
    make -j3 distcheck

### CMake

For builds that work on Windows as well as MacOS and Linux, and
that are easily usable from other CMake projects, `libsc` can be built directly,
or used via `FetchContent` or `ExternalProject` from other CMake projects.

Per default MPI is disabled and the build configuration is `RelWithDebInfo`.
To configure and build from the source directory, run:

    cmake -B build
    cmake --build build --parallel

To configure and build from an empty build directory, run:

    cd empty/build/directory
    cmake path/to/source
    cmake --build . --parallel

To enable JSON via jansson, first install the
[jansson CMake project](https://github.com/akheron/jansson), then specify path where you
installed jansson to CMake, say ~/local:

    cmake -B build -Djansson_ROOT=~/local

To enable MPI:

    cmake -B build -Dmpi=on

To compile with debug options:

    cmake -B build -DCMAKE_BUILD_TYPE=Debug

Optionally, run self-tests in parallel:

    ctest --test-dir build -j

Optionally, install `libsc` like:

    cmake -B build -DCMAKE_INSTALL_PREFIX=~/local
    cmake --build build --parallel
    cmake --install build

The optional examples can be built and tested like:

    cmake -S example -B example/build -DSC_ROOT=~/local
    cmake --build example/build
    ctest --test-dir example/build -j

For developers, source and binary distribution packages can be generated by:

    cmake -B build -DCMAKE_INSTALL_PREFIX=~/local
    cmake --build build --parallel
    cpack --config build/CPackSourceConfig.cmake
    cpack --config build/CPackConfig.cmake

which creates files:

 * `build/package/SC-<version>-Source.tar.gz` containing source code
 * `build/package/SC-<version>-<platform>.tar.gz` containing binary libraries
    and executables suitable for computers of same operating system and compatible
    CPU arch

Note that the tarball from CPack is structured differently from the one
built using the autotools (see above).  Only the latter adheres to the GNU
file system standards and is recommended for releases.

On Windows above cpack command will yield `.zip`-Files.
