Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / nlunit-test / repo / third_party / nlbuild-autotools / repo / autoconf / m4 / nl_enable_optimization.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-optimization configuration option to the package and
22 #      controls whether the package will be built with or without code
23 #      optimization.
24 #
25
26 #
27 # NL_ENABLE_OPTIMIZATION(default)
28 #
29 #   default - Whether the option should be enabled (yes) or disabled (no)
30 #             by default.
31 #
32 # Adds an --enable-optimization configuration option to the package with a
33 # default value of 'default' (should be either 'no' or 'yes') and controls
34 # whether the package will be built with or without code optimization.
35 #
36 # The value 'nl_cv_build_optimized' will be set to the result. In
37 # addition, the contents of CFLAGS, CXXFLAGS, OBJCFLAGS, and OBJCXXFLAGS may
38 # be altered by the use of this macro, converting -O<something> to -O0.
39 #
40 # NOTE: The behavior of this is influenced by nl_cv_build_coverage from
41 #       NL_ENABLE_COVERAGE
42 #
43 #------------------------------------------------------------------------------
44 AC_DEFUN([NL_ENABLE_OPTIMIZATION],
45 [
46     # Check whether or not a default value has been passed in.
47
48     m4_case([$1],
49         [yes],[],
50         [no],[],
51         [m4_fatal([$0: invalid default value '$1'; must be 'yes' or 'no'])])
52
53     AC_CACHE_CHECK([whether to build code-optimized instances of programs and libraries],
54         [nl_cv_build_optimized],
55         [
56             AC_ARG_ENABLE(optimization,
57                 [AS_HELP_STRING([--enable-optimization],[Enable the generation of code-optimized instances @<:@default=$1@:>@.])],
58                 [
59                     case "${enableval}" in 
60
61                     no|yes)
62                         nl_cv_build_optimized=${enableval}
63
64                         if test "${nl_cv_build_coverage}" = "yes" && test "${nl_cv_build_optimized}" = "yes"; then
65                             AC_MSG_ERROR([both --enable-optimization and --enable-coverage cannot used. Please, choose one or the other to enable.])
66                         fi
67                         ;;
68
69                     *)
70                         AC_MSG_ERROR([Invalid value ${enableval} for --enable-optimized])
71                         ;;
72
73                     esac
74                 ],
75                 [
76                     if test "${nl_cv_build_coverage}" = "yes"; then
77                         AC_MSG_WARN([--enable-coverage was specified, optimization disabled])
78                         nl_cv_build_optimized=no
79             
80                     else
81                         nl_cv_build_optimized=$1
82             
83                     fi
84                 ])
85     ])
86
87     if test "${nl_cv_build_optimized}" = "no"; then
88         CFLAGS="`echo ${CFLAGS} | sed -e 's,-O[[[:alnum:]]]*,-O0,g'`"
89         CXXFLAGS="`echo ${CXXFLAGS} | sed -e 's,-O[[[:alnum:]]]*,-O0,g'`"
90         OBJCFLAGS="`echo ${OBJCFLAGS} | sed -e 's,-O[[[:alnum:]]]*,-O0,g'`"
91         OBJCXXFLAGS="`echo ${OBJCXXFLAGS} | sed -e 's,-O[[[:alnum:]]]*,-O0,g'`"
92     fi
93
94 ])