Python cross-platform build script for CMake projects on Windows

Опубликовано: 08 Июнь 2026
на канале: Scanframe
21
0

Simplifying C++ Multi-Platform Builds with a single Python script.

https://www.scanframe.com/export/build.py

Initially I created a similar functionality using Bash scripts (Cygwin)

(https://www.scanframe.com/export/build.py)

Cross-platform C++ development often means juggling multiple toolchains, environments, and build configurations.
After wrestling with this complexity, I built a unified solution using a comprehensive CMake build automation script which uses information from the presets json-configuration files.

What makes it powerful:
✅ Multi-Toolchain Support – Seamlessly switch between GNU, MinGW, MSVC, and ARM cross-compilers
✅ Cross-Platform Made Easy – Build for Linux, Windows, and ARM64 from a single environment
✅ Nested Execution – Chain Docker and Wine environments for specialized builds (yes, MSVC builds on Linux!)
✅ Interactive Interface – Curses-based menu system for selecting presets and targets
✅ Smart Environment Management – Automatic toolchain configuration with INI-based inheritance
✅ Complete Workflow Automation – Configure, build, test, package, and run—all in one command
✅ CI/CD Pipeline Docker – Run a complete workflow for all toolchains in CI/CD pipeline
✅ Run with Environment – Runs a build-target using the presets' environment

Example workflows:

● Linux native x86_64/aarch64: ./build.py -mbt gnu-debug
● Linux native in Docker: ./build.py docker -- -mbt gnu-debug
● Cross-compile for Linux ARM64: ./build.py docker -- -mbt ga-debug
● Cross-compile for Windows: ./build.py -mbt gw-debug
● MSVC on Linux via Wine: ./build.py wine -- -mbt msvc-debug
● MSVC on Linux via Wine in Docker: ./build.py docker -- wine -- -mbt msvc-debug
● MinGW on Windows: ./build.py -mbt mingw-debug
● MSVC on Windows: ./build.py -mbt msvc-debug

This approach has dramatically reduced build complexity in projects, enabling to focus on code rather than environment configuration.
The script leverages CMakePresets.json (+ CMakeUserPresets.json), supports custom toolchain paths, and handles the messy details of PATH variables, Wine prefixes, and Docker mounts automatically.
It allows building projects for multiple platforms and run the unittests on a single machine (Linux).
When necessary, the project can be built and debugged natively on any of the supported platforms.

📢 One unified interface for all platforms beats maintaining separate scripts for each toolchain.

#CPlusPlus #DevOps #BuildAutomation #CMake #CrossPlatform #DeveloperTools #SoftwareEngineering