nabs
nabs copied to clipboard
not a build system
not a build system
nabs is a single-header library for writing build recipes in C++. It is directly inspired by nobuild, but with more feature (bloat) and built-in support for makefile-like dependency resolution.
The primary objective of this (not a) build system is to allow writing build recipes/scripts that:
- are written in one language (the best one) -- C++
- work for all major platforms -- Linux, macOS, BSDs, Windows
- easily support, with very little boilerplate, standard makefile project patterns
- provide platform- and compiler-independent abstractions for common flags/options
example
While the documentation is not quite there yet, we already have a lot of features. For example, to create a build recipe that automatically:
- recompiles itself when its source file changes
- generates header-include dependency information for source files
- generates and uses a precompiled header (and updates the pch if anything changes)
- supports incremental builds (one source to one object, only rebuilding when necessary)
- runs compilation jobs in parallel
- works in most environments including Windows+MSVC
- finds
cl.exeon Windows without needing to be in avcvarscommand prompt
we just need something like this:
#include "nabs.h"
namespace n = nabs;
int main(int argc, char** argv)
{
auto OUTPUT_EXE = n::auto_set_extension_exe("build/lc");
n::self_update(argc, argv, __FILE__);
size_t threads = std::max(std::thread::hardware_concurrency(), 1u);
n::log("using {} thread{}", threads, threads == 1 ? "" : "s");
auto tool = n::find_toolchain().expect("failed to find toolchain");
tool.add_cpp_includes("source/include")
.use_cpp_precompiled_header("source/include/precompile.h")
.use_exceptions(false);
auto src_files = n::fs::find_files_with_extension_recursively("source", ".cpp");
n::dep::Graph graph;
n::auto_add_precompiled_header(graph, tool, "source/include/precompile.h", n::LANGUAGE_CPP);
auto exe_file = n::auto_executable_from_sources(graph, tool, OUTPUT_EXE, src_files)
.expect("error");
auto pool = zmt::ThreadPool(threads);
n::auto_build_target(pool, tool, graph, exe_file)
.expect("compilation failed");
}
missing features
Some things are still not implemented:
-
Any form of cross compilation support
- looking for toolchains in another folder (ie. anywhere other than the default)
- specifying prefixes, sysroots, etc.
-
Searching for libraries using something other than
pkg-config- eg. looking in
/usr/liband/usr/local/lib - any form of library searching on windows
- eg. looking in
-
Misc features
- creating shared/static libraries
- more "automatic" argument parsing (eg. automatically handle stuff like
-j,--help)
license
This header is licensed under the Apache License 2.0.