diff --git a/scripts/setup.sh b/scripts/setup.sh index c698be4..c6dbc47 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -261,31 +261,36 @@ fi # 2. Fix unique_ptr and missing memory headers globally (Idempotent) echo "Fixing namespaces and missing headers for C++11 compatibility..." -# First, clean up any previous double-patching bugs find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/std::std::/std::/g' {} + - -# Apply patch only if not already namespaced find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)unique_ptr\b/\1std::unique_ptr/g' {} + -# Custom make_unique for C++11 compatibility -cat <<'EOF_MAKE_UNIQUE' > /tmp/make_unique.patch +# Create a single compatibility header +cat <<'EOF_COMPAT' > src/cpp11_compat.h +#ifndef OFXPIMAPPER_CPP11_COMPAT_H +#define OFXPIMAPPER_CPP11_COMPAT_H +#include +#include #if __cplusplus < 201402L namespace std { template - unique_ptr make_unique(Args&&... args) { - return unique_ptr(new T(std::forward(args)...)); + std::unique_ptr make_unique(Args&&... args) { + return std::unique_ptr(new T(std::forward(args)...)); } } #endif -EOF_MAKE_UNIQUE +#endif +EOF_COMPAT +# Include the compat header in the main addon header +grep -q "cpp11_compat.h" src/ofxPiMapper.h || sed -i '1i #include "cpp11_compat.h"' src/ofxPiMapper.h + +# Also ensure make_unique is namespaced in the source +find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)make_unique\b/\1std::make_unique/g' {} + + +# Add memory header only where missing for f in $(find src -type f -name "*.h"); do grep -q "" "$f" || sed -i '1i #include ' "$f" - if ! grep -q "make_unique" "$f"; then - cat /tmp/make_unique.patch >> "$f" - fi done -rm -f /tmp/make_unique.patch # Build Example (Force C++11 for binary symbol compatibility with OF core) cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper/example_basic"