-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathtest-library.sh
executable file
·126 lines (109 loc) · 2.6 KB
/
test-library.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
123
124
125
#!/bin/bash -e
# builds the marnav library and tests if it is usable as library in
# various ways.
export SCRIPT_BASE=$(dirname `readlink -f $0`)
export BASE=${SCRIPT_BASE}/..
export BUILD=${BASE}/build
if [ `which nproc` ] ; then
export NUM_PROC_ARG="-j ${NUM_PROC:-$(nproc --all --ignore=2)}"
else
num_proc=${NUM_PROC:-$(($(cat /proc/cpuinfo | grep -E "^processor" | wc -l) - 2))}
if [ ${num_proc} -gt 0 ] ; then
export NUM_PROC_ARG="-j ${num_proc}"
else
export NUM_PROC_ARG="-j 1"
fi
fi
function prepare_dir()
{
dir=$1
if [ -d ${dir} ] ; then
rm -fr ${dir}
fi
mkdir -p ${dir}
}
function build_library()
{
install_prefix=$1
tarballs_install=$2
builddir=${BUILD}/build-marnav
mkdir -p ${install_prefix}
mkdir -p ${tarballs_install}
prepare_dir ${builddir}
pushd ${builddir}
cmake \
-DCMAKE_INSTALL_PREFIX=${install_prefix} \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_EXAMPLES=OFF \
-DENABLE_TESTS=OFF \
-DENABLE_TOOLS=OFF \
${BASE}
cmake --build . ${NUM_PROC_ARG}
cmake --build . --target install
cpack -G TGZ
mv marnav-*.tar.gz ${tarballs_install}
popd
}
function test_example_use_installation()
{
install_prefix=$1
builddir=${BUILD}/build-example-installed
prepare_dir ${builddir}
pushd ${builddir}
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=${install_prefix} \
${BASE}/examples/library
cmake --build . ${NUM_PROC_ARG}
./foobar
popd
}
function test_example_use_tarball()
{
tarball=$1
builddir=${BUILD}/build-example-tarball
unpackdir=${builddir}/marnav
prepare_dir ${builddir}
mkdir -p ${unpackdir}
pushd ${builddir}
tar --strip-components=1 -xzf ${tarball} -C ${unpackdir}
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=${unpackdir} \
${BASE}/examples/library
cmake --build . ${NUM_PROC_ARG}
./foobar
popd
}
function test_example_use_externalproject_import()
{
builddir=${BUILD}/build-example-externalproject
prepare_dir ${builddir}
pushd ${builddir}
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DMARNAV_SOURCE_DIR=${BASE} \
${BASE}/examples/subproject
cmake --build . ${NUM_PROC_ARG}
./src/marnav-demo
popd
}
function test_example_use_subdirectory()
{
builddir=${BUILD}/build-example-subdirectory
prepare_dir ${builddir}
pushd ${builddir}
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DMARNAV_SOURCE_DIR=${BASE} \
${BASE}/examples/subdirectory
cmake --build . ${NUM_PROC_ARG}
./foobar
popd
}
prepare_dir ${BUILD}
build_library ${BUILD}/install ${BUILD}/tarballs
test_example_use_installation ${BUILD}/install
test_example_use_tarball ${BUILD}/tarballs/marnav-*.tar.gz
test_example_use_externalproject_import
test_example_use_subdirectory