2 # Copyright 2020 Project nlbuild-autotools Authors. All Rights Reserved.
3 # Copyright 2015-2016 Nest Labs Inc. All Rights Reserved.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
20 # This file defines a GNU autoconf M4-style macro that adds an
21 # --enable-coverage configuration option to the package and
22 # controls whether the package will be built for code coverage.
26 # NL_ENABLE_COVERAGE(default)
28 # default - Whether the option should be enabled (yes) or disabled (no)
31 # Adds an --enable-coverage configuration option to the package with a
32 # default value of 'default' (should be either 'no' or 'yes') and controls
33 # whether the package will be built with or without code coverage.
35 # The value 'nl_cv_build_coverage' will be set to the result. In
36 # addition, NL_COVERAGE_CPPFLAGS and NL_COVERAGE_LIBS will be set
37 # to the appropriate values to pass to the compiler and linker,
40 # NOTE: This is only supported at present for GCC or GCC-compatible
43 # NOTE: The behavior of this is influenced by nl_cv_build_optimized from
44 # NL_DISABLE_OPTIMIZATION
46 #------------------------------------------------------------------------------
47 AC_DEFUN([NL_ENABLE_COVERAGE],
49 # Check whether or not a default value has been passed in.
54 [m4_fatal([$0: invalid default value '$1'; must be 'yes' or 'no'])])
56 AC_CACHE_CHECK([whether to build code-coverage instances of programs and libraries],
57 [nl_cv_build_coverage],
59 AC_ARG_ENABLE(coverage,
60 [AS_HELP_STRING([--enable-coverage],[Enable the generation of code-coverage instances @<:@default=$1@:>@.])],
62 case "${enableval}" in
65 nl_cv_build_coverage=${enableval}
67 if test "${nl_cv_build_optimized}" = "yes"; then
68 AC_MSG_ERROR([both --enable-optimization and --enable-coverage cannot used. Please, choose one or the other to enable.])
73 AC_MSG_ERROR([Invalid value ${enableval} for --enable-coverage])
79 if test "${nl_cv_build_optimized}" = "yes"; then
80 AC_MSG_WARN([--enable-optimization was specified, coverage disabled])
81 nl_cv_build_coverage=no
84 nl_cv_build_coverage=$1
90 if test "${nl_cv_build_coverage}" = "yes"; then
91 if test "${GCC}" != "yes"; then
92 AC_MSG_ERROR([GCC or a GCC-compatible toolchain is required for --enable-coverage])
94 NL_COVERAGE_CPPFLAGS="--coverage"
95 if ${CC} --version | grep -q clang; then
96 NL_COVERAGE_LDFLAGS="--coverage"
98 NL_COVERAGE_LIBS="-lgcov"