2 # Copyright 2015-2016 Nest Labs Inc. All Rights Reserved.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
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 # reporting, using the LCOV package.
26 # NL_ENABLE_COVERAGE_REPORTS(default)
28 # default - Whether the option should be automatic (auto), enabled
29 # (yes), or disabled (no) by default.
31 # Adds an --enable-coverage-reports configuration option to the
32 # package with a default value of 'default' (should be 'auto', 'no' or
33 # 'yes') and controls whether the package will be built with or
34 # without code coverage reports, using the LCOV package.
36 # The value 'nl_cv_build_coverage_reports' will be set to the result. In
37 # addition, LCOV will be set to the path of the 'lcov' tool and GENHTML will be set to the path of the 'genhtml' tool.
39 # NOTE: The behavior of this is influenced by nl_cv_build_coverage from
42 #------------------------------------------------------------------------------
43 AC_DEFUN([NL_ENABLE_COVERAGE_REPORTS],
45 # Check whether or not a default value has been passed in.
51 [m4_fatal([$0: invalid default value '$1'; must be 'auto', 'yes' or 'no'])])
53 # Check for the presence of lcov and genhtml, required
54 # to build and generate the coverage reports.
56 AC_PATH_PROG(LCOV, lcov)
57 AC_PATH_PROG(GENHTML, genhtml)
59 AC_CACHE_CHECK([whether to build graphical code coverage reports],
60 nl_cv_build_coverage_reports,
62 AC_ARG_ENABLE(coverage-reports,
63 [AS_HELP_STRING([--enable-coverage-reports],[Enable the generation of code coverage reports (requires lcov) @<:@default=$1@:>@.])],
65 case "${enableval}" in
68 nl_cv_build_coverage_reports=${enableval}
72 AC_MSG_ERROR([Invalid value ${enableval} for --enable-coverage])
78 nl_cv_build_coverage_reports=$1
81 # If coverage is not enabled, then coverage reports
82 # defaults to 'no' if it is 'auto' or fails if it is
83 # 'yes'. Otherwise, availability of lcov and genhtml
84 # condition behavior. Lack of availability for 'yes'
85 # results in failure; however, for 'auto' then coverage
86 # reports default to 'no'.
88 case "${nl_cv_build_coverage}" in
91 case "${nl_cv_build_coverage_reports}" in
94 nl_cv_build_coverage_reports="no"
98 AC_MSG_ERROR([--enable-coverage must be asserted to use --enable-coverage-reports.])
108 case "${nl_cv_build_coverage_reports}" in
111 # Both lcov and genhtml must exist to successfully
112 # enable coverage reports.
114 if test "x${LCOV}" = "x" || test "x${GENHTML}" = "x"; then
115 nl_cv_build_coverage_reports="no"
118 nl_cv_build_coverage_reports="yes"
124 # Both lcov and genhtml must exist to successfully
125 # enable coverage reports. Since the default or user
126 # ask is 'yes', we must fail if lcov or genhtml cannot
129 if test "x${LCOV}" = "x"; then
130 AC_MSG_ERROR([Cannot find 'lcov'. You must have the lcov package installed to use coverage reports.])
132 elif test "x${GENHTML}" = "x"; then
133 AC_MSG_ERROR([Cannot find 'genhtml'. You must have the lcov package installed to use coverage reports.])
135 elif test "${nl_cv_build_coverage_reports}" = "auto"; then
136 nl_cv_build_coverage_reports="yes"