Skip to content
Snippets Groups Projects
Commit 9d2123cf authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Make mongocxx install script more user friendly. Add a clear warning with what...

Make mongocxx install script more user friendly. Add a clear warning with what to do if mongocxx is missing.
parent 76c6b268
No related branches found
No related tags found
No related merge requests found
......@@ -22,3 +22,21 @@ add_subdirectory(source)
install_project()
add_subdirectory(scenarios)
if (TRUE)
find_package(libmongocxx QUIET)
find_package(libbsoncxx QUIET)
if (NOT libbsoncxx_FOUND OR NOT libbsoncxx_FOUND)
string(ASCII 27 Esc)
set(BoldYellow "${Esc}[1;33m")
set(ColourReset "${Esc}[m")
message(WARNING "${BoldYellow}\
The packages libbsoncxx or libbsoncxx not found. \
They are required to build the memory system (armem and related libraries). \
Please use this installation script to install libmongocxx and libbsoncxx:
cd ${PROJECT_SOURCE_DIR}/etc/mongocxx/ && ./install_mongocxx.sh ~/repos \
${ColourReset}")
endif()
endif()
#!/bin/bash
# By Fabian Peller 2021-06-10;
# Extended by Rainer Kartmann 2021-06-23;
if [ "$#" -ne 1 ]; then
echo "Usage: $0 CLONE-DIRECTORY" >&2
echo "Usage: $0 target-directory" >&2
echo -e " target-directory \t Directory where mongocxx should be placed (e.g. ~/repos)"
exit 1
fi
# Stolen from mycroft-core/dev_setup.sh // Rainer Kartmann
# If tput is available and can handle multiple colors
if found_exe tput ; then
if [[ $(tput colors) != "-1" && -z $CI ]]; then
GREEN=$(tput setaf 2)
BLUE=$(tput setaf 4)
CYAN=$(tput setaf 6)
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)
RESET=$(tput sgr0)
HIGHLIGHT=$YELLOW
fi
fi
function get_YN() {
# Loop until the user hits the Y or the N key
echo -e -n "Choice [${CYAN}Y${RESET}/${CYAN}N${RESET}]: "
while true; do
read -N1 -s key
case $key in
[Yy])
return 0
;;
[Nn])
return 1
;;
esac
done
}
extractDir="$1"
sourceDir="$extractDir/mongo-cxx-driver-r3.2.1"
installDir="$extractDir/mongo-cxx-driver-r3.2.1/build/install"
scriptDir="$(readlink -f "$(dirname "$0")")"
pwd="$(pwd)"
# You first have to install libbson-dev and libmongoc-dev (not necessary on the lab pcs)
#sudo apt install libbson-dev libmongoc-dev
......@@ -24,6 +62,73 @@ pwd="$(pwd)"
#sudo ln -s /usr/include/libmongoc-1.0/ /usr/lib/include/libmongoc-1.0
#sudo ln -s /usr/lib /usr/lib/lib
function install_deps()
{
APT_PACKAGE_LIST=(libbson-dev libmongoc-dev)
declare -a installed_packages
declare -a missing_packages
for pkg in "${APT_PACKAGE_LIST[@]}"; do
if dpkg -V "$pkg" > /dev/null 2>&1 ; then
installed_packages+=($pkg)
else
missing_packages+=($pkg)
fi
done
if [ ${#installed_packages[*]} -ne 0 ]; then
echo "$GREEN
The following apt packages are already installed: "
echo "${installed_packages[*]} $RESET"
fi
if [ ${#missing_packages[*]} -eq 0 ]; then
echo "$GREEN
No missing packages. $RESET"
echo ""
else
echo "$YELLOW
The following apt packages still need to be installed: "
echo "${missing_packages[*]} $RESET"
echo "
Do you want to install these packages and update some required
symlinks in /usr/lib/include/? (requires sudo)
Y)es, install missing packages via apt-get and update symlinks
N)o, don't install or I don't have sudo permissions"
if get_YN ; then
echo -e "$HIGHLIGHT Y - installing missing packages $RESET"
sudo apt-get install ${missing_packages[*]}
function verbose_ln()
{
echo "Updating symlink $2 -> $1"
sudo ln -s "$1" "$2"
}
sudo mkdir -p /usr/lib/include/
verbose_ln /usr/include/libbson-1.0/ /usr/lib/include/libbson-1.0
verbose_ln /usr/include/libbson-1.0/ /usr/lib/include/libbson-1.0
verbose_ln /usr/include/libmongoc-1.0/ /usr/lib/include/libmongoc-1.0
verbose_ln /usr/lib /usr/lib/lib
else
echo -e "$HIGHLIGHT N - not installing missing pacakges $RESET"
echo ""
fi
fi
}
install_deps
# Then you can build the mongocxx driver
mkdir $extractDir &> /dev/null || true
tar -xvf mongo-cxx-driver-r3.2.1.tar.gz -C $extractDir
......@@ -36,6 +141,21 @@ cmake .. -DBSON_LIBRARY="/usr/lib/x86_64-linux-gnu/libbson-1.0.so" -DMONGOC_LIBR
make -j`nproc`
make install
# Finally, tell RobotAPI where to find mongocxx
echo "You need to cmake RobotAPI now with: cmake -DCMAKE_PREFIX_PATH=$installDir .."
#armarx-dev exec --no-deps RobotAPI "cd build && cmake -DCMAKE_PREFIX_PATH=$installDir ."
echo "$HIGHLIGHT
You now need to cmake RobotAPI with:
cmake -DCMAKE_PREFIX_PATH=$installDir .. $RESET"
echo "
Should I do that for you?
Y)es, run cmake in RobotAPI
N)o, I'll do it myself"
if get_YN ; then
echo -e "$HIGHLIGHT Y - running cmake in RobotAPI $RESET"
armarx-dev exec --no-deps RobotAPI "cd build && cmake -DCMAKE_PREFIX_PATH=$installDir ."
else
echo -e "$HIGHLIGHT N - not running cmake in RobotAPI $RESET"
fi
......@@ -3,10 +3,14 @@ set(LIB_NAME armem)
armarx_component_set_name("${LIB_NAME}")
armarx_set_target("Library: ${LIB_NAME}")
SET(INSTALL_SCRIPT_MSG
"Please use the installation script in RobotAPI/etc/mongocxx to install libmongocxx and libbsoncxx."
)
find_package(libmongocxx QUIET)
armarx_build_if(libmongocxx_FOUND "libmongocxx not available. Please use the installation script in RobotAPI/etc/mongocxx to install libmongocxx and libbsoncxx.")
armarx_build_if(libmongocxx_FOUND "libmongocxx not available. ${INSTALL_SCRIPT_MSG}")
find_package(libbsoncxx QUIET)
armarx_build_if(libbsoncxx_FOUND "libbsoncxx not available. Please use the installation script in RobotAPI/etc/mongocxx to install libmongocxx and libbsoncxx.")
armarx_build_if(libbsoncxx_FOUND "libbsoncxx not available. ${INSTALL_SCRIPT_MSG}")
#message("LIBMONGOCXX:")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment