Created
November 26, 2017 05:42
-
-
Save bc-lee/46cef7b39be2a9e645aa9e615fcf26d3 to your computer and use it in GitHub Desktop.
setup_conan.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function die { | |
echo "$*" 1>&2 ; | |
exit 1; | |
} | |
CC=${CC:-/usr/bin/gcc} | |
CXX=${CXX:-/usr/bin/g++} | |
echo "CC: $CC" | |
echo "CXX: $CXX" | |
_COMPILER_MACRO=$(echo '#include <stdlib.h>' | $CXX -dM -E -) | |
function get { | |
echo -n "$_COMPILER_MACRO" | grep "define $1" | sed -re "s/.*$1\s+(\S+)/\1/g" | |
} | |
GLIBC_MAJOR=$(get "__GLIBC__") | |
if [ -z "$GLIBC_MAJOR" ]; then | |
GLIBC_VER="" | |
else | |
GLIBC_MINOR=$(get "__GLIBC_MINOR__") | |
GLIBC_VER="$GLIBC_MAJOR.$GLIBC_MINOR" | |
fi | |
echo "GLIBC_VER: $GLIBC_VER" | |
COMPILER=$(get "__clang__") | |
if [ -n "$COMPILER" ]; then | |
COMPILER="clang" | |
else | |
COMPILER=$(get "__GNUC__") | |
if [ -n "$COMPILER" ]; then | |
COMPILER="gcc" | |
else | |
COMPILER="unknown" | |
fi | |
fi | |
echo "COMPILER: $COMPILER" | |
if [ "$COMPILER" == "gcc" ]; then | |
COMPILER_MAJOR=$(get "__GNUC__") | |
COMPILER_MINOR=$(get "__GNUC_MINOR__") | |
COMPILER_VER="$COMPILER_MAJOR.$COMPILER_MINOR" | |
elif [ "$COMPILER" == "clang" ]; then | |
COMPILER_MAJOR=$(get "__clang_major__") | |
COMPILER_MINOR=$(get "__clang_minor__") | |
COMPILER_VER="$COMPILER_MAJOR.$COMPILER_MINOR" | |
else | |
COMPILER_VER="" | |
fi | |
echo "COMPILER_VER: $COMPILER_VER" | |
LIBSTDCXX_VER=$(strings $($CXX --print-file-name=libstdc++.so.6) | grep GLIBCXX_3 | sed -e 's/GLIBCXX_//g' | sort -r -t '.' -h -k 3 | head -1) | |
LIBSTDCXX_VER_PATCH=$(echo "$LIBSTDCXX_VER" | awk -F . '{ print $3 }') | |
echo "LIBSDCXX_VER: $LIBSTDCXX_VER" | |
if [ $(($LIBSTDCXX_VER_PATCH + 0)) -ge 21 ]; then | |
LIBCXX="libstdc++11" | |
else | |
LIBCXX="libstdc++" | |
fi | |
mkdir -p $HOME/.conan/profile | |
cat << EOF >$HOME/.conan/profile/default | |
[build_requires] | |
[settings] | |
os=Linux | |
os.glibc=$GLIBC_VER | |
arch=x86_64 | |
compiler=$COMPILER | |
compiler.libstdcxx=$LIBSTDCXX_VER | |
compiler.version=$COMPILER_VER | |
compiler.libcxx=$LIBCXX | |
build_type=Release | |
[env] | |
CC=$CC | |
CXX=$CXX | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment