A cargo-like modern cpp build tools, aimed to combine all existing best practices, rather than re-inventing them from scratch.
cppship cmake
to convert a cppship project to CMake projectFurther details can be found in wiki
The above goals are achieved by the following features:
cppship init <name>
or cppship init --lib <name>
to start a new projectconan2
to import dependencies
cppship run
or cppship test
or cppship bench
without any configuration or boilerplate code$ brew install qqiangwu/tap/cppship
Try homebrew, or build it yourself, see below.
We can use cmake to build cppship
mkdir build
cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build build -j8
cmake --build build -j8 --target install
We can also use cppship to build cppship
# install
cppship install
Cppship will generate cmake projects based on your directory structure and cppship.toml.
See examples
[package]
# (required) your lib or binary name
name = "cppship"
# (required)
version = "0.0.1"
authors = []
# (optional) specifiy you cppstd
std = 20
[dependencies]
# conan dependencies
boost = { version = "1.81.0", components = ["headers"], options = { header_only = true } }
toml11 = "3.7.1"
fmt = "9.1.0"
range-v3 = "0.12.0"
bshoshany-thread-pool = "3.3.0"
ms-gsl = "4.0.0"
argparse = "2.9"
spdlog = "1.11.0"
# git header-only libs
scope_guard = { git = "https://github.com/Neargye/scope_guard.git", commit = "fa60305b5805dcd872b3c60d0bc517c505f99502" }
# git cppship header only lib
header_only = { git = "https://github.com/cppship/demo_header_only.git", commit = "93f6793" }
# git cppship lib
simple_lib = { git = "https://github.com/cppship/demo_lib.git", commit = "25dbedf" }
[dev-dependencies]
scnlib = "1.1.2"
[profile]
definitions = ["BOOST_PROCESS_USE_STD_FS"]
ubsan = true
asan = true
tsan = false
leak = false
[target.'cfg(not(compiler = "msvc"))'.profile]
cxxflags = ["-Wall", "-Wextra", "-Werror", "-Wno-unused-parameter", "-Wno-missing-field-initializers"]
[target.'cfg(compiler = "msvc")'.profile]
cxxflags = ["/Zc:__cplusplus", "/Zc:preprocessor", "/MP"]
[profile.debug]
# appends to cxxflags in [profile]
cxxflags = ["-g"]
# merged with definitions in [profile]
definitions = ["C"]
[profile.release]
# appends to cxxflags in [profile]
cxxflags = ["-O3", "-DNDEBUG"]
make sure your project have the following structure:
lib
will be its dependencymake sure your project have the following structure:
lib
will be its dependencymake sure your project have the following structure:
lib
will be its dependencylib
and gtest
will be its dependencyYou can easily convert a cppship project into a cmake project:
# CMakeFiles.txt and conanfiles.txt will be generated under the project root dir
cppship cmake
# Build with cmake
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build
# init a binary
cppship init demo
cd demo
cppship run
cppship test
# init a library
cppship init demolib --lib
cd demolib
cppship build
# debug build
cppship build
# release build
cppship build -r
# dry-run, config cmake and generate compile_commands.json under build
cppship build -d
# build tests only
cppship build --tests
# build examples only
cppship build --examples
# build benches only
cppship build --benches
# build binaries only
cppship build --bins
cppship run
cppship run -- a b c extra_args
# run a binary
cppship run --bin <name>
# run an example
cppship run --example <name>
cppship test
cppship test --rerun-failed
cppship test <testname>
cppship test -R <testname-regex>
cppship bench
cppship bench <bench-name>
cppship install
cppship clean
We will use clang-format
to format our code
# by default, only format files changed since last commit
# dry-run and warn
cppship fmt
# only fmt git cached files
cppship fmt --cached
# fix it
cppship fmt -f
# reun against commit
cppship fmt -c <commit>
# format all files
cppship fmt -a
cppship fmt -a -f
We will use clang-tidy
to lint your code
# by default, only lint files changed since last commit
cppship lint
# lint git cached files
cppship lint --cached
# lint all
cppship lint -a
# lint against commit
cppship lint -c <commit>
Now cppship has no extensions for VSCode, but use clangd
is enough. Just write your project and run cppship build -d
, which will create build/compile_commands.json
. Clangd will find it and do its work.