Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / nlassert / repo / third_party / nlbuild-autotools / repo / autoconf / m4 / nl_enable_coverage.m4
1 #
2 #    Copyright 2020 Project nlbuild-autotools Authors. All Rights Reserved.
3 #    Copyright 2015-2016 Nest Labs Inc. All Rights Reserved.
4 #
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
8 #
9 #    http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16 #
17
18 #
19 #    Description:
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.
23 #
24
25 #
26 # NL_ENABLE_COVERAGE(default)
27 #
28 #   default - Whether the option should be enabled (yes) or disabled (no)
29 #             by default.
30 #
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.
34 #
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,
38 # respectively.
39 #
40 # NOTE: This is only supported at present for GCC or GCC-compatible
41 #       toolchains.
42 #
43 # NOTE: The behavior of this is influenced by nl_cv_build_optimized from
44 #       NL_DISABLE_OPTIMIZATION
45 #
46 #------------------------------------------------------------------------------
47 AC_DEFUN([NL_ENABLE_COVERAGE],
48 [
49     # Check whether or not a default value has been passed in.
50
51     m4_case([$1],
52         [yes],[],
53         [no],[],
54         [m4_fatal([$0: invalid default value '$1'; must be 'yes' or 'no'])])
55
56     AC_CACHE_CHECK([whether to build code-coverage instances of programs and libraries],
57         [nl_cv_build_coverage],
58         [
59             AC_ARG_ENABLE(coverage,
60                 [AS_HELP_STRING([--enable-coverage],[Enable the generation of code-coverage instances @<:@default=$1@:>@.])],
61                 [
62                     case "${enableval}" in
63
64                     no|yes)
65                         nl_cv_build_coverage=${enableval}
66
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.])
69                         fi
70                         ;;
71
72                     *)
73                         AC_MSG_ERROR([Invalid value ${enableval} for --enable-coverage])
74                         ;;
75
76                     esac
77                 ],
78                 [
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
82
83                     else
84                         nl_cv_build_coverage=$1
85
86                     fi
87                 ])
88     ])
89
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])
93         else
94             NL_COVERAGE_CPPFLAGS="--coverage"
95             if ${CC} --version | grep -q clang; then
96                 NL_COVERAGE_LDFLAGS="--coverage"
97             else
98                 NL_COVERAGE_LIBS="-lgcov"
99             fi
100         fi
101     fi
102
103 ])
104
105
106
107
108
109
110
111