forked from JeffersonLab/clara-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·201 lines (161 loc) · 4.46 KB
/
configure
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/sh
# wrapper for using CMake options
#
# SPDX-FileCopyrightText: © The Clara Framework Authors
#
# SPDX-License-Identifier: Apache-2.0
set -e
# check cmake
if ! command -v cmake > /dev/null 2>&1; then
cat << EOF >&2
Please install the CMake build tool.
Then you can call this configure script, which wraps and simplify
the equivalent CMake command to generate the build files.
EOF
exit 1;
fi
cmake=$(command -v cmake)
# helper functions
usage() {
cat << EOF
Usage: $0 [OPTION]... [VAR=VALUE]...
Build options:
--build-type=TYPE set CMake build type [RelWithDebInfo]:
- Debug: debugging flags enabled
- MinSizeRel: minimal output size
- Release: optimizations on, debugging off
- RelWithDebInfo: release flags plus debugging
--build-dir=DIR place build files in directory [build]
Installation directory:
--prefix=PREFIX installation directory [/usr/local]
Features (use --enable-FEATURE or --disable-FEATURE):
tests compile tests [enabled]
EOF
}
add_cache_entry() {
if [ -z "${cmake_cache}" ]; then
cmake_cache="-D$1:$2=$3"
else
cmake_cache="${cmake_cache} \\\\\n -D$1:$2=$3"
fi
}
add_env_entry() {
if [ -z "${cmake_env}" ]; then
cmake_env="$1=$2"
else
cmake_env="${cmake_env} \\\\\n$1=$2"
fi
}
ensure_value() {
value="$(echo "$1" | sed 's/[-_a-zA-Z0-9]*=//')"
if [ -z "${value}" ]; then
echo "Error: missing value for '$1'" 1>&2
exit 1
fi
echo "${value}"
}
# set defaults
src_dir="$(cd "$( dirname "$0")" && pwd)"
build_type=RelWithDebInfo
build_dir=build
prefix=/usr/local
cmake_cache=""
cmake_env=""
build_tests="ON"
# parse arguments
while [ $# -ne 0 ]; do
case "$1" in
-*=*) optarg="$(ensure_value "$1")" ;;
--enable-*) optarg="ON" ;;
--disable-*) optarg="OFF" ;;
*) optarg= ;;
esac
case "$1" in
--help|-h)
usage
exit
;;
--build-type=*)
build_type="${optarg}"
;;
--build-dir=*)
build_dir="${optarg}"
;;
--prefix=*)
prefix="${optarg}"
;;
--*able-tests)
build_tests="${optarg}"
;;
*)
echo "Error: unrecognized option '$1'"
echo "Try $0 --help for more information"
exit 1
;;
esac
shift
done
# set cmake configuration
add_cache_entry CMAKE_BUILD_TYPE STRING ${build_type}
add_cache_entry CMAKE_INSTALL_PREFIX PATH "\"${prefix}\""
add_cache_entry CLARA_BUILD_TESTS BOOL ${build_tests}
# generate config.status
mkdir -p "${build_dir}"
cd "${build_dir}"
config_status="config.status"
cat << EOF > "${config_status}"
#!/bin/sh
# Generated by configure.
# Run this file to recreate the current configuration.
set -e
cmake="$cmake"
src_dir="$src_dir"
echo "-- Found \$(\$cmake --version | head -1)"
echo "-- Source directory: \$src_dir"
# Delete cache to use a clean configuration
rm -f CMakeCache.txt
# Run CMake to generate build files
EOF
if [ ! -z "${cmake_env}" ]; then
# shellcheck disable=SC2059
printf "${cmake_env} \\\\\n" >> "${config_status}"
fi
echo "\$cmake \\" >> "${config_status}"
if [ ! -z "${cmake_cache}" ]; then
# shellcheck disable=SC2059
printf " ${cmake_cache} \\\\\n" >> "${config_status}"
fi
echo " \"\$src_dir\"" >> "${config_status}"
# run config
chmod u+x "${config_status}"
./"${config_status}"
# generate top-level Makefile
cat << EOF > "${src_dir}/Makefile"
# Makefile. Generated by configure.
ifeq (\$(findstring w,\$(lastword \$(MAKEFLAGS))),)
MAKEFLAGS += --no-print-directory
endif
BUILDDIR="${build_dir}"
all:
+@\$(MAKE) -C \$(BUILDDIR)
install:
+@\$(MAKE) -C \$(BUILDDIR) install
uninstall:
+@\$(MAKE) -C \$(BUILDDIR) uninstall
check:
+@if \$(MAKE) -sn -C \$(BUILDDIR) test > /dev/null 2>&1; \\
then \$(MAKE) -C \$(BUILDDIR) test CTEST_OUTPUT_ON_FAILURE=1; \\
else echo "No tests found!"; fi
test: check
integration_test:
+@if \$(MAKE) -sn -C \$(BUILDDIR) integration_test > /dev/null 2>&1; \\
then \$(MAKE) -C \$(BUILDDIR) integration_test CTEST_OUTPUT_ON_FAILURE=1; \\
else echo "No integration tests found!"; fi
clean:
+@\$(MAKE) -C \$(BUILDDIR) clean
distclean:
rm -rf \$(BUILDDIR)
rm -f ${config_status}
rm -f Makefile
.PHONY : install check test integration_test clean distclean
EOF