• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2#    Copyright 2015-2016 Nest Labs Inc. All Rights Reserved.
3#
4#    Licensed under the Apache License, Version 2.0 (the "License");
5#    you may not use this file except in compliance with the License.
6#    You may obtain a copy of the License at
7#
8#    http://www.apache.org/licenses/LICENSE-2.0
9#
10#    Unless required by applicable law or agreed to in writing, software
11#    distributed under the License is distributed on an "AS IS" BASIS,
12#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13#    See the License for the specific language governing permissions and
14#    limitations under the License.
15#
16
17#
18#    Description:
19#      This file defines a GNU autoconf M4-style macro that adds an
20#      --enable-coverage configuration option to the package and
21#      controls whether the package will be built for code coverage.
22#
23
24#
25# NL_ENABLE_COVERAGE(default)
26#
27#   default - Whether the option should be enabled (yes) or disabled (no)
28#             by default.
29#
30# Adds an --enable-coverage configuration option to the package with a
31# default value of 'default' (should be either 'no' or 'yes') and controls
32# whether the package will be built with or without code coverage.
33#
34# The value 'nl_cv_build_coverage' will be set to the result. In
35# addition, NL_COVERAGE_CPPFLAGS and NL_COVERAGE_LIBS will be set
36# to the appropriate values to pass to the compiler and linker,
37# respectively.
38#
39# NOTE: This is only supported at present for GCC or GCC-compatible
40#       toolchains.
41#
42# NOTE: The behavior of this is influenced by nl_cv_build_optimized from
43#       NL_DISABLE_OPTIMIZATION
44#
45#------------------------------------------------------------------------------
46AC_DEFUN([NL_ENABLE_COVERAGE],
47[
48    # Check whether or not a default value has been passed in.
49
50    m4_case([$1],
51        [yes],[],
52        [no],[],
53        [m4_fatal([$0: invalid default value '$1'; must be 'yes' or 'no'])])
54
55    AC_CACHE_CHECK([whether to build code-coverage instances of programs and libraries],
56        nl_cv_build_coverage,
57        [
58            AC_ARG_ENABLE(coverage,
59                [AS_HELP_STRING([--enable-coverage],[Enable the generation of code-coverage instances @<:@default=$1@:>@.])],
60                [
61                    case "${enableval}" in
62
63                    no|yes)
64                        nl_cv_build_coverage=${enableval}
65
66                        if test "${nl_cv_build_optimized}" = "yes"; then
67                            AC_MSG_ERROR([both --enable-optimization and --enable-coverage cannot used. Please, choose one or the other to enable.])
68                        fi
69                        ;;
70
71                    *)
72                        AC_MSG_ERROR([Invalid value ${enableval} for --enable-coverage])
73                        ;;
74
75                    esac
76                ],
77                [
78                    if test "${nl_cv_build_optimized}" = "yes"; then
79                        AC_MSG_WARN([--enable-optimization was specified, coverage disabled])
80                        nl_cv_build_coverage=no
81
82                    else
83                        nl_cv_build_coverage=$1
84
85                    fi
86                ])
87
88            if test "${nl_cv_build_coverage}" = "yes"; then
89                if test "${GCC}" != "yes"; then
90                    AC_MSG_ERROR([GCC or a GCC-compatible toolchain is required for --enable-coverage])
91                else
92                    NL_COVERAGE_CPPFLAGS="--coverage"
93                    if ${CC} --version | grep -q clang; then
94                        NL_COVERAGE_LDFLAGS="--coverage"
95                    else
96                        NL_COVERAGE_LIBS="-lgcov"
97                    fi
98                fi
99            fi
100    ])
101])
102
103
104
105
106
107
108
109
110