Project with CMs as examples - TelepathyIM/telepathy-qt GitHub Wiki

To simplify development process, it is useful to have TelepathyQt and connection managers in a single project.

Follow script can be used to (optionally) integrate Morse and Nonsense connection managers as TelepathyQt examples with all needed custom libraries (TelegramQt and QXmpp) and still have all projects in different directories to keep git operations the same.

Usage:

  • Create a new file in the working directory (say, bundle.sh) and copy/paste the script content to the file
  • sh bundle.sh
  • The script will extract subscripts and suggest you to run the scripts to clone and prepare sources.
  • The script creates "telepathy-bundle" directory with projects sources and bin subdirectory with integration scripts.
  • If you rejected automatic source setup, then (in the "telepathy-bundle" directory) you need to either:
    • Run bin/all.sh to setup both Morse and Nonsense as TelepathyQt examples.
    • Run bin/download-morse.sh && bin/link-morse.sh && bin/cmake-morse.sh to setup TelepathyQt with Morse and TelegramQt.
    • Run bin/download-nonsense.sh && bin/link-nonsense.sh && bin/cmake-nonsense.shto setup TelepathyQt with Nonsense and QXmpp.
  • Projects directories (except telepathy-qt/examples) are not changed and are suitable for usual VCS operations.
  • If you added or removed source file (may be via checking out a branch), run bin/link-<cm>.sh && bin/cmake-<cm>.sh to apply the changes. (Manual cmake re-configuration might be required as well)

Script:

#!/bin/sh

mkdir telepathy-bundle
cd telepathy-bundle

mkdir bin
echo bin/all.sh
cat << 'EOF' > bin/all.sh
#!/bin/sh

# figure out the absolute path to the script being run a bit
# non-obvious, the ${0%/*} pulls the path out of $0, cd's into the
# specified directory, then uses $PWD to figure out where that
# directory lives - and all this in a subshell, so we don't affect
# $PWD

SCRIPTS_DIR=$(cd "${0%/*}" && echo $PWD)

BUNDLE_URL_PREFIX="https://github.com/"

read -p "Use ssh url for git clone (requires ssh key)? " yn
case $yn in
    [Yy]* ) BUNDLE_URL_PREFIX="[email protected]:" ;;
    * ) echo "Fallback to https urls.";;
esac

if [ ! -d "telepathy-qt" ]; then
    git clone ${BUNDLE_URL_PREFIX}TelepathyQt/telepathy-qt.git
fi

export BUNDLE_URL_PREFIX
$SCRIPTS_DIR/morse-01-download.sh
$SCRIPTS_DIR/morse-02-link.sh
$SCRIPTS_DIR/morse-03-cmake.sh

$SCRIPTS_DIR/nonsense-01-download.sh
$SCRIPTS_DIR/nonsense-02-link.sh
$SCRIPTS_DIR/nonsense-03-cmake.sh

echo "Bundle is ready."
echo "Use git for all projects as usual, but use single telepathy-qt project to build everything."
EOF
chmod +x bin/all.sh
echo bin/morse-01-download.sh
cat << 'EOF' > bin/morse-01-download.sh
#!/bin/sh

GIT_DEPTH="--depth 1"

URL_PREFIX=$BUNDLE_URL_PREFIX

if [ -z "$URL_PREFIX" ]; then
    URL_PREFIX="https://github.com/"
fi

if [ ! -d "telepathy-qt" ]; then
    git clone ${URL_PREFIX}TelepathyQt/telepathy-qt.git $GIT_DEPTH
fi

git clone ${URL_PREFIX}TelepathyQt/telepathy-morse.git
git clone ${URL_PREFIX}Kaffeine/telegram-qt.git
EOF
chmod +x bin/morse-01-download.sh
echo bin/morse-02-link.sh
cat << 'EOF' > bin/morse-02-link.sh
#!/bin/sh

TOP_DIR=`pwd`
cd telepathy-qt/examples

if [ -d "morse" ]; then
  echo "morse directory is already exists. Say 'y' to remove (and recreate)."
  rm -rI morse
fi

mkdir morse
cd morse
ln -s $TOP_DIR/telepathy-morse/* .
rm CMakeLists.txt

mkdir telegram-qt
cd telegram-qt
ln -s $TOP_DIR/telegram-qt/* .
rm CMakeLists.txt
EOF
chmod +x bin/morse-02-link.sh
echo bin/morse-03-cmake.sh
cat << 'EOF' > bin/morse-03-cmake.sh
#!/bin/sh

TOP_DIR=`pwd`
cd telepathy-qt/examples

if [ `grep morse CMakeLists.txt|wc -l` = '0' ]; then
 echo "add_subdirectory(morse)" >> CMakeLists.txt
fi

cd morse
cp $TOP_DIR/telepathy-morse/CMakeLists.txt .

# Remove all find_package TelepathyQt
sed -i '/set(TELEPATHY_QT_VERSION/d' CMakeLists.txt
sed -i '/find_package(TelepathyQt/d' CMakeLists.txt

# Remove all find_package TelegramQt
sed -i '/find_package(TelegramQt/d' CMakeLists.txt

sed -i 's/${TELEGRAM_QT._INCLUDE_DIR}/telegram-qt\/TelegramQt/g' CMakeLists.txt

# Replace TelepathyQt CMake-found libraries with TpQt "this-project" ones.
sed -i 's/\${TELEPATHY_QT._LIBRARIES}/telepathy-qt\${QT_VERSION_MAJOR}/g' CMakeLists.txt
sed -i 's/\${TELEPATHY_QT._SERVICE_LIBRARIES}/telepathy-qt\${QT_VERSION_MAJOR}-service/g' CMakeLists.txt

sed -i 's/\${TELEGRAM_QT._LIBRARIES}/TelegramQt\${QT_VERSION_MAJOR}/g' CMakeLists.txt

# Promote TelepathyQt version
sed -i '3i set(TELEPATHY_QT_VERSION ${TP_QT_MAJOR_VERSION}.${TP_QT_MINOR_VERSION}.${TP_QT_MICRO_VERSION})' CMakeLists.txt

echo "add_subdirectory(telegram-qt)" >> CMakeLists.txt

cd telegram-qt
cp $TOP_DIR/telegram-qt/CMakeLists.txt .

sed -i '/CMakePackageConfigHelpers/{q}' CMakeLists.txt

# Enable developer build
sed -i 's/if (DEVELOPER_BUILD)/if (TRUE)/' CMakeLists.txt
EOF
chmod +x bin/morse-03-cmake.sh
echo bin/nonsense-01-download.sh
cat << 'EOF' > bin/nonsense-01-download.sh
#!/bin/sh

GIT_DEPTH="--depth 1"

URL_PREFIX=$BUNDLE_URL_PREFIX

if [ -z "$URL_PREFIX" ]; then
    URL_PREFIX="https://github.com/"
fi

if [ ! -d "telepathy-qt" ]; then
    git clone ${URL_PREFIX}TelepathyQt/telepathy-qt.git $GIT_DEPTH
fi

git clone ${URL_PREFIX}TelepathyQt/telepathy-nonsense.git
git clone ${URL_PREFIX}qxmpp-project/qxmpp.git $GIT_DEPTH

EOF
chmod +x bin/nonsense-01-download.sh
echo bin/nonsense-02-link.sh
cat << 'EOF' > bin/nonsense-02-link.sh
#!/bin/sh

CM_DIR=telepathy-qt/examples/nonsense
TOP_DIR=`pwd`

if [ -d "$CM_DIR" ]; then
  echo "$CM_DIR already exists. Say 'y' to remove (and recreate)."
  rm -rI $CM_DIR
fi

mkdir $CM_DIR

cd $CM_DIR
ln -s $TOP_DIR/telepathy-nonsense/*.cc .
ln -s $TOP_DIR/telepathy-nonsense/*.hh .
ln -s $TOP_DIR/telepathy-nonsense/*.in .

mkdir qxmpp

cd qxmpp
ln -s $TOP_DIR/qxmpp/src .

EOF
chmod +x bin/nonsense-02-link.sh
echo bin/nonsense-03-cmake.sh
cat << 'EOF' > bin/nonsense-03-cmake.sh
#!/bin/sh

# Needed for DOWNLOAD_TOOL
source utils.sh

TOP_DIR=`pwd`

cd telepathy-qt/examples

if [ `grep nonsense CMakeLists.txt|wc -l` = '0' ]; then
 echo "add_subdirectory(nonsense)" >> CMakeLists.txt
fi

cd nonsense
cp $TOP_DIR/telepathy-nonsense/CMakeLists.txt .

# Remove all find_package TelepathyQt
sed -i '/find_package(TelepathyQt/d' CMakeLists.txt

# Remove all find_package QXmpp
sed -i '/find_package(QXmpp/d' CMakeLists.txt

# ${QXMPP_INCLUDE_DIR} to qxmpp/src/base and qxmpp/src/client
sed -i 's/${QXMPP_INCLUDE_DIR}/qxmpp\/src\/base qxmpp\/src\/client/g' CMakeLists.txt

# Replace TelepathyQt CMake-found libraries with TpQt "this-project" ones.
sed -i 's/\${TELEPATHY_QT._LIBRARIES}/telepathy-qt\${QT_VERSION_MAJOR}/g' CMakeLists.txt
sed -i 's/\${TELEPATHY_QT._SERVICE_LIBRARIES}/telepathy-qt\${QT_VERSION_MAJOR}-service/g' CMakeLists.txt

sed -i 's/\${QXMPP_LIBRARIES}/qxmpp/g' CMakeLists.txt

echo "add_subdirectory(qxmpp)" >> CMakeLists.txt

cd qxmpp

QXMPP_CMAKE_URL="https://raw.githubusercontent.com/pol51/QXMPP-CMake/master/CMakeLists.txt"

$DOWNLOAD_TOOL $QXMPP_CMAKE_URL

echo "remove_definitions(-DQT_NO_CAST_FROM_ASCII)" >> CMakeLists.txt
EOF
chmod +x bin/nonsense-03-cmake.sh
echo bin/utils.sh
cat << 'EOF' > bin/utils.sh
DOWNLOAD_TOOL=""

if [ `which wget |wc -l` -ne 0 ]; then
  DOWNLOAD_TOOL="wget"
else
  if [ `which curl |wc -l` -ne 0 ]; then
    DOWNLOAD_TOOL = "curl --silent --remote-name"
  else
    echo "Unable to find wget or curl!"
  fi
fi
EOF
chmod +x bin/utils.sh
echo "Bundle scripts extracted."

read -p "Clone and prepare sources now? " yn
case $yn in
    [Yy]* ) bin/all.sh ;;
    * ) echo "Run bin/all.sh to continue.";;
esac
⚠️ **GitHub.com Fallback** ⚠️