# This installation is for building macos 10.13 compatible releases including
# database drivers. IOW: For me

brew install python3 cmake pkg-config

# Compile SQL Drivers if necessary:

brew install mariadb-connector-c postgresql unixodbc

# Download Qt sources with the same version, currently:
#   qtbase-everywhere-src-5.15.1

./configure -recheck -sql-mysql -sql-odbc -sql-psql -opensource -confirm-license -feature-datestring \
      MYSQL_LIBDIR=$(pkg-config --variable=prefix libmariadb)/lib/mariadb \
      MYSQL_INCDIR=$(pkg-config --variable=prefix libmariadb)/include/mariadb/ \
      MYSQL_LIBS="-lmariadb" \
      PSQL_PREFIX=$(brew --prefix)/opt/postgresql@14 \
      ODBC_PREFIX=$(pkg-config --variable=prefix odbc)

make sub-plugins

https://github.com/PostgresApp/PostgresApp/releases/download/v2.6.2/Postgres-2.6.2-14.dmg



# Compile OpenSSL

#! /bin/sh
OSSL="openssl-3.0.8"
INSTALL="$(pwd)/install"

test -d "$OSSL"
for arch in x86_64 arm64; do
  mkdir -p "${OSSL}-${arch}"
  ( cd  "${OSSL}-${arch}" &&
    ../${OSSL}/Configure \
         darwin64-${arch}-cc shared \
	 --prefix="$INSTALL" \
         -mmacosx-version-min=10.14
 #   make -j6
  #  make install_sw
  )
  PARTS_crypto="$PARTS_crypto ${OSSL}-${arch}/libcrypto.3.dylib"
  PARTS_ssl="$PARTS_ssl ${OSSL}-${arch}/libssl.3.dylib"
done
rm -f "$INSTALL"/lib/libcrypto.3.dylib "$INSTALL"/lib/libssl.3.dylib
lipo -create -output "$INSTALL"/lib/libcrypto.3.dylib $PARTS_crypto
lipo -create -output "$INSTALL"/lib/libssl.3.dylib $PARTS_ssl

#Install Qt6
QT_VERSION="6.2.4"
pip install aqtinstall
aqt install-qt mac desktop $QT_VERSION

# Compile XCA
cmake -DOPENSSL_ROOT_DIR=$(pwd)/install \
      -DCMAKE_PREFIX_PATH=$(pwd)/$QT_VERSION/macos/lib/cmake \
      -B build xca

cmake --build build -j7
cd build && cpack
