Created
March 31, 2021 08:44
-
-
Save ziotom78/f01b3976be79d886a3a384d7e0d2e7e5 to your computer and use it in GitHub Desktop.
Bash script to download the fmt library (C++)
This file contains hidden or 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 | |
# Copyright (c) 2020 Maurizio Tomasi | |
# | |
# This Bash script downloads the "fmt" C++ library and installs it in | |
# the current directory. | |
FMT_VERSION="7.1.2" | |
download_file() { | |
filename="$1" | |
dest="$2" | |
if [ -z "$dest" ]; then | |
dest=$filename | |
fi | |
destdir=$(dirname "$dest") | |
if [ -n "$destdir" ]; then | |
mkdir -p "$destdir" | |
fi | |
printf "Downloading file '%s' (version %s)\n" "$filename" "$FMT_VERSION" | |
curl -s "https://raw.githubusercontent.com/fmtlib/fmt/${FMT_VERSION}/$filename" > "$dest" | |
} | |
echo "Going to download fmt library version ${FMT_VERSION} in current directory" | |
echo "Press ENTER to continue, or Ctrl+C to quit…" | |
read -s | |
for filename in fmt/core.h fmt/format.h fmt/format-inl.h; do | |
download_file "include/$filename" "$filename" | |
done | |
download_file src/format.cc format.cc | |
cat > fmtlib.h <<EOF | |
#pragma once | |
#ifndef __has_include | |
// No way to check if <format> exists, so play safe | |
#include "fmt/format.h" | |
#else | |
#if __has_include(<format>) | |
// Hurrah, we're using a C++20 compiler! | |
#include <format> | |
namespace fmt = std::format; | |
#else | |
// No full C++20 support | |
#include "fmt/format.h" | |
#endif | |
#endif | |
EOF | |
cat <<EOF | |
The library has been downloaded. To use it, include in your C++ files the lines | |
#include "fmtlib.h" | |
and be sure to add "format.cc" to your Makefile, e.g.: | |
myprogram: myprogram.cc routines.cc format.cc | |
c++ -o \$@ -g -Wall -std=c++11 \$^ | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment