fix: enforce clean ofxPiMapper addon state and implement high-powered global compatibility header to resolve syntax and namespace errors

This commit is contained in:
Timothy Hofland
2026-03-15 09:04:01 +01:00
parent c0589b6c5e
commit e0e06978b2

View File

@ -101,9 +101,9 @@ fi
# 2.3 Install Dependencies
echo "Installing Core Dependencies..."
if command -v apt-get > /dev/null; then
DEBIAN_FRONTEND=noninteractive apt-get install -y git hostapd dnsmasq avahi-daemon curl ffmpeg build-essential libzmq3-dev libavahi-compat-libdnssd-dev wget
DEBIAN_FRONTEND=noninteractive apt-get install -y git hostapd dnsmasq avahi-daemon curl ffmpeg build-essential libzmq3-dev libavahi-compat-libdnssd-dev wget unzip
elif command -v pacman > /dev/null; then
pacman -S --noconfirm git hostapd dnsmasq avahi curl ffmpeg base-devel zeromq wget
pacman -S --noconfirm git hostapd dnsmasq avahi curl ffmpeg base-devel zeromq wget unzip
fi
# Install Node.js if missing
@ -248,27 +248,30 @@ sudo -u "$REAL_USER" git clone --depth 1 https://github.com/kr15h/ofxPiMapper.gi
cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper"
echo "Applying clean Global Compatibility Patches..."
# 1. Fix highlight patch
cat <<'EOF_PATCH' > /tmp/highlight.patch
# 1. Locate OscControl.cpp and apply highlight patch
OSC_CTRL=$(find src -name OscControl.cpp | head -n 1)
if [ -n "$OSC_CTRL" ]; then
cat <<'EOF_PATCH' > /tmp/highlight.patch
if (m.getAddress() == "/ofxPiMapper/surface/highlight"){
int surfaceIndex = m.getArgAsInt32(0);
mapper->getSurfaceManager()->selectSurface(surfaceIndex);
return;
}
EOF_PATCH
sed -i '/if (m.getAddress() == "\/ofxPiMapper\/surface\/select"){/r /tmp/highlight.patch' src/Osc/OscControl.cpp
rm -f /tmp/highlight.patch
sed -i '/if (m.getAddress() == "\/ofxPiMapper\/surface\/select"){/r /tmp/highlight.patch' "$OSC_CTRL"
rm -f /tmp/highlight.patch
fi
# 2. Fix unique_ptr and make_unique globally (Only if std:: is missing)
find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)unique_ptr\b/\1std::unique_ptr/g' {} +
find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)make_unique\b/\1std::make_unique/g' {} +
# 3. Create a single compatibility header for C++11
# 2. Create a high-powered compatibility header
cat <<'EOF_COMPAT' > src/cpp11_compat.h
#ifndef OFXPIMAPPER_CPP11_COMPAT_H
#define OFXPIMAPPER_CPP11_COMPAT_H
#include <memory>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#if __cplusplus < 201402L
namespace std {
template<typename T, typename... Args>
@ -277,26 +280,27 @@ namespace std {
}
}
#endif
// Explicitly bridge common namespaces to bypass C++20 strictness
using std::unique_ptr;
using std::make_unique;
using std::vector;
using std::string;
#endif
EOF_COMPAT
# 4. Include the compat header in the main addon header
sed -i '1i #include "cpp11_compat.h"' src/ofxPiMapper.h
# 5. Add memory header to all headers where unique_ptr is used
for f in $(grep -l "unique_ptr" src/*.h 2>/dev/null); do
sed -i '1i #include <memory>' "$f"
done
# 3. Inject the compatibility header into ALL headers
find src -name "*.h" -not -name "cpp11_compat.h" -exec sed -i '1i #include "cpp11_compat.h"' {} +
# Build Example
cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper/example_basic"
echo "Cleaning old objects..."
sudo -u "$REAL_USER" make clean
echo "Starting compilation (Forcing C++11 for Symbol Compatibility)..."
# Use -O2 and -fno-tree-vrp to prevent Internal Compiler Errors (ICE) on ARM
GLOBAL_FLAGS="-Wno-error -Wno-reorder -Wno-sign-compare -Wno-delete-non-virtual-dtor -std=c++11 -O2 -fno-tree-vrp"
sudo -u "$REAL_USER" make -j1 PLATFORM_CFLAGS="$GLOBAL_FLAGS" USER_CFLAGS="$GLOBAL_FLAGS" USER_CPPFLAGS="-std=c++11"
echo "Starting compilation (Stability Mode: -O1 + C++11)..."
# Use -O1 to prevent the compiler Segfault/Internal Error seen on Pi 3B with g++ 14
GLOBAL_FLAGS="-Wno-error -Wno-reorder -Wno-sign-compare -Wno-delete-non-virtual-dtor -std=c++11 -O1"
sudo -u "$REAL_USER" make -j1 PLATFORM_CFLAGS="$GLOBAL_FLAGS -I$REAL_HOME/openFrameworks/addons/ofxPiMapper/src" USER_CFLAGS="$GLOBAL_FLAGS" USER_CPPFLAGS="-std=c++11"
cp bin/example_basic /usr/local/bin/ofxPiMapper
chmod +x /usr/local/bin/ofxPiMapper