-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathbuild-unix.sh
executable file
·68 lines (54 loc) · 1.73 KB
/
build-unix.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# Builds the library using CMake on UNIX-like platforms
# The script should be run from the project's root directory
#
# This environment variables are the parameters to this script:
# - BUILD_DIR : build directory
# - BIT_VERSION : target platform architecture (32 or 64)
# - COVERAGE : add compiler flags necessary for test coverage (set to ON)
# - INSTALL : install after the build finishes (set to ON)
# - WARN_AS_ERR : treat compiler warnings as errors (set to ON)
# - CXXFLAGS : additional compiler flags
#
# Command line arguments are forwarded to CMake.
#
# exit if a command returns non-zero status
set -e
# add compiler flags necessary for test coverage
if [ "$COVERAGE" = "ON" ]; then
CXXFLAGS="$CXXFLAGS -fprofile-arcs -fprofile-update=atomic -ftest-coverage -fPIC -O0"
fi
# set -m32 or -m64 if a BIT_VERSION is given
if [ -n "$BIT_VERSION" ]; then
CXXFLAGS="$CXXFLAGS -m$BIT_VERSION"
fi
# enable all compiler warnings
CXXFLAGS="$CXXFLAGS -Wall"
if [ "$WARN_AS_ERR" = "ON" ]; then
CXXFLAGS="$CXXFLAGS -Werror"
fi
# remove the given build directory if already exists
if [ -d "$BUILD_DIR" ]; then
echo "Given build directory $BUILD_DIR exists. Removing for a clean build."
rm -rf $BUILD_DIR
fi
# print variables for debugging
echo "BUILD_DIR = $BUILD_DIR"
echo "BIT_VERSION = $BIT_VERSION"
echo "COVERAGE = $COVERAGE"
echo "INSTALL = $INSTALL"
echo "CXXFLAGS = $CXXFLAGS"
echo "CMake arguments = $@"
# export flags variable to be used by CMake
export CXXFLAGS
SOURCE_DIR=$(pwd)
mkdir $BUILD_DIR
cd $BUILD_DIR
echo "Configuring..."
cmake $SOURCE_DIR "$@"
echo "Building..."
VERBOSE=1 cmake --build .
if [ "$INSTALL" = "ON" ]; then
echo "Installing..."
cmake --build . --target install
fi