#!/bin/sh
set -e

OPTIONS="
-DUNIX:BOOL=true
"
# -DBUILD_SHARED_LIBS:BOOL=true

if [ "$config_build_pic" = yes ]; then
    # untested, see https://stackoverflow.com/questions/38296756/what-is-the-idiomatic-way-in-cmake-to-add-the-fpic-compiler-option
    OPTIONS="$OPTIONS -DCMAKE_POSITION_INDEPENDENT_CODE=ON"
fi
if [ "$config_build_host" ]; then
    # cross is handled from the host-specific "cmake" which is setup globally
    true
fi

GEN_IS_VS=
if cmake --system-information | grep 'CMAKE_GENERATOR "' | grep -qi 'visual studio'; then
    # on msys[2] cmake might default to visual studio - not good for us, so we
    # override it later with -G"MSYS Makefiles"
    GEN_IS_VS=yes
fi

set -x
mkdir -p "$config_local_prefix"/tmp/freetype2_build
cd "$config_local_prefix"/tmp/freetype2_build
cmake ${GEN_IS_VS:+"-GMSYS Makefiles"} \
      -DCMAKE_INSTALL_PREFIX="$config_local_prefix" \
      -DLIB_INSTALL_DIR="$config_local_prefix"/lib \
      $OPTIONS "$@" "$config_freetype2_source"
