-
Notifications
You must be signed in to change notification settings - Fork 10
/
configure.sh
executable file
·123 lines (110 loc) · 2.67 KB
/
configure.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
#
# Runs CMake to configure build in Git branch-specific directory,
# allows user to custom configuration.
#
# Copyright (C) 2013 Mateusz Loskot <mateusz@loskot.net>
#
# Uses parts and ideas adapted from Boost's bootstrap.sh script
# Copyright (C) 2005, 2006 Douglas Gregor.
# Copyright (C) 2006 The Trustees of Indiana University
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
################################################################################
err()
{
echo -e "error: $1"
exit 1
}
msg()
{
echo "$1"
}
msg_line()
{
echo -n "$1..."
}
msg_done()
{
if [[ -n "$1" ]]; then
echo "$1"
else
echo "done"
fi
}
# Check source directory
is_src_dir()
{
[[ -f "$1/CMakeLists.txt" ]]
}
# Determine Git branch, if found
function get_git_branch
{
ref=$(cd $SRC_DIR && exec git symbolic-ref HEAD 2> /dev/null) || return
echo "${ref#refs/heads/}"
}
################################################################################
PREFIX=""
SRC_DIR="$PWD"
BUILD_DIR="$PWD/_build"
CMAKE_OPTIONS=""
for option
do
case $option in
-help | --help | -h)
show_help=yes
;;
-prefix=* | --prefix=*)
PREFIX=`expr "x$option" : "x-*prefix=\(.*\)"`
;;
-src-dir=* | --src-dir=*)
SRC_DIR=`expr "x$option" : "x-*src-dir=\(.*\)"`
;;
-build-dir=* | --build-dir=*)
BUILD_DIR=`expr "x$option" : "x-*build-dir=\(.*\)"`
;;
-D*)
CMAKE_OPTION=`expr "x$option" : "x\(-D.*\)"`
CMAKE_OPTIONS="${CMAKE_OPTIONS} ${CMAKE_OPTION}"
;;
-*)
err "unrecognized option: $option"
;;
esac
done
if [ "x$show_help" = "xyes" ]; then
cat <<EOF
\`./configure.sh' runs CMake to configure build
Usage: $0 [OPTION]...
Defaults for the options are specified in brackets.
EOF
fi
[[ -n "$show_help" ]] && exit 0
msg "Preparing build using "
msg_line "Looking for sources in '$SRC_DIR'"
if ! is_src_dir "$SRC_DIR"; then
err "cannot find sources in '$SRC_DIR'"
fi
msg_done
msg_line "Detecting current Git branch"
BRANCH=$(get_git_branch)
if [ -n $BRANCH ]; then
SUFFIX=$(echo $BRANCH | sed -e 's/\//\-/g')
BUILD_DIR="$BUILD_DIR-$SUFFIX"
fi
msg_done $BRANCH
# Create build directory
if [ ! -d "$BUILD_DIR" ]; then
msg_line "Creating build directory in '$BUILD_DIR'"
mkdir -p $BUILD_DIR
msg_done
fi
[[ ! -d "$BUILD_DIR" ]] && err "cannot find '$BUILD_DIR' directory"
# Run cmake
msg "Running CMake in build directoru '$BUILD_DIR'"
msg "CMake options:"
msg " ${CMAKE_OPTIONS}"
(cd $BUILD_DIR; cmake -DCMAKE_INSTALL_PREFIX:PATH="$PREFIX" $CMAKE_OPTIONS "$SRC_DIR")