# Note that this script can accept some limited command-line arguments, run
# `julia build_tarballs.jl --help` to see a usage message.
using BinaryBuilder, Pkg

name = "assimp"
version = v"6.0.4"

# Collection of sources required to complete build
sources = [
    GitSource("https://github.com/assimp/assimp.git",
              "e0b52347c6e52de2827ec957a9ebf00ce3c54f79"),
]

# Bash recipe for building across all platforms
script = raw"""
# Need newer cmake from JLL
apk del cmake

cd $WORKSPACE/srcdir
cd assimp/
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_TOOLCHAIN_FILE="${CMAKE_TARGET_TOOLCHAIN}" \
    -DCMAKE_BUILD_TYPE=Release \
    -DASSIMP_BUILD_ASSIMP_TOOLS=false \
    -DASSIMP_BUILD_TESTS=false \
    -DASSIMP_INSTALL_PDB=false \
    -DASSIMP_DOUBLE_PRECISION=false \
    -DINJECT_DEBUG_POSTFIX=false \
    -DASSIMP_WARNINGS_AS_ERRORS=OFF \

make -j${nproc}
make install
install_license ../LICENSE
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
platforms = supported_platforms()
platforms = expand_cxxstring_abis(platforms)

platforms_win = filter(Sys.iswindows, platforms)
platforms = setdiff(platforms, platforms_win)

# The products that we will ensure are always built
products = [
    LibraryProduct("libassimp", :libassimp)
]

# Dependencies that must be installed before this package can be built
dependencies = [
    HostBuildDependency("CMake_jll"),
    Dependency("Zlib_jll")
]

const YGGDRASIL_DIR = "../.."
include(joinpath(YGGDRASIL_DIR, "fancy_toys.jl"))

# Build the tarballs, and possibly a `build.jl` as well.
if any(should_build_platform.(triplet.(platforms_win)))
    build_tarballs(ARGS, name, version, sources, script, platforms_win, products, dependencies; preferred_gcc_version=v"12", julia_compat="1.6")
end
if any(should_build_platform.(triplet.(platforms)))
    build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; preferred_gcc_version=v"10", julia_compat="1.6")
end