NMEA: enhancement and fix of RTE
[marnav.git] / bin / test-library.sh
blob3785bf3405ff24c9d5d39e949b88d9ad5e53df9b
1 #!/bin/bash -e
3 # builds the marnav library and tests if it is usable as library in
4 # various ways.
6 export SCRIPT_BASE=$(dirname `readlink -f $0`)
7 export BASE=${SCRIPT_BASE}/..
8 export BUILD=${BASE}/build
10 # TODO: activate this code after upgrading to cmake version > 3.11
11 #if [ `which nproc` ] ; then
12 # export NUM_PROC_ARG="-j ${NUM_PROC:-$(nproc --all --ignore=2)}"
13 #else
14 # num_proc=${NUM_PROC:-$(($(cat /proc/cpuinfo | grep -E "^processor" | wc -l) - 2))}
15 # if [ ${num_proc} -gt 0 ] ; then
16 # export NUM_PROC_ARG="-j ${num_proc}"
17 # else
18 # export NUM_PROC_ARG="-j 1"
19 # fi
20 #fi
21 export NUM_PROC_ARG=""
23 function prepare_dir()
25 dir=$1
26 if [ -d ${dir} ] ; then
27 rm -fr ${dir}
29 mkdir -p ${dir}
32 function build_library()
34 install_prefix=$1
35 tarballs_install=$2
36 builddir=${BUILD}/build-marnav
38 mkdir -p ${install_prefix}
39 mkdir -p ${tarballs_install}
41 prepare_dir ${builddir}
42 pushd ${builddir}
43 cmake \
44 -DCMAKE_INSTALL_PREFIX=${install_prefix} \
45 -DCMAKE_BUILD_TYPE=Release \
46 -DENABLE_EXAMPLES=OFF \
47 -DENABLE_TESTS=OFF \
48 -DENABLE_TOOLS=OFF \
49 ${BASE}
50 cmake --build . ${NUM_PROC_ARG}
51 cmake --build . --target install
52 cpack -G TGZ
53 mv marnav-*.tar.gz ${tarballs_install}
54 popd
57 function test_example_use_installation()
59 install_prefix=$1
60 builddir=${BUILD}/build-example-installed
62 prepare_dir ${builddir}
63 pushd ${builddir}
64 cmake \
65 -DCMAKE_BUILD_TYPE=Release \
66 -DCMAKE_PREFIX_PATH=${install_prefix} \
67 ${BASE}/examples/library
68 cmake --build . ${NUM_PROC_ARG}
69 ./foobar
70 popd
73 function test_example_use_tarball()
75 tarball=$1
76 builddir=${BUILD}/build-example-tarball
77 unpackdir=${builddir}/marnav
79 prepare_dir ${builddir}
80 mkdir -p ${unpackdir}
81 pushd ${builddir}
82 tar --strip-components=1 -xzf ${tarball} -C ${unpackdir}
83 cmake \
84 -DCMAKE_BUILD_TYPE=Release \
85 -DCMAKE_PREFIX_PATH=${unpackdir} \
86 ${BASE}/examples/library
87 cmake --build . ${NUM_PROC_ARG}
88 ./foobar
89 popd
92 function test_example_use_externalproject_import()
94 builddir=${BUILD}/build-example-externalproject
96 prepare_dir ${builddir}
97 pushd ${builddir}
98 cmake \
99 -DCMAKE_BUILD_TYPE=Release \
100 -DMARNAV_SOURCE_DIR=${BASE} \
101 ${BASE}/examples/subproject
102 cmake --build . ${NUM_PROC_ARG}
103 ./src/marnav-demo
104 popd
107 function test_example_use_subdirectory()
109 builddir=${BUILD}/build-example-subdirectory
111 prepare_dir ${builddir}
112 pushd ${builddir}
113 cmake \
114 -DCMAKE_BUILD_TYPE=Release \
115 -DMARNAV_SOURCE_DIR=${BASE} \
116 ${BASE}/examples/subdirectory
117 cmake --build . ${NUM_PROC_ARG}
118 ./foobar
119 popd
122 prepare_dir ${BUILD}
123 build_library ${BUILD}/install ${BUILD}/tarballs
124 test_example_use_installation ${BUILD}/install
125 test_example_use_tarball ${BUILD}/tarballs/marnav-*.tar.gz
126 test_example_use_externalproject_import
127 test_example_use_subdirectory