Skip to main content

Project Configuration

Project Configuration

Basic Configuration

The cforge.toml file is the heart of your project configuration:

[project]
name = "myproject"
version = "1.0.0"
description = "My awesome C++ project"
cpp_standard = "17"
c_standard = "11"
binary_type = "executable" # executable, shared_library, static_library, header_only
authors = ["Your Name <you@example.com>"]
license = "MIT"

[build]
build_type = "Debug"
directory = "build"
source_dirs = ["src"]
include_dirs = ["include"]

[build.config.debug]
defines = ["DEBUG=1"]
flags = ["DEBUG_INFO", "NO_OPT"]

[build.config.release]
defines = ["NDEBUG=1"]
flags = ["OPTIMIZE"]

[test]
enabled = true
directory = "tests"
framework = "catch2" # or "gtest"

[benchmark]
directory = "bench"
target = "benchmarks"

[package]
enabled = true
generators = ["ZIP", "TGZ"]
vendor = "Your Name"

Configuration Options

SectionKeyDescription
[project]nameProject name
[project]versionProject version (semantic versioning)
[project]descriptionProject description
[project]cpp_standardC++ standard (11, 14, 17, 20, 23)
[project]c_standardC standard (99, 11, 17)
[project]binary_typeOutput type (executable, shared_library, static_library, header_only)
[project]authorsList of authors
[project]licenseLicense identifier
[build]build_typeDefault build type (Debug, Release, RelWithDebInfo, MinSizeRel)
[build]directoryBuild output directory
[build]source_dirsSource file directories
[build]include_dirsHeader file directories

Using Version in Code

The version from cforge.toml is automatically available as compile definitions:

#include <iostream>

int main() {
// Generic version macros (works for any project)
std::cout << "Version: " << PROJECT_VERSION << std::endl;
std::cout << "Major: " << PROJECT_VERSION_MAJOR << std::endl;
std::cout << "Minor: " << PROJECT_VERSION_MINOR << std::endl;
std::cout << "Patch: " << PROJECT_VERSION_PATCH << std::endl;

// Project-specific macros (e.g., for project named "myapp")
// std::cout << MYAPP_VERSION << std::endl;

return 0;
}

Available macros:

MacroDescriptionExample
PROJECT_VERSIONFull version string"1.2.3"
PROJECT_VERSION_MAJORMajor version number1
PROJECT_VERSION_MINORMinor version number2
PROJECT_VERSION_PATCHPatch version number3
<PROJECTNAME>_VERSIONProject-specific version"1.2.3"

CMake Integration

Customize CMake behavior with includes, injections, and module paths:

[cmake]
version = "3.15" # Minimum CMake version
generator = "Ninja" # CMake generator
includes = ["cmake/custom.cmake"] # Custom CMake files to include
module_paths = ["cmake/modules"] # Custom module search paths

# Inject custom CMake code
inject_before_target = """
# Code inserted before add_executable/add_library
include(FetchContent)
"""

inject_after_target = """
# Code inserted after add_executable/add_library
target_precompile_headers(${PROJECT_NAME} PRIVATE <pch.hpp>)
"""

[cmake.compilers]
c = "/usr/bin/gcc-12"
cxx = "/usr/bin/g++-12"

[cmake.visual_studio]
platform = "x64"
toolset = "v143"

Platform-Specific Configuration

Configure settings per platform (windows, linux, macos):

[platform.windows]
defines = ["WIN32", "_WINDOWS"]
flags = ["/W4"]
links = ["kernel32", "user32"]

[platform.linux]
defines = ["LINUX"]
flags = ["-Wall", "-Wextra"]
links = ["pthread", "dl"]

[platform.macos]
defines = ["MACOS"]
flags = ["-Wall"]
frameworks = ["Cocoa", "IOKit"] # macOS frameworks

Compiler-Specific Configuration

Configure settings per compiler (msvc, gcc, clang, apple_clang, mingw):

[compiler.msvc]
flags = ["/W4", "/WX", "/permissive-"]
defines = ["_CRT_SECURE_NO_WARNINGS"]

[compiler.gcc]
flags = ["-Wall", "-Wextra", "-Wpedantic"]

[compiler.clang]
flags = ["-Wall", "-Wextra", "-Wpedantic"]

[compiler.mingw]
flags = ["-Wall", "-Wextra"]
defines = ["MINGW"]

Platform + Compiler Combinations

Combine platform and compiler for fine-grained control:

[platform.windows.compiler.msvc]
flags = ["/W4"]
defines = ["_CRT_SECURE_NO_WARNINGS"]

[platform.windows.compiler.mingw]
defines = ["MINGW_BUILD"]
links = ["mingw32"]

[platform.linux.compiler.gcc]
flags = ["-Wall", "-Wextra", "-fPIC"]

Build Configurations

Define build configurations with specific compiler flags and defines:

[build.config.debug]
defines = ["DEBUG=1", "_DEBUG"]
flags = ["DEBUG_INFO", "NO_OPT"]

[build.config.release]
defines = ["NDEBUG=1"]
flags = ["OPTIMIZE", "LTO"]

[build.config.relwithdebinfo]
defines = ["NDEBUG=1"]
flags = ["OPTIMIZE", "DEBUG_INFO"]

Available Flags

Abstract flags that translate to compiler-specific options:

FlagDescriptionMSVCGCC/Clang
DEBUG_INFODebug symbols/Zi-g
NO_OPTDisable optimization/Od-O0
OPTIMIZEFull optimization/O2-O3
LTOLink-time optimization/GL-flto
UNICODEUnicode support/DUNICODE-DUNICODE