|
| 1 | +#include "buildcc.h" |
| 2 | + |
| 3 | +using namespace buildcc; |
| 4 | + |
| 5 | +constexpr const char *const EXE = "build"; |
| 6 | + |
| 7 | +// Function Prototypes |
| 8 | +static void clean_cb(); |
| 9 | +static void hello_world_build_cb(BaseTarget &target); |
| 10 | + |
| 11 | +int main(int argc, char **argv) { |
| 12 | + // 1. Get arguments |
| 13 | + Args args; |
| 14 | + ArgToolchain arg_gcc; |
| 15 | + args.AddToolchain("gcc", "Generic gcc toolchain", arg_gcc); |
| 16 | + args.Parse(argc, argv); |
| 17 | + |
| 18 | + // 2. Initialize your environment |
| 19 | + Register reg(args); |
| 20 | + |
| 21 | + // 3. Pre-build steps |
| 22 | + reg.Clean(clean_cb); |
| 23 | + |
| 24 | + // 4. Build steps |
| 25 | + // Explicit toolchain - target pairs |
| 26 | + Toolchain_gcc gcc; |
| 27 | + ExecutableTarget_gcc hello_world("hello_world", gcc, ""); |
| 28 | + auto verified_toolchains = gcc.Verify(); |
| 29 | + env::assert_fatal(!verified_toolchains.empty(), "GCC Toolchain not found"); |
| 30 | + |
| 31 | + // Select your builds and tests using the .toml files |
| 32 | + reg.Build(arg_gcc.state, hello_world_build_cb, hello_world); |
| 33 | + |
| 34 | + // 5. Test steps |
| 35 | + reg.Test(arg_gcc.state, "{executable}", hello_world); |
| 36 | + |
| 37 | + // 6. Build Target |
| 38 | + reg.RunBuild(); |
| 39 | + |
| 40 | + // 7. Test Target |
| 41 | + reg.RunTest(); |
| 42 | + |
| 43 | + // 8. Post Build steps |
| 44 | + // - Clang Compile Commands |
| 45 | + plugin::ClangCompileCommands({&hello_world}).Generate(); |
| 46 | + |
| 47 | + return 0; |
| 48 | +} |
| 49 | + |
| 50 | +static void clean_cb() { |
| 51 | + env::log_info(EXE, fmt::format("Cleaning {}", env::get_project_build_dir())); |
| 52 | + fs::remove_all(env::get_project_build_dir()); |
| 53 | +} |
| 54 | + |
| 55 | +static void hello_world_build_cb(BaseTarget &target) { |
| 56 | + target.AddSource("main.cpp", "src"); |
| 57 | + |
| 58 | + target.Build(); |
| 59 | +} |
0 commit comments