build: libavr rides as the pinned submodule

The submodule replaces FetchContent and the unpinned forge fallback;
LIBAVR_ROOT stays as the tandem-development override, the presets take the
toolchain file from the submodule, and the Studio project's include path
anchors there — correct by construction.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-28 00:29:38 +02:00
parent 2cdf56f8d6
commit 5afe29359c
6 changed files with 28 additions and 22 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "libavr"]
path = libavr
url = ../libavr.git

View File

@@ -2,18 +2,19 @@ cmake_minimum_required(VERSION 3.28)
project(fantemp LANGUAGES CXX) project(fantemp LANGUAGES CXX)
# libavr from a local checkout (LIBAVR_ROOT) or the forge; the toolchain # libavr rides as the pinned submodule; LIBAVR_ROOT (cache or environment)
# file comes from the same checkout via CMakePresets.json. # overrides it for tandem development against a working tree. The toolchain
include(FetchContent) # file comes from the submodule via CMakePresets.json either way.
if(NOT LIBAVR_ROOT AND DEFINED ENV{LIBAVR_ROOT}) if(NOT LIBAVR_ROOT AND DEFINED ENV{LIBAVR_ROOT})
set(LIBAVR_ROOT $ENV{LIBAVR_ROOT}) set(LIBAVR_ROOT $ENV{LIBAVR_ROOT})
endif() endif()
if(LIBAVR_ROOT) if(NOT LIBAVR_ROOT)
FetchContent_Declare(libavr SOURCE_DIR ${LIBAVR_ROOT}) set(LIBAVR_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/libavr)
else()
FetchContent_Declare(libavr GIT_REPOSITORY git@git.blackmark.me:avr/libavr.git GIT_TAG main)
endif() endif()
FetchContent_MakeAvailable(libavr) if(NOT EXISTS ${LIBAVR_ROOT}/CMakeLists.txt)
message(FATAL_ERROR "libavr not found at ${LIBAVR_ROOT} — run: git submodule update --init libavr")
endif()
add_subdirectory(${LIBAVR_ROOT} libavr-build)
add_executable(fantemp src/main.cpp) add_executable(fantemp src/main.cpp)
target_link_libraries(fantemp PRIVATE libavr) target_link_libraries(fantemp PRIVATE libavr)

View File

@@ -6,7 +6,7 @@
"hidden": true, "hidden": true,
"generator": "Ninja", "generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}", "binaryDir": "${sourceDir}/build/${presetName}",
"toolchainFile": "$env{LIBAVR_ROOT}/cmake/avr-toolchain.cmake", "toolchainFile": "${sourceDir}/libavr/cmake/avr-toolchain.cmake",
"cacheVariables": { "cacheVariables": {
"CMAKE_BUILD_TYPE": "Release", "CMAKE_BUILD_TYPE": "Release",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON",

View File

@@ -12,10 +12,13 @@ log) is gone: the Beta equation and the cubic fan curve are evaluated
consteval into flash tables — the firmware itself never touches floating consteval into flash tables — the firmware itself never touches floating
point. point.
Build against a libavr checkout: libavr rides as the `libavr/` submodule, pinned to the commit this firmware
builds against; `LIBAVR_ROOT` (cache or environment) overrides it for
development against a working tree:
```sh ```sh
LIBAVR_ROOT=/path/to/libavr cmake --preset atmega328p-generated git submodule update --init libavr
cmake --preset atmega328p-generated
cmake --build --preset atmega328p-generated cmake --build --preset atmega328p-generated
``` ```
@@ -25,15 +28,13 @@ cmake --build --preset atmega328p-generated
builds the same firmware — byte-identical `.text` and `.data` to the CMake builds the same firmware — byte-identical `.text` and `.data` to the CMake
build — from the same sources, with the flags mirrored by hand. build — from the same sources, with the flags mirrored by hand.
Studio expects libavr checked out **beside this repo**, and finds it at Studio finds libavr in the **submodule**, at
`$(MSBuildProjectDirectory)\..\..\libavr\include`anchored to the project `$(MSBuildProjectDirectory)\..\libavr\include`correct by construction, and
rather than written relative to the generated makefile, which runs from the anchored to the project rather than written relative to the generated makefile,
configuration's output directory and would need a different number of `..`. which runs from the configuration's output directory and would need a different
Unlike the CMake build there is no `LIBAVR_ROOT` to point elsewhere: an number of `..`. Unlike the CMake build there is no `LIBAVR_ROOT` to point
environment variable set in a shell is not visible to Studio launched from the elsewhere: an environment variable set in a shell is not visible to Studio
Start menu, which fails as a missing `libavr/libavr.hpp` rather than as anything launched from the Start menu which is what the submodule answers.
about the variable. Pinning libavr as a submodule is the better answer and is on
libavr's task list.
It also needs a GCC 16.1 toolchain registered as flavour `avr-g++-16.1.0`; It also needs a GCC 16.1 toolchain registered as flavour `avr-g++-16.1.0`;
nothing older can compile `-std=c++26`. nothing older can compile `-std=c++26`.

View File

@@ -57,7 +57,7 @@
</avrgcccpp.compiler.symbols.DefSymbols> </avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.directories.IncludePaths> <avrgcccpp.compiler.directories.IncludePaths>
<ListValues> <ListValues>
<Value>$(MSBuildProjectDirectory)\..\..\libavr\include</Value> <Value>$(MSBuildProjectDirectory)\..\libavr\include</Value>
</ListValues> </ListValues>
</avrgcccpp.compiler.directories.IncludePaths> </avrgcccpp.compiler.directories.IncludePaths>
<avrgcccpp.compiler.optimization.level>Optimize for size (-Os)</avrgcccpp.compiler.optimization.level> <avrgcccpp.compiler.optimization.level>Optimize for size (-Os)</avrgcccpp.compiler.optimization.level>
@@ -86,7 +86,7 @@
</avrgcccpp.compiler.symbols.DefSymbols> </avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.directories.IncludePaths> <avrgcccpp.compiler.directories.IncludePaths>
<ListValues> <ListValues>
<Value>$(MSBuildProjectDirectory)\..\..\libavr\include</Value> <Value>$(MSBuildProjectDirectory)\..\libavr\include</Value>
</ListValues> </ListValues>
</avrgcccpp.compiler.directories.IncludePaths> </avrgcccpp.compiler.directories.IncludePaths>
<avrgcccpp.compiler.optimization.level>Optimize debugging experience (-Og)</avrgcccpp.compiler.optimization.level> <avrgcccpp.compiler.optimization.level>Optimize debugging experience (-Og)</avrgcccpp.compiler.optimization.level>

1
libavr Submodule

Submodule libavr added at 43b1f34ed1