blob: f4bfb8a1d0300fc3b4974912845f527c98226694 [file] [log] [blame]
Davide Pesavento780e6462021-02-08 20:58:12 -05001#!/usr/bin/env bash
2
3# It's intentional not to use `set -x`, because this script explicitly prints useful information
4# and should not run in trace mode.
5# It's intentional not to use `set -e`, because this script wants to check all headers
6# (similar to running all test cases), instead of failing at the first error.
7
8PROJ=ChronoSync
Davide Pesavento9c4bd6d2022-07-26 15:28:08 -04009PCFILE=ChronoSync
Davide Pesavento780e6462021-02-08 20:58:12 -050010
11if [[ -n $DISABLE_HEADERS_CHECK ]]; then
12 echo 'Skipping headers check.'
13 exit 0
14fi
15
Davide Pesavento9c4bd6d2022-07-26 15:28:08 -040016if has CentOS $NODE_LABELS; then
Davide Pesavento780e6462021-02-08 20:58:12 -050017 export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
18fi
19
20CXX=${CXX:-g++}
Davide Pesavento8663ed12022-07-23 03:04:27 -040021STD=-std=c++17
Davide Pesavento9c4bd6d2022-07-26 15:28:08 -040022CXXFLAGS="-O2 -Wall -Wno-unneeded-internal-declaration -Wno-unused-const-variable $(pkg-config --cflags libndn-cxx $PCFILE)"
23INCLUDEDIR="$(pkg-config --variable=includedir $PCFILE)"/$PROJ
Davide Pesavento780e6462021-02-08 20:58:12 -050024
25echo "Using: $CXX $STD $CXXFLAGS"
26
27NCHECKED=0
28NERRORS=0
29while IFS= read -r -d '' H; do
30 echo "Checking header ${H#${INCLUDEDIR}/}"
31 "$CXX" -xc++ $STD $CXXFLAGS -c -o /dev/null "$H"
32 [[ $? -eq 0 ]] || ((NERRORS++))
33 ((NCHECKED++))
34done < <(find "$INCLUDEDIR" -name '*.hpp' -type f -print0 2>/dev/null)
35
36if [[ $NCHECKED -eq 0 ]]; then
37 echo "No headers found. Is $PROJ installed?"
38 exit 1
39else
40 echo "$NCHECKED headers checked."
41fi
42
43if [[ $NERRORS -gt 0 ]]; then
44 echo "$NERRORS headers could not be compiled."
45 exit 1
46fi