Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Build and Install MySQL Plugin for QT on MacOS
#!/bin/bash
which -s brew
if [[ $? != 0 ]] ; then
echo -e $'\e[31m# Install Homebrew\e[0m'
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
echo
fi
# Install MySQL Connector C
if brew ls --versions mysql-connector-c > /dev/null; then
echo -e $'\e[31m# Upgrading MySQL Connector\e[0m'
brew upgrade mysql-connector-c
echo
else
echo -e $'\e[31m# Installing MySQL Connector\e[0m'
brew install mysql-connector-c
echo
fi
# Locate QT Installation
which -s qmake
if [[ $? != 0 ]] ; then
read -p $'\e[31m -> Enter qmake location\e[0m (e.g. /etc/qt5/5.15.0/clang_64/bin/qmake): ' QMAKE
else
QMAKE="$(which qmake)"
fi
bash -c "${QMAKE} -query QT_VERSION"
if [ $? -ne 0 ]; then
echo -e $'\e[31m[ERROR] Invalid QMAKE path!\e[0m'
exit
fi
echo
QT_INSTALL_PREFIX="$(bash -c "${QMAKE} -query QT_INSTALL_PREFIX")"
QT_SOURCES="$(dirname $QT_INSTALL_PREFIX)/Src"
QT_SQLDRIVERS_SOURCES="${QT_SOURCES}/qtbase/src/plugins/sqldrivers"
MYSQL_CONNECTOR=$(brew --prefix mysql-connector-c)
MYSQL_INCDIR="${MYSQL_CONNECTOR}/include/mysql"
MYSQL_LIBDIR="${MYSQL_CONNECTOR}/lib"
echo -e $'\e[31m# Input variables:\e[0m'
echo "QMAKE = ${QMAKE}"
echo "QT_SQLDRIVERS_SOURCES = ${QT_SQLDRIVERS_SOURCES}"
echo "MYSQL_INCDIR = ${MYSQL_INCDIR}"
echo "MYSQL_LIBDIR = ${MYSQL_LIBDIR}"
echo
echo -e $'\e[31m# Build SQL Drivers Plugin\e[0m'
cd "${QT_SQLDRIVERS_SOURCES}" && echo $PWD
bash -cx "${QMAKE} sqldrivers.pro -- MYSQL_INCDIR=${MYSQL_INCDIR} MYSQL_LIBDIR=${MYSQL_LIBDIR}"
echo
echo -e $'\e[31m# Build QT MySQL Plugin\e[0m'
cd "${QT_SQLDRIVERS_SOURCES}/mysql" && echo $PWD
bash -cx "${QMAKE} mysql.pro"
bash -cx "make"
echo
echo -e $'\e[31m# Copying plugins to QT dist\e[0m'
cp -vr "${QT_SQLDRIVERS_SOURCES}/plugins/sqldrivers/." "${QT_INSTALL_PREFIX}/plugins/sqldrivers/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment