Package: clang-build
Clang-buildFind the full documentation athttps://clang-build.readthedocs.ioFirst stepsCustomisationsMultiple targetsMultiple projectsDefaultsMotivation:Building as much as possible from source eases dependency management and
ensures stability and reproducibilityMeta build systems are inherently the wrong way to go, either the build
system or the compiler should be platform-agnostic (ideally both).Trying to cover all use-cases is the wrong way to go - there is no need to
let people do it the wrong wayCMake is cumbersome, unnecessarily generic and verbose and people should not
need a programming/scripting language whose only purpose is to build C++With Clang, finally a properly cross-platform compiler existsGoals:One compiler (Clang), one build system (written in Python)Simple projects should be simple to buildBuild process for reasonable project structures should still be easyAdding third-party dependencies should be manageableWhat it's not designed to do:Build anything aside from C language dialectsBe able to adapt to any project structure in the world - certain standards are encouragedWork smoothly with or locate pre-built libraries and libraries installed by system package managersRelated resources:CppCon 2017: Isabella Muerte "There Will Be Build Systems: I Configure Your Milkshake"https://medium.com/@corentin.jabot/accio-dependency-manager-b1846e1caf76UsageIn order to runclang-build, you only need Clang and Python3.
Install viapip install clang-build(add the--userflag if you don't have admin rights).Runningclang-buildwill try to build the current directory.
The command-line options include-d path/to/dirto build a different directory-pto show a progress bar-Vto print some additional info--debugto print the called clang commandsThe given directory will be searched for aclang-build.tomlfile, which you can use to configure
your build targets, if necessary. However, if you only want to build an executable, you will
likely not even need a build file.clang-build tries to use sane defaults, designed to make most projects very easy to configure
and even complex projects far easier than with common build or meta-build systems.Real-World ExamplesExamples of real-world used and tested projects, which can be easily be integrated
into your project usingclang-build:test/boost-filesystemGeneral IdeasNote: not all of these are implemented, yet.What should be trivialThis would be things that require only the invocation ofclang-buildand no build file.build any hello world program or other MWE, given a reasonable folder
structure (i.e anything with a main and without non-std dependencies)include anything that can be found by sane default searchusing command line arguments:specify root/source and build directoriesset build type (last used should be cached/remembered)set verbositySane defaults and default behaviour:platform-independencebuild into a "build/" directory, not into toplevelfor multiple targets build each into its own "build/targetname"default search paths for different platforms, including also e.g.
"./include", "./lib", "./build/lib", "/usr/local/...", ...What should be easyThis would be things that only require a minimal TOML project fileadd dependency / external project from source folder or remote (e.g.
github)header-only should be trivialfor a library with a good folder structure, it should be easy to
write a build configcreate a library from one subfolder, an executable from another and
link themsetting target-specific (note: defaults should be sane!)source file extensionssource directoriescompile and link flagsoptional versiondependencies (which may include non-targets, e.g. configuration
steps)properties (required c++ version, definitions/#defines, ...)access to flag "lists" such as flags forcoveragecudaopenmpset target-specific flags, include folders, etc. which should not be
propagated to dependency parents as "private"What should be possibleSteps that would involve more effort from the user, including possibly
some python codea Target configuration step before building (e.g. for more involved
version numbering)through the configuration step, inclusion of e.g. CMake-project
should be possiblepackaging: any target may be packaged, meaning it's dependencies are
handled and if built, binaries may be bundledexternal package dependenciesbinaries on a serversource on a server (fallback from binaries)binaries on disk, try to determine version from path and file namessource on disk, try to determine version from path and file namesProject File By ExampleA single targetNote:by default, therootand<targetname>folders, as well as "include" and "src" subdirectories
will be searched for ".hpp", ".hxx", ".h" and ".cpp", ".cxx" and ".c" filesa target withouttarget_type, but with source files will be an executableoutput_nameshould not contain pre- or suffixes such as lib, .exe, .so, as they are added automaticallyif we don't care about the output name, in this case we could skip the project file entirely# Top-level brackets indicate a target[hello]output_name="runHello"Two targets with linking# Build a library[mylib]target_type="shared library"# Build an executable and link the library[myexe]output_name="runExe"target_type="executable"dependencies=["mylib"][myexe.flags]link=["-DMYEXE_SOME_DEFINE"]Adding external dependenciesNote:external targets will be copied/downloaded into "build/targetname/external_sources"you can specify a subdirectory, if the thirdparty code has an unusual structurefurther granularity is given byinclude_directoriesandsourcessources,headers_excludeandsources_excludeexpect a list of globbing patterns or files (not folders!)[mylib]url="https://github.com/trick-17/mylib"version=1.1# will try to `git checkout 1.1`directory="sources"# will point to "build/mylib/external_sources/sources"include_directories=["mylib/include"]# will point to "build/mylib/external_sources/sources/mylib/include"sources=["mylib/src/*"]# will list everything inside "build/mylib/external_sources/sources/mylib/src"# Maybe we need to deactivate annoying warnings coming from the library[mylib.flags]compile=["-Wno-deprecated-declarations","-Wno-self-assign"]# Build an executable and link the library[myexe]dependencies=["mylib"]