MC-CPP uses CMake as its build system and includes all required dependencies in the source tree.
Prerequisites
Install a C++20 Compiler
Windows: MinGW-w64 (GCC 10+) or MSVC 2019+Linux: GCC 10+ or Clang 11+sudo apt install build-essential cmake # Debian/Ubuntu
sudo dnf install gcc-c++ cmake # Fedora
macOS: Xcode Command Line Tools Install CMake
CMake 3.17 or higher is required.Windows: Download from cmake.orgLinux:sudo apt install cmake # Debian/Ubuntu
macOS:Verify installation: Clone the Repository
git clone <repository-url>
cd MC-CPP
Build Instructions
All dependencies (GLFW, GLAD, GLM, stb, zlib, miniaudio) are included in the include/ directory - no external package manager needed!
# Use the provided compile script
compile.bat
# Or manually:
cmake -G "MinGW Makefiles" -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
CMake Configuration Options
The CMakeLists.txt (source:/home/daytona/workspace/source/CMakeLists.txt:1) configures the project with optimized defaults:
Build Type
# Defaults to Release if not specified
-DCMAKE_BUILD_TYPE=Release
Compiler Optimizations
The build system automatically applies platform-specific optimizations:
MSVC (Windows):
/O2 - Maximum optimization
/LTCG - Link-time code generation
/permissive- - Standards conformance
GCC/Clang (Linux/macOS):
-O3 - Aggressive optimization
-march=native -mtune=native - CPU-specific tuning
-flto=6 - Link-time optimization with 6 parallel jobs
Interprocessural optimization (IPO/LTO) is enabled by default via CMAKE_INTERPROCEDURAL_OPTIMIZATION=ON for maximum performance.
C++ Standard
The project requires C++20:
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Build Targets
The build system creates multiple executables:
Main Game
# Executable: MC-CPP (or MC-CPP.exe on Windows)
cd build
./MC-CPP
Unit Tests
# Test executable with headless mode
./mc_tests
Defined in CMakeLists.txt (source:/home/daytona/workspace/source/CMakeLists.txt:64) with the UNIT_TEST preprocessor definition.
# Benchmark hotspots
./mc_bench
Defined in CMakeLists.txt (source:/home/daytona/workspace/source/CMakeLists.txt:68) for profiling critical code paths.
Asset Copying
CMake automatically copies required assets to the build directory:
file(COPY ${CMAKE_SOURCE_DIR}/assets DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/data DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/save DESTINATION ${CMAKE_BINARY_DIR})
This ensures:
- assets/ - Shaders, textures, fonts, audio files
- data/ - Block definitions (
blocks.mccpp)
- save/ - World save directory
are available when running the executable from the build directory.
The build system links appropriate OpenGL and windowing libraries:
target_link_libraries(${PROJECT_NAME} PRIVATE
glfw glad zlib opengl32 gdi32
)
Incremental vs Clean Builds
Incremental Build (Faster)
The Windows compile script (compile.bat) performs incremental builds by default:
# CMake detects existing build/ and only rebuilds changed files
cmake -G "MinGW Makefiles" -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
Clean Build (From Scratch)
The Linux/macOS script (compile.sh) performs clean builds:
rm -rf build
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release --parallel
Clean builds take longer but ensure no stale build artifacts. Use them when switching between Debug/Release or after major code changes.
Troubleshooting
Compiler Not Found
If CMake can’t find your compiler:
# Specify compiler explicitly
cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -S . -B build
Linux: Install OpenGL development libraries
sudo apt install libgl1-mesa-dev libglu1-mesa-dev # Debian/Ubuntu
sudo dnf install mesa-libGL-devel # Fedora
Build Fails with Link Errors
On Linux, if you see lseek errors from zlib:
# The CMakeLists.txt already handles this with:
add_compile_definitions(Z_HAVE_UNISTD_H)
add_compile_definitions(_GNU_SOURCE)
If issues persist, ensure you’re using a recent CMake version:
cmake --version # Should be 3.17+
Next Steps
Once the build completes successfully, proceed to the Quickstart Guide to run the game and learn the controls.