#cargo #cpp #cargo-subcommand #cli #cargo-build

bin+lib cargo-newcpp

A cargo plugin for creating new C++ projects

15 releases

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

#187 in Cargo plugins

Download history 2/week @ 2024-09-21 2/week @ 2024-10-12 153/week @ 2024-11-02 666/week @ 2024-11-09

819 downloads per month

Apache-2.0 OR MIT

42KB
291 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

Ensure that you have a fairly recent version of rust/cargo installed. On Ubuntu you might also want to install cmake and gcc or g++ so that you can actually build project.

If you'd like to kick the tires on the build feature (cargo buildcpp) you will want the following installed

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

Create a new project

Create a new CPP project with the following command.

cargo newcpp <your_project_name>

This will output to the following default project scaffolding.

scaffolding

Building the CPP project with cargo

Once you've create the project, you can use the following example to build the project.

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
~118K SLoC