Skip to content

Rexrn/old-cpp-build

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 

Repository files navigation

cpp-build

Note: this is only a goal README. Most of things described here are not implemented yet.

Table of contents:

New to build systems?

Checkout the simple explaination.

What cpp-build is?

An easy to use and (not yet) powerful C++ build system. It uses JavaScript executed by Node.js to provide powerful scripting language, so you easily setup your project build process.

cpp-build provides object oriented way to represent your applications.

Minimal example code

Create Project.js in main project folder:

const cb = require("cpp-build");

let app = {
	name: "ConsoleApp",
	language: "C++17",
	includeDirectories: [ "include" ],
	files: [
		"include/PrintHello.hpp",
		"src/PrintHello.cpp",
		"src/Main.cpp"
	]
};

// Export application as a target to build.
// NOTE: first argument has to be "module"!
cb.export(module, app);

Following project structure assumed:

  • include/
    • PrintHello.hpp (declarations)
  • src/
    • PrintHello.cpp (definitions)
    • Main.cpp (main function)

Building minimal example

  1. Create "build" folder inside main project folder
  2. Open terminal in "build" folder.
  3. Execute following command:
    node cpp-build ../Project.js -g -b -i
  • -g generates project files
  • -b builds project
  • -i installs it to default directory

A simple explaination

What you can do with cpp-build:

  1. Write your code
  2. Tell cpp-build how your project is organised
  3. Build project on any platform using any tool*

* - compiler or tool must be supported by cpp-build and be able to build your code.

cpp-build is a cross-platform meta build system. It generates build files used by specific compilers or tools.

Supported build tools

  • GNU Make (generates Makefiles)
  • // TODO: expand it.

Some more examples

Use those to quickly introduce yourself.

Library and a project linked to library

let workspace = new cb.TargetGroup("GameWorkspace");

let lib = new cb.StaticLibrary("GameEngine");
let app = new cb.Application("Game");
app.link(lib);
workspace.targets = [ lib, app ];

// Setup "lib"...

// Setup "app"...

cb.export(module, workspace);

Load external code

This requires the external code to export its settings using cpp-build.

let testApp = new cb.Application("Test");

// Setup configuration options
testApp.configuration = {
	"gtest.root": ""
};

// To link external libraries we have
// to wait until target is configured.
testApp.on("configured", (cfg) =>
		{
			// Load google test:
			let gtestWks = require(cfg["gtest.root"] + "/workspace.js");
			let gtestProj = gtestWks.targets.find( t => t.name == "gtest" );

			// Add google test as dependency:
			if (gtestProj) {
				testApp.link(googleTestProject);
			}
			else
				throw 'google test library project not found.';
		}
	);

Install events

let wks = new cb.TargetGroup("MyWorkspace");
let app = new cb.Application("MyApplication");
let lib = new cb.StaticLibrary("MyLibrary");
wks.targets = [ app, lib ];

app.installs = [		
	// Installs (recursively) all files from:
	//   build_output_dir/bin/
	// to:
	//   install_base_dir/bin/cfgName/
	{ from: "bin/**", to: `bin/${cb.cfgName}` }
];


lib.installs = [
	{ from: "include/**", to: "include" },
	{ from: "lib/**", to: `lib/${cb.cfgName}` },
	{ from: "bin/**", to: `bin/${cb.cfgName}` },
	{ from: "docs/**", to: "docs" }
];

cb.export(module, wks);

About

An easy to use C++ build system.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published