Skip to content

coder137/build_in_cpp

Repository files navigation

Build in CPP [BuildCC]

Linux GCC build

Windows CMake build

codecov

Build C, C++ and ASM files in C++

Aim

BuildCC aims to be an alternative to Makefiles while using the feature rich C++ language instead of a custom DSL.

Features

  • Complete flexibility for custom workflows and toolchains
  • C++ language feature benefits and debuggable build binaries
  • Optimized rebuilds through serialization. See target.fbs schema
    • Can optimize for rebuilds by comparing the previous stored build with current build.
    • See also FAQ
  • Customizable for community plugins. More details provided in the Community Plugin section.

Pre-requisites

  • C++17 Compiler with
    • C++17 filesystem library support
    • C++11 thread library support
  • Third Party Libraries (See License below)
    • Flatbuffers v2.0.0
    • Taskflow v3.1.0
    • CLI11 v2.1.0
    • Tiny Process Library v2.0.4
    • fmt v8.0.1
    • spdlog v1.9.2
    • CppUTest v4.0

General Information

  • A one stage input / output procedure is called a Generator with a wide variety of use cases
    • Single input creates single output
    • Single input creates multiple outputs
    • Multiple inputs create single output
    • Multiple inputs creates multiple outputs
  • A two stage compile and link procedure is called a Target
    • This means that Executables, StaticLibraries and DynamicLibraries are all categorized as Targets
    • In the future C++20 modules can also be its own target dependending on compiler implementations
  • Every Target requires a complementary (and compatible) Toolchain
    • This ensures that cross compiling is very easy and explicit in nature.
    • Multiple toolchains can be mixed in a single build file i.e we can generate targets using the GCC, Clang, MSVC and many other compilers simultaneously.
  • The compile_command and link_command is fed to the process/system call to generate files.
  • Each Target can depend on other targets efficiently through Parallel Programming using Taskflow.
    • Dependency between targets is explicitly mentioned through the Taskflow APIs
    • This has been made easier for the user through the buildcc::Register module.
  • Build files can be customized through command line arguments
    • Command line arguments can be stored in configurable .toml files and passed using the --config flag.
    • Users can define their own custom arguments.
    • Argument passing has been made easy using the buildcc::Args module.

Taskflow dependency for hybrid/simple example Hybrid Simple example

  • Build GCC and MSVC Targets simultaneously
  • 1 C and 1 CPP example for both toolchains

Taskflow dependency for hybrid/pch example Hybrid PCH example

  • Activate PCH for GCC and MSVC Targets
  • 1 C and 1 CPP example for both toolchains

Taskflow dependency for hybrid/dep_chaining example Hybrid Dep Chain example

  • Chain Generator with Targets for Dependency
  • 1 C and 1 CPP example for both toolchains

Software Architecture

Interface lib dependencies

BuildCC Interface library

Single lib dependencies

BuildCC Single library

Dependency Chart

Depedency Chart

Community Plugin

  • ClangCompileCommands

  • BuildCCFind

    • Host system executable
    • BuildCC Library
    • BuildCC Plugin
  • ClangFormat

  • Target graph visualizer (through Taskflow)

  • buildcc::base::Target contains public getters that can be used to construct unique community plugins.

  • Common tools and plugins would have first-party support in buildcc.

  • All other tools and plugins can be maintained through individual developers.

User Guide

Developers interested in using BuildCC

BuildCC User options

  • BUILDCC_INSTALL: ON
  • BUILDCC_FLATBUFFERS_FLATC: ON
  • BUILDCC_BUILD_AS_SINGLE_LIB: ON
    • Generates libbuildcc
  • BUILDCC_BUILD_AS_INTERFACE_LIB: OFF
    • Generates libbuildcc_i with other libs linked during compilation
  • BUILDCC_PRECOMPILE_HEADERS: OFF
  • BUILDCC_EXAMPLES: OFF
    • Uses SINGLE_LIB for its examples
  • BUILDCC_TESTING: ON
    • Unit testing with ctest --output-on-failure
    • Only active for GCC compilers
    • Provides code coverage
    • cmake --build {builddir} --target lcov_coverage (on linux ONLY)
    • cmake --build {builddir} --target gcovr_coverage (installed via pip gcovr)
  • BUILDCC_CLANGTIDY: ON
    • Auto runs with CMake
  • BUILDCC_CPPCHECK: ON
    • Cppcheck with cmake --build {builddir} --target cppcheck_static_analysis
  • BUILDCC_DOCUMENTATION: ON
    • Basic Doxygen generated html pages
    • cmake --build {builddir} --target doxygen_documentation
  • BUILDCC_NO_DEPRECATED: OFF
    • Required on certain clang arch compilers -Wno-deprecated flag

Build

NOTE: Currently, BuildCC needs to be built from source and bootstrapped using CMake.

I aim to bootstrap BuildCC into an executable to remove the dependency on CMake.

  • By default all the developer options are turned OFF.
  • Only the BUILDCC_INSTALL option is turned on.
# Generate your project
cmake -B [Build folder] -G [Generator]
cmake -B build -G Ninja

# Build your project
cmake --build build

Install

# Manually
cd [build_folder]
sudo cmake --install .

# Cpack generators
cpack --help

# ZIP
cpack -G ZIP

# Executable
cpack -G NSIS

NOTE: On windows NSIS needs to be installed

  • Install the package and add to environment PATH
  • As a starting point, go through the gcc/AfterInstall example and Hybrid examples
  • For more details read the examples README to use buildcc in different situations

Examples

Contains proof of concept and real world examples.

Developer Guide

Developers interested in contributing to BuildCC

Build

CMakePresets (from Version 3.20)

  • See CMakePresets.json for GCC, MSVC and Clang configurations
# Generating
cmake --list-presets
cmake --preset=[your_preset]

# Building
cmake --build --list-presets
cmake --build --preset=[your_preset]

# Testing (ONLY supported on gcc)
ctest --preset=gcc_dev_all

Custom Targets

# Run custom target using
cd [folder]
cmake --build . --target [custom_target]

Tools

  • cppcheck_static_analysis
  • doxygen_documentation
  • gcovr_coverage
  • lcov_coverage

Examples

  • run_hybrid_simple_example_linux
  • run_hybrid_simple_example_win
  • run_hybrid_foolib_example_linux
  • run_hybrid_foolib_example_win
  • run_hybrid_externallib_example_linux
  • run_hybrid_externallib_example_win
  • run_hybrid_customtarget_example_linux
  • run_hybrid_customtarget_example_win

Install

Basic Installation steps

  • Install TARGETS
  • Install HEADER FILES
  • Export CONFIG

Test

FAQ

Design

Miscellaneous

TODO

List of features to be implemented before buildcc can be considered production ready.

I would also like to request help from the Community for the following:

  • Code reviews
  • Design patterns
  • Optimization strategies
  • TODO discussions

License Dependencies

BuildCC is licensed under the Apache License, Version 2.0. See LICENSE for the full license text. BuildCC aims to use open-source libraries containing permissive licenses.

Developers who would like to suggest an alternative library, raise an issue with the license and advantages clearly outlined.

  • Fmtlib (Formatting) [MIT License] [Header Only]
  • Spdlog (Logging) [MIT License] [Header Only]
  • Tiny Process Library (Process handling) [MIT License]
  • Taskflow (Parallel Programming) [MIT License] [Header Only]
  • Flatbuffers (Serialization) [Apache-2.0 License] [Header Only]
  • CLI11 (Argument Parsing) [BSD-3-Clause License] [Header Only]
  • CppUTest (Unit Testing/Mocking) [BSD-3-Clause License]

About

Build C, C++ and ASM files in C++

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages