#cargo #cpp #cargo-subcommand #cli

bin+lib cargo-newcpp

A cargo plugin for creating new C++ projects

16 releases

new 0.6.4 Nov 20, 2024
0.6.3 Nov 17, 2024
0.5.45 Nov 11, 2024
0.5.2 Sep 30, 2023
0.2.17 Aug 3, 2023

#172 in Cargo plugins

Download history 2/week @ 2024-09-19 2/week @ 2024-10-10 140/week @ 2024-10-31 657/week @ 2024-11-07 265/week @ 2024-11-14

1,065 downloads per month

Apache-2.0 OR MIT

43KB
364 lines

cargo newcpp

This tool extends Cargo to allow for the creation of new C++ projects in the spirit of cargo new <project>

cargo install cargo-newcpp

Required Prereqs

Ensure that you have a fairly recent version of Rust/Cargo installed.

In order to build projects using cargo buildcpp you will also want to install recent versions of standard C++ build tools:

sudo apt install gcc, g++, ninja-build, build-essential, cmake

Create a new project

To create a new C++ project:

cargo newcpp <your_project_name> [--lib]

This will output to the following default project scaffolding under the <project_name> folder.

scaffolding

If you have git installed this will also initialize your new project as a git repo.

Building the CPP project with cargo

Once you've created the project, you can build it using the command below:

cd <your_project_name> 
cargo buildcpp [--debug | --release]

By default, buildcpp will place cmake buildtree artifacts into the target/debug folder. Specifying the --release flag will generate the buildtree artifacts in target/release

Cleaning the CPP project with cargo-cleancpp

This is functionally equivilant to "rm -rf target/". I struggled with whether or not I should do something more idiomatic to modern cmake (e.g. cmake --build <target> -t clean or cmake --fresh ...) but these did not feel right and chose to default to what ```cargo clean`` does instead.

cargo cleancpp 

Dependencies

~6MB
~117K SLoC