A simple C++ build system that uses C++ as the scripting language thus doesn't need any new tools to be installed. Moreover, it is easier because well, it uses C++ as a scripting language.
Because Tsoding said you should write your own build system.
- Command Execution: Execute system commands and shell commands with ease.
- Logging: Log messages with different severity levels (INFO, WARNING, ERROR).
- Process Management: Wait for processes to complete and handle their exit statuses.
- Output Handling: Capture and read the output of executed commands.
- System Metadata: Print system metadata including OS, compiler, and architecture information.
To use bld
in your project, include the bld.hpp
header file and define B_LDR_IMPLEMENTATION
in one of your source files to include the implementation.
#define B_LDR_IMPLEMENTATION
#include "bld.hpp"
Log messages with different severity levels:
bld::log(bld::Log_type::INFO, "This is an info message.");
bld::log(bld::Log_type::WARNING, "This is a warning message.");
bld::log(bld::Log_type::ERROR, "This is an error message.");
Create and execute commands:
bld::Command cmd("ls", "-la");
int result = bld::execute(cmd);
Execute shell commands:
std::string shell_cmd = "echo Hello, World!";
int result = bld::execute_shell(shell_cmd);
Capture the output of a command:
std::string output;
bld::Command cmd("ls", "-la");
bool success = bld::read_process_output(cmd, output);
Capture the output of a shell command:
std::string output;
std::string shell_cmd = "echo Hello, World!";
bool success = bld::read_shell_output(shell_cmd, output);
int main(int argc, char *argv[])
{
BLD_REBUILD_YOURSELF_ONCHANGE();
bld::Dep_graph dg;
dg.add_dep({"main",
{"main.cpp", "./foo.o", "./bar.o"},
{"g++", "main.cpp", "-o", "main", "foo.o", "bar.o"}});
dg.add_dep({"./foo.o",
{"foo.cpp"},
{"g++", "-c", "foo.cpp", "-o", "foo.o"}});
dg.add_dep({"./bar.o",
{"bar.cpp"},
{"g++", "-c", "bar.cpp", "-o", "bar.o"}});
dg.build_all();
return 0;
}
$ls
main.cpp foo.cpp foo.hpp bar.cpp bar.hpp
Check if an executable is up-to-date with it's file: This specific example tracks it's own executable file.
// Requires arguments for main function
int main(int argc, char *argv[])
{
// Check if the executable needs to be rebuilt and restart if necessary
BLD_REBUILD_YOURSELF_ONCHANGE();
}
Print system metadata:
bld::print_metadata();
- Parallel incremental builds
- Fully cross-platform functions
Rinav (GitHub: rrrinav)