|
C Container Collection (CCC)
|
Currently, this library utilizes some features that many compilers support such as gcc, clang, and AppleClang, but support is not ready for Windows. The C Container Collection supports freestanding environments.
By default the C Container Collection offers a cohesive set of robust containers. However, some users may have niche runtime or space requirements. Therefore, there is a ccc-specialized-[VERSION].zip release available on the releases page. Obtaining either will not affect these build instructions. If the specialized/ directories are found, their files will be compiled. If they are absent, they are ignored. However, if you wish to force only compilation of the core library when all specialized/ directories are present, use the following CMake cache variable.
On the command line.
As a CMake cache variable.
This will likely not affect users as much as developers but the instruction is provided for completeness.
This approach will allow CMake to build the collection from source as part of your project. The collection does not have external dependencies, besides the standard library, so this may be viable for you. This is helpful if you want the ability to build the library in release or debug mode along with your project and possibly step through it with a debugger during a debug build. If you would rather link to the release build library file see the next section for the manual install.
To avoid including tests, samples, and other extraneous files when fetching content download a release.
To link against the library in the project use the ccc namespace.
Here is a concrete example with an arbitrary release that is likely out of date. Replace this version with the newest version on the releases page.
Now, the C Container Collection is part of your project build, allowing you to configure as you see fit. For a more traditional approach read the manual install section below.
If you wish to track the bleeding edge of the collection, you can track the main release archive. GitHub maintains a zip file of the repository by default at https://github.com/SkeletOSS/ccc/archive/refs/heads/main.zip. This archive file respects the current .gitattributes file, producing a clean repository snapshot free of unnecessary files, similar to release archives. Change the FetchContent_Declare command as follows.
Keep in mind a few points about what you are opting in to if you take this approach.
Use this method if you don't care about versioning and want the latest changes. Prefer this method for consuming the library over fetching or cloning the main branch; cloning the main branch directly will download many unneeded files and folders from the repository.
The C Container Collection uses the following functions or macros that must be supported by the user on freestanding targets.
Traditionally included via <string.h>:
memcpy()memmove()memset()memcmp()Traditionally included via <assert.h>:
assert()To provide these functions, the user may create a header. For example, my_ccc_configuration.h.
In this header the user has two options: provide the listed functions directly or include their versions of the headers that provide the needed functionality. It is common for freestanding environments to provide their own <string.h> and <assert.h> that implement these functions.
The Include What You Use (IWYU) comment is helpful if you want to avoid tooling warnings in CCC code and have not marked CCC code as a system library to silence such warnings. If you are providing functions directly, this is not applicable. Then, ensure the C Container Collection can find that header.
Now pass the flag to CMake at configure time via CMakePresets.json, CMakeUserPresets.json, or the command line.
Or they can be passed on the command line.
Now the C Container Collection is fully configured to be built as part of the user project in a freestanding environment.
Any other C headers that the collection uses internally, such as <stdint.h>, <stddef.h>, and <stdalign.h>, are those provided by the C23 standard on freestanding targets and do not require a user implementation.
See the flat hash map documentation for how to select the optimal Single Instruction Multiple Data or Single Register Multiple Data implementation. Even on freestanding targets, the compiler intrinsics used on x86-64 and ARM NEON platforms should be available. However, CCC_FLAT_HASH_MAP_PORTABLE is an available directive for users that need to force a portable fallback implementation when such compiler platform intrinsics are not available. See ccc/flat_hash_map.h for more.
To complete steps 1-3 with one command try the following if your system supports make.
Or build and install with gcc. However, a newer gcc than the default on many systems may be required. For example, I compile this library with gcc-14.2 as of the time of writing. To set up a CMakeUserPresets.json file to use a newer gcc.
This will use CMake and your default compiler to build and install the library in release mode. By default, this library does not touch your system paths and it is installed in the install/ directory of this folder. This is best for testing the library out while pointing cmake to the install location. Then, deleting the install/ folder deletes any trace of this library from your system.
Then, in your CMakeLists.txt:
You can simply write the following command in your CMakeLists.txt.
To do so, specify that this library shall be installed to a location CMake recognizes by default. For example, my preferred location is as follows:
Then the installation looks like this.
Now to delete the library if needed, simply find all folders and files with the *ccc* string somewhere within them and delete. You can also check the build/install_manifest.txt to confirm the locations of any files installed with this library.
Once CMake can find the package, link against it and include the container header.
The CMakeLists.txt file.
The C code.
If your system does not support Makefiles or the make command here are the CMake commands one can run that will do the same.
If you do not like the default presets, create a CMakeUserPresets.json in this folder and place your preferred configuration in that file. Here is my preferred configuration to get you started. I like to use the newest version of GCC that I have installed.
Then your preset can be invoked as follows:
Documentation is available HERE. However, if you want to build the documentation locally you will need doxygen and graphviz installed. Then run:
This will generate documentation in the docs folder. To view the docs in your local browser, double click the docs/doxygen/index.html file.