Skip to content

Repository files navigation

MakeBuilder

A CMake-based meta-build system that automatically generates CMakeLists.txt files from project directory structure.

Overview

MakeBuilder scans your project's directory structure and automatically generates CMakeLists.txt files. Instead of manually writing build configuration for each module, you organize your code in directories and add minimal .module.config files.

Quick Start

  1. Build MakeBuilder:

    ./build.sh -release
  2. Run on your project:

    ./run.sh /path/to/your/project
  3. Build your project:

    cmake -B build -S . -G "Ninja Multi-Config"
    cmake --build build --config Release

Project Structure

myproject/
├── .project.config # Project-level settings
├── .module.config # Root module config (buildType = None)
├── src/
│ ├── .module.config # buildType = Executable
│ └── main.cpp
├── lib/
│ ├── .module.config # buildType = StaticLibrary
│ └── mylib.cpp
└── build/ # Generated by cmake

Configuration Files

.project.config (Project Root)

Located in the project root directory.

OptionDefaultDescription
requiredCMakeVersion3.12Minimum CMake version
cxxStandard17C++ standard version
compileOptions-Wall -WerrorCompiler flags (non-MSVC)
msvcCompileOptions/W3 /WXCompiler flags (MSVC)
precompileDefinitions(none)Preprocessor definitions
linkerGroupDependency(not set)Comma-separated list of dependencies to wrap with --start-group/--end-group (or 'all' for all libraries)

.module.config (Each Module)

Located in each module directory.

OptionDescription
nameModule identifier (defaults to directory name)
buildTypeModule type (see below)
precompileDefinitionsModule-specific definitions
optimizeLevelOptimization level override (0-3)
ignoreSubdirectoriesSpace-separated list of subdirectories to skip
linkerGroupDependencyComma-separated list of dependencies to wrap with --start-group/--end-group (or 'all' for all libraries)
includeSemicolon-separated include directories (relative to module)
dependencySemicolon-separated module dependencies
librarySemicolon-separated libraries to link
linkDirectorySemicolon-separated linker directories
frameworkSemicolon-separated frameworks to link

Build Types

TypeDescription
NoneNot a module, but may contain valid submodules
IgnoredSkip this directory
HeaderOnlyHeader files only (no compilation)
ExecutableProduces an executable
StaticLibraryStatic library (.a/.lib)
SharedLibraryShared library (.so/.dll)
ExternalLibraryExternal library directory

Circular Dependency Resolution

Static library linking with gcc/g++ can fail with circular dependencies. The linker processes libraries left-to-right and may fail to resolve symbols that are defined later in the dependency chain.

Solution: Use linker group flags (--start-group/--end-group) to let the linker repeatedly scan the group until all symbols are resolved.

Configuration Options:

OptionDescription
linkerGroupDependencyComma-separated list of dependency names to wrap. Use all to wrap all libraries.

Examples:

# .project.config or .module.config# Option 1: Group all libraries (simplest)linkerGroupDependency=all# Option 2: Group specific dependencies (recommended)linkerGroupDependency=Core,Math,OSAL# Option 3: Disable linker group# (Simply do not set linkerGroupDependency)

Generated CMakeLists.txt (with Option 2):

target_link_libraries (MyTarget-Wl,--start-groupCoreMathOSAL-Wl,--end-groupExternalLibInternalLib
)

Configuration Hierarchy:

  1. Check .module.config in the module directory
  2. Fall back to .project.config in the project root
  3. If neither is set, the feature is disabled

Module Specifier Files

Optional files placed in module directories:

FileDescription
customCMake.txtIts contents will be added to CMakeLists.txt for custom usage

File Detection

MakeBuilder automatically detects source and header files:

  • Source files: .c, .cpp
  • Header files: .h, .hpp, .inl

Multi-Configuration Build

You can use the provided build script for convenience:

./build.sh -dev -debug -release

Alternatively, you can use CMake directly:

cmake -B build -G "Ninja Multi-Config" -S .
cmake --build build --config Debug
cmake --build build --config Dev
cmake --build build --config Release

Build Types:

ConfigFlagsUse Case
Debug-g -O0Development with debug symbols
Dev-g -O1Optimized but with debug info
Release-O3Full optimization

Note: For Windows, use the .bat versions of the scripts (e.g., build.bat, run.bat).

Testing

Run built-in test cases using the provided scripts:

./runDebug.sh . --test-run
./runDev.sh . --test-run
./run.sh . --test-run

Note: Test cases can specify pre-execution commands in a pretest_commands.txt file located within the test directory. Each line in this file is executed as a system command before running makebuild.

Test cases are located in TestCases/: ...

  • 01_simple_executable - Basic executable build
  • 02_static_library - Static library build
  • 03_external_library - External library integration (uses pretest_commands.txt)
  • 04_objective_c - Objective-C support

Requirements

  • CMake 3.12 or higher
  • C++ compatible compiler
  • Ninja (recommended) or Xcode generator on macOS

About

Help building a 'cmake' project with existing sources based on its directory structure

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages