Package: cxxbuild
cxxbuild / cxxdepsVersion:cxxbuild version=1.5.2Installation:pip install cxxbuildcxxbuild is a python script to easily build C++ programs: just invoke 'cxxbuild' and it works!For basic introduction, read the post:Using cxxbuild to easily build C++ project with tests and dependenciesWe know it is very hard to start a C++ project and learn basics of build systems such as CMake and Bazel, and package managers like conan and vcpkg... so just type "cxxbuild" and be happy!The strongest point of this project is thecxxdeps.txtformat,
that allow easy specification of dependencies from different package managers (in similar style of pythonrequirements.txtformat)To use it locally, just copycxxbuild/cxxbuild.pyfile to your project and execute it:python3 cxxbuild.py helpOr, just install it from pip:pip install cxxbuildThen, just run:cxxbuild helpFrom this point, we assume cxxbuild is installed in your system :)Basic commandscxxbuildhas four main modes (three unimplemented, yet):build mode (default): just pass some root directory with filesclean mode (unimplemented): will clean specific build fileslint mode (unimplemented): will lint project filestest mode (unimplemented): will run project testsRunning demosDemo 1README:cxxbuild demo/project1Demo 2README:cxxbuild demo/project2Demo 3README:cxxbuild demo/project3Demo 4README:cxxbuild demo/project4 --c++20All of them support both CMake and Bazel build systems,
for common platforms Linux, Windows and Mac.Test summary for demosdemo/project1: runs on linux, osx and windows* (bash only) - default c++17 (works with c++11 to c++23)demo/project2: runs on linux, osx and windows (bash and cmd) - default c++17 (works with c++11 to c++23)demo/project3: runs on linux, osx and windows* (bash only) - default c++17 (works with c++11 to c++23)demo/project4: runs on linux, osx and windows* (bash only) - requires minimum c++20(*) Some limitations on windows/cmd are related to fmt dependency on cmake, not cxxbuild.Running demo 1 (explained)python3 cxxbuild/cxxbuild.py demo/project1OR, after installation:cxxbuild demo/project1It will:read dependencies from cxxdeps.txt file, if availablegenerate a CMakeLists.txt on project (backup your file if you already have one!)build with cmake+ninja (default) or any other provided build systemGenerated binaries will be ondemo/project1/build/demo1: binary with entrypoint (main) for demo (file:src/demo1.cpp)my_test: binary with unit tests (file:tests/my_test.cpp)To clean it (sincecleancommand is still unimplemented), just deletebuild/folder.Expected project organizationThe tool cxxbuild assumes that:source code (.cpp, .cc, .c, etc) is located on asrc/folderthis can be changed with--src SRC_PATHoptiontest code is located on atests/folderthis can be changed with--tests TEST_PATHoptionheader only libraries are located on ainclude/folderthis can be changed with--include INCLUDE_PATHoptionThe reason forsrc/folder is:enforces some "basic" project organization (I know many people don't like asrc/folder...)recursively searching source files on root folder yields some issues,
asbuild/folder in same directory level becomes contaminated with external .cpp dependencies, thus requiring some clever exclusion algorithmThe reason fortests/folder is:enforces some "basic" project organization (I know many people don't like atests/folder...)it is hard to distinguish between binary.cppfiles and unit test files,
unless  some other "standard" is imposed, such as namingtests.cpp(but what about multiple tests then?)The reason forinclude/folder is:this is classic organization, c'mon!!!this is necessary to isolate header only library and make it easier for others to include them... if you don't want to offer a header only library, ok then, just put everything onsrc/folder and that is fine!These things can be easily changed, either manually oncxxbuild.pyscript, or by opening an issue and we discuss if some other option is really necessary...
Note that this project does not aim to have many personalizations and complications, let's use KISS method!Advantages and DrawbacksGreatest advantage of this project is to easily describe dependencies on acxxdeps.txtfile.An example is:fmt == "9.1.0"     [ fmt ]                    git *    https://github.com/fmtlib/fmt.git
Catch2 == "v3.3.1" [ Catch2::Catch2WithMain ] git test https://github.com/catchorg/Catch2.git
mThis is quite simple and powerful, with few lines describing the following:takefmtproject from git repository in specific versiontakeCatch2project from git repository in specific version and use it for tests onlytake system-lmdependencyThegitpart could be any package manager, such as conan and vcpkg, although not implemented yet!
Thegitcan be specified forcmakeorbazel, likecmake+gitorbazel+git.It can also bebcr, for the Bazel Central Registry, or more specifically:bazel+bcr(not supported forcmake+bcr)Ongoing extensions for cxxdepsSome ongoing extensions will allow managing dev dependencies,
such as build systems (cmake, bazel, etc) and C/C++ package managers (conan, etc), all automatically oncxxdeps.txt(or exclusively oncxxdeps.dev.txt):cmake == *          [ cmake ]       pip dev [ ninja ]
ninja:windows == *  [ ninja ]       choco dev
ninja:linux == *    [ ninja-build ] apt dev
bazel:windows == *  [ bazelisk ]    choco dev 
bazel:linux == *    [ bazelisk ]    npm dev 
conan == *          [ conan ]       pip devNote that we can support triplet package notation on project name,
so as different system package managers (such as apt on ubuntu/debian).
Some package dependency notation can be useful as well to orchestrate installation
flow, when necessary (as an example, ninja could be forcefully installed before cmake).Other extension is somebuildsection... similar todev, but it installs automatically
before build process. Thebuildcan be seen as amandatorydevdependency.
Someconfigureactions andpatchescould also happen inbuildphase
(which are in fact somepre-buildactions).cxxdeps is a cool thing!In fact, this was the most motivating part of this project, so feel free to check more painful experiences directly onmanydeps-gmpproject!Writing cxxdeps in.tomlformatIt is currently possible to writecxxdeps.tomlfile, that automatically generatescxxdeps.txtandcxxdeps.dev.txtfiles. Some users may find this easier to understand:[all]fmt={git="https://github.com/fmtlib/fmt.git",tag="9.1.0",links=["fmt"]}m={links=["m"]}pthread={}[test]catch2={git="https://github.com/catchorg/Catch2.git",tag="v3.3.1",links=["Catch2::Catch2WithMain"]}[dev]bazel=[{choco=["bazelisk"],platform="windows"},{npm=["bazelisk"],platform="linux"}]ninja=[{choco=["ninja"],platform="windows"},{apt=["ninja-build"],platform="linux"}]cmake={pip=["cmake"],deps=["ninja"]}conan={pip=["conan"]}Here one can find sectionsall(equivalent to*),testanddev.
This example install system libraries-lmand-lpthreadfor runtime dependencies (all),catch2test library linked with cmakeCatch2::Catch2WithMain, and defines several dev packages.Check an example in project3 with:python3 cxxbuild/cxxbuild.py demo/project3DrawbacksNone that I know, yet :)Some people may dislike the imposed organization, likesrc/andtests/, but it can be changed manually on script. The idea here is to really make a simplistic script, that really works with highly complex setups (such as taking dependencies from remote and dealing with build systems like cmake and bazel). These things are hard to do even for some experienced c++ programmers... so, as long as it is simple and it works, that is fine! If it doesn't work, file an issue!Related WorksSeeccbuild from debianSeebneijt/ccbuildSeeMantle project(experimental but with similar ideas)None of them support dependencies, such ascxxdeps.txt, or even build systems such as cmake and bazel.Hopefully, when this project is fully finished, C++ will be a better place for all of us :)AcknowledgementsThanks for those trying to use and improve this software.
Specially, thanks Fellipe Pessanha for early suggesting integrating toml support for cxxdeps.CitationIgor Machado Coelho. (2023). cxxbuild project. Zenodo. https://doi.org/10.5281/zenodo.10447208LicenseDual licensed: Creative Commons Attribution 4.0 International OR MIT LicenseCopyleft 2023Igor Machado Coelho