build: extract CMake plugin/harness modules and add platform build scripts

Split CMakeLists.txt into cmake/Plugin.cmake (production formats and
MinGW link flags) and cmake/Harness.cmake (console test harness with
CTest registration). Add SERUMALT_BUILD_PLUGIN and SERUMALT_BUILD_TESTS
options so production and harness builds are mutually exclusive and
each omits the other's targets.

Add build_linux.sh, build_macos.sh, and build_harness.sh with host
validation, env-overridable build dirs, and explicit option flags.
Rewrite build_windows.sh to use the checked-in mingw64-toolchain.cmake
instead of regenerating it, validate all required tools, and stage
with cmake -E copy_directory.

Broaden .gitignore to cover all build_*/ directories.
This commit is contained in:
2026-09-09 13:24:09 +02:00
parent a1feeb76f0
commit f10409ad1e
8 changed files with 260 additions and 118 deletions
+50 -54
View File
@@ -7,60 +7,60 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
TOOLCHAIN_FILE="mingw64-toolchain.cmake"
BUILD_DIR="build_windows"
OUTPUT_DIR="SerumAlt_Windows"
TOOLCHAIN_FILE="$SCRIPT_DIR/mingw64-toolchain.cmake"
BUILD_DIR="${BUILD_DIR:-$SCRIPT_DIR/build_windows}"
BUILD_TYPE="${BUILD_TYPE:-Release}"
OUTPUT_DIR="${OUTPUT_DIR:-$SCRIPT_DIR/SerumAlt_Windows}"
PLUGIN_NAME="SerumAlt"
export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:-2}"
# 1. Check for the MinGW-w64 cross-compiler and exit if it is not found.
if ! command -v x86_64-w64-mingw32-g++ >/dev/null 2>&1; then
echo "ERROR: x86_64-w64-mingw32-g++ not found." >&2
echo "Please install the MinGW-w64 cross-compiler first, e.g.:" >&2
echo " sudo pacman -S mingw-w64-gcc" >&2
if [[ "$(uname -s)" != Linux ]]; then
echo "ERROR: build_windows.sh cross-compiles from Linux using MinGW-w64." >&2
exit 1
fi
# 1. Check for the host tools and MinGW-w64 cross-compiler.
for tool in cmake ninja pkg-config "${CC:-cc}" "${CXX:-c++}" \
x86_64-w64-mingw32-gcc x86_64-w64-mingw32-g++ \
x86_64-w64-mingw32-windres x86_64-w64-mingw32-ar \
x86_64-w64-mingw32-ranlib x86_64-w64-mingw32-strip; do
if ! command -v "$tool" >/dev/null 2>&1; then
echo "ERROR: $tool not found. See README.md prerequisites." >&2
exit 1
fi
done
echo "Found: $(command -v x86_64-w64-mingw32-g++)"
# 2. Generate the CMake toolchain file.
cat > "$TOOLCHAIN_FILE" <<'EOF'
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
set(CMAKE_AR x86_64-w64-mingw32-ar)
set(CMAKE_RANLIB x86_64-w64-mingw32-ranlib)
set(CMAKE_STRIP x86_64-w64-mingw32-strip)
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
EOF
echo "Wrote toolchain file: $TOOLCHAIN_FILE"
# 2. Use the checked-in CMake toolchain file without overwriting it.
if [[ ! -f "$TOOLCHAIN_FILE" ]]; then
echo "ERROR: Toolchain file not found: $TOOLCHAIN_FILE" >&2
exit 1
fi
echo "Using toolchain file: $TOOLCHAIN_FILE"
# 3. Configure with CMake + Ninja (VST3-only cross build, no test harness).
cmake -S . -B "$BUILD_DIR" -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
echo "Configuring Windows VST3 in $BUILD_DIR ($BUILD_TYPE)..."
cmake -S "$SCRIPT_DIR" -B "$BUILD_DIR" -G Ninja \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" \
-DSERUMALT_BUILD_PLUGIN=ON \
-DSERUMALT_BUILD_TESTS=OFF
# 4. Build the VST3 target.
cmake --build "$BUILD_DIR" --target SerumAlt_VST3
echo "Building Windows VST3..."
cmake --build "$BUILD_DIR" --config "$BUILD_TYPE" --target SerumAlt_VST3
# 5. Inject the VST3 moduleinfo.json.
# The automatic manifest step is disabled when cross-compiling (see
# CMakeLists.txt), because JUCE's manifest helper is a host tool that would
# cmake/Plugin.cmake), because JUCE's manifest helper is a host tool that would
# otherwise be built as a Windows executable. The moduleinfo content is
# deterministic and platform-independent: it depends only on the plugin's
# name, manufacturer/plugin codes, and version, so we write the identical
# file that the native helper generates. Keep it in sync with the metadata
# in CMakeLists.txt (PLUGIN_CODE, PLUGIN_MANUFACTURER_CODE, VERSION).
VST3_BUNDLE="$BUILD_DIR/${PLUGIN_NAME}_artefacts/Release/VST3/$PLUGIN_NAME.vst3"
# deterministic for this Windows plugin: it depends on the plugin's
# name, manufacturer/plugin codes, and version, so we write the same metadata
# that the native Windows helper generates. Keep it in sync with the metadata
# in CMakeLists.txt and cmake/Plugin.cmake, including the vendored VST3 SDK version.
VST3_BUNDLE="$BUILD_DIR/${PLUGIN_NAME}_artefacts/$BUILD_TYPE/VST3/$PLUGIN_NAME.vst3"
echo "Writing Windows VST3 manifest..."
mkdir -p "$VST3_BUNDLE/Contents/Resources"
cat > "$VST3_BUNDLE/Contents/Resources/moduleinfo.json" <<'EOF'
{
@@ -73,8 +73,8 @@ cat > "$VST3_BUNDLE/Contents/Resources/moduleinfo.json" <<'EOF'
"Flags": {
"Unicode": true,
"Classes Discardable": false,
"Component Non Discardable": false,
},
"Component Non Discardable": false
}
},
"Classes": [
{
@@ -86,12 +86,11 @@ cat > "$VST3_BUNDLE/Contents/Resources/moduleinfo.json" <<'EOF'
"SDKVersion": "VST 3.7.8",
"Sub Categories": [
"Instrument",
"Synth",
"Synth"
],
"Class Flags": 2,
"Cardinality": 2147483647,
"Snapshots": [
],
"Snapshots": []
},
{
"CID": "ABCDEF011234ABCD53616C7453657261",
@@ -102,12 +101,11 @@ cat > "$VST3_BUNDLE/Contents/Resources/moduleinfo.json" <<'EOF'
"SDKVersion": "VST 3.7.8",
"Sub Categories": [
"Instrument",
"Synth",
"Synth"
],
"Class Flags": 2,
"Cardinality": 2147483647,
"Snapshots": [
],
"Snapshots": []
},
{
"CID": "ABCDEF01C0DEF00D53616C7453657261",
@@ -118,17 +116,15 @@ cat > "$VST3_BUNDLE/Contents/Resources/moduleinfo.json" <<'EOF'
"SDKVersion": "VST 3.7.8",
"Class Flags": 0,
"Cardinality": 2147483647,
"Snapshots": [
],
},
],
"Snapshots": []
}
]
}
EOF
# 6. Copy the resulting .vst3 bundle to SerumAlt_Windows/.
mkdir -p "$OUTPUT_DIR"
rm -rf "$OUTPUT_DIR/$PLUGIN_NAME.vst3"
cp -R "$BUILD_DIR/${PLUGIN_NAME}_artefacts/Release/VST3/$PLUGIN_NAME.vst3" "$OUTPUT_DIR/"
# 6. Copy the resulting .vst3 bundle to SerumAlt_Windows/ without deleting files.
echo "Staging Windows VST3 in $OUTPUT_DIR..."
cmake -E copy_directory "$VST3_BUNDLE" "$OUTPUT_DIR/$PLUGIN_NAME.vst3"
echo
echo "Done. Windows VST3 plugin at: $SCRIPT_DIR/$OUTPUT_DIR/$PLUGIN_NAME.vst3"
echo "Done. Windows VST3 plugin at: $OUTPUT_DIR/$PLUGIN_NAME.vst3"