/zerocode

A C++ library with zero code included

Primary LanguageCMakeMIT LicenseMIT

zerocode

About

This is a C++ library with zero code included1.

zerocode is useful for nothing, though it might contain value as an experiment in modern and minimal C++ project structure.

Building

Dependencies

This project is mainly tested on Ubuntu 22.04, but it should be as portable as CMake is.

This project has zero C or C++ depenendencies.

It does require two tools as build-time dependencies:

  • cmake
  • ninja, make, or another CMake-supported build system
    • CMake defaults to "Unix Makefiles" on POSIX systems

Instructions

Basic Build

This project strives to be as normal and simple a CMake project as possible. This build workflow in particular will work, producing a static zerocode library, ready to package:

cmake -B /some/build/dir -S .
cmake --build /some/build/dir
ctest --test-dir /some/build/dir \
  --output-junit build/xunit/results.xml
DESTDIR=/some/staging/dir cmake --install /some/build/dir --component libzerocode-dev --prefix /opt/zerocode

If all of those steps complete successfully, you should see the library installed in your staging directory.

An example command:

find /some/staging/dir -type f

You will see files like so:

/some/staging/dir
└── opt
    └── zerocode
        ├── include
        │   └── zerocode.hxx
        └── lib
            ├── cmake
            │   └── zerocode
            │       ├── zerocode-noconfig.cmake
            │       └── zerocode.cmake
            ├── libzerocode.a
            └── pkgconfig
                └── zerocode.pc

Manipulating Warnings

To build this project with warnings enabled, simply use CMAKE_CXX_FLAGS as documented in upstream CMake documentation:

cmake -B /some/build/dir -S . -DCMAKE_CXX_FLAGS='-Werror=all -Wno-error=deprecated-declarations'

Otherwise follow the Basic Build workflow as described above.

Sanitizers and Coverage Analysis

To build this project with sanitizers enabled, simply use CMAKE_CXX_FLAGS as documented in upstream CMake documentation. For instance, to enable an address sanitizer build:

cmake -B /some/build/dir -S . -DCMAKE_CXX_FLAGS='-sanitize=address'

Similarly, but enabling coverage analysis:

cmake -B /some/build/dir -S . -DCMAKE_CXX_FLAGS='--coverage'

Otherwise follow the Basic Build workflow as described above.

Usage

From C++

If you really want to use zerocode from your project (why???), you can include zerocode.hxx from your C++ source files

#include <zerocode.hxx>

zerocode supports C++98, C++03, C++11, C++14, C++17, C++20, and C++23. It has no known issues with C++26 or C++29, though there are no compilation toolchains available to test against in those build modes.

Note that zerocode is incidentally compatible with most C dialects, but that behavior is not regularly tested and should be considered unsupported.

From CMake

For consumers using CMake, you will need to use the zerocode CMake module to define the zerocode CMake target:

find_package(zerocode REQUIRED)

You will also need to add zerocode::zerocode to the link libraries of any libraries or executables that include zerocode.hxx in their source or header file.

target_link_libraries(yourlib PUBLIC zerocode::zerocode)

From Other Build Systems

Build systems that support pkg-config by providing a zerocode.pc file. Build systems that support interoperation via pkg-config should be able to detect zerocode for you automatically.

Contributing

Please do! Issues and pull requests are appreciated.

Note that adding more C++ code will be out of scope for this project. Changes that further improve or simplify this project given that goal are appreciated. Enhancements to better support packaging ecosystems would also make sense.

Inspiration

Kelsey Hightower's kelseyhightower/nocode parody repository was an inspiration for this project.

Footnotes

  1. Please note that this project contains strictly more code than kelseyhightower/nocode. zerocode contains some code in CMakeLists.txt files. Objectively, kelseyhightower/nocode is a superior project that should be preferred whenever possible.