|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Utility script to download and build libpng |
| 4 | +# |
| 5 | +# Copyright Contributors to the OpenImageIO project. |
| 6 | +# SPDX-License-Identifier: Apache-2.0 |
| 7 | +# https://github.com/AcademySoftwareFoundation/OpenImageIO |
| 8 | + |
| 9 | +# Exit the whole script if any command fails. |
| 10 | +set -ex |
| 11 | + |
| 12 | +# Repo and branch/tag/commit of libpng to download if we don't have it yet |
| 13 | +LIBPNG_REPO=${LIBPNG_REPO:=https://github.com/glennrp/libpng.git} |
| 14 | +LIBPNG_VERSION=${LIBPNG_VERSION:=v1.6.35} |
| 15 | + |
| 16 | +# Where to put libpng repo source (default to the ext area) |
| 17 | +LIBPNG_SRC_DIR=${LIBPNG_SRC_DIR:=${PWD}/ext/libpng} |
| 18 | +# Temp build area (default to a build/ subdir under source) |
| 19 | +LIBPNG_BUILD_DIR=${LIBPNG_BUILD_DIR:=${LIBPNG_SRC_DIR}/build} |
| 20 | +# Install area for libpng (default to ext/dist) |
| 21 | +LIBPNG_INSTALL_DIR=${LIBPNG_INSTALL_DIR:=${PWD}/ext/dist} |
| 22 | +#LIBPNG_CONFIG_OPTS=${LIBPNG_CONFIG_OPTS:=} |
| 23 | + |
| 24 | +pwd |
| 25 | +echo "libpng install dir will be: ${LIBPNG_INSTALL_DIR}" |
| 26 | + |
| 27 | +mkdir -p ./ext |
| 28 | +pushd ./ext |
| 29 | + |
| 30 | +# Clone libpng project from GitHub and build |
| 31 | +if [[ ! -e ${LIBPNG_SRC_DIR} ]] ; then |
| 32 | + echo "git clone ${LIBPNG_REPO} ${LIBPNG_SRC_DIR}" |
| 33 | + git clone ${LIBPNG_REPO} ${LIBPNG_SRC_DIR} |
| 34 | +fi |
| 35 | +cd ${LIBPNG_SRC_DIR} |
| 36 | + |
| 37 | + |
| 38 | +echo "git checkout ${LIBPNG_VERSION} --force" |
| 39 | +git checkout ${LIBPNG_VERSION} --force |
| 40 | + |
| 41 | +if [[ -z $DEP_DOWNLOAD_ONLY ]]; then |
| 42 | + time cmake -S . -B ${LIBPNG_BUILD_DIR} -DCMAKE_BUILD_TYPE=Release \ |
| 43 | + -DCMAKE_INSTALL_PREFIX=${LIBPNG_INSTALL_DIR} \ |
| 44 | + -DPNG_EXECUTABLES=OFF \ |
| 45 | + -DPNG_TESTS=OFF \ |
| 46 | + ${LIBPNG_CONFIG_OPTS} |
| 47 | + time cmake --build ${LIBPNG_BUILD_DIR} --config Release --target install |
| 48 | +fi |
| 49 | + |
| 50 | +# ls -R ${LIBPNG_INSTALL_DIR} |
| 51 | +popd |
| 52 | + |
| 53 | + |
| 54 | +# Set up paths. These will only affect the caller if this script is |
| 55 | +# run with 'source' rather than in a separate shell. |
| 56 | +export PNG_ROOT=$LIBPNG_INSTALL_DIR |
| 57 | + |
0 commit comments