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-warnings-as-errors configuration option to the package 21# and controls whether the package will be built to treat all 22# compilation warnings as errors. # 23 24# 25# NL_ENABLE_WERROR(default) 26# 27# default - Whether the option should be enabled (yes) or disabled (no) 28# by default. 29# 30# Adds an --enable-warnings-as-errors configuration option to the 31# package with a default value of 'default' (should be either 'no' or 32# 'yes') and controls whether the package will be built with or 33# without -Werror enabled. 34# 35# The value 'nl_cv_warnings_as_errors' will be set to the result. In 36# addition, the variable NL_WERROR_CPPFLAGS will be set to the 37# compiler-specific flag necessary to assert this option. 38# 39#------------------------------------------------------------------------------ 40AC_DEFUN([NL_ENABLE_WERROR], 41[ 42 # Check whether or not a default value has been passed in. 43 44 m4_case([$1], 45 [yes],[], 46 [no],[], 47 [m4_fatal([$0: invalid default value '$1'; must be 'yes' or 'no'])]) 48 49 AC_CACHE_CHECK([whether to treat all compilation warnings as errors], 50 nl_cv_warnings_as_errors, 51 [ 52 AC_ARG_ENABLE(warnings-as-errors, 53 [AS_HELP_STRING([--enable-warnings-as-errors],[Treat all compilation warnings as errors @<:@default=$1@:>@.])], 54 [ 55 case "${enableval}" in 56 57 no|yes) 58 nl_cv_warnings_as_errors=${enableval} 59 ;; 60 61 *) 62 AC_MSG_ERROR([Invalid value ${enableval} for --enable-warnings-as-errors]) 63 ;; 64 65 esac 66 ], 67 [ 68 nl_cv_warnings_as_errors=$1 69 ]) 70 ]) 71 72 if test "${nl_cv_warnings_as_errors}" = "yes"; then 73 AX_CHECK_COMPILER_OPTION([C], NL_WERROR_CPPFLAGS, [-Werror]) 74 if test "x${NL_WERROR_CPPFLAGS}" = "x"; then 75 AC_MSG_ERROR([Could not determine how to treat warnings as errors for your compiler ${CC}]) 76 fi 77 fi 78]) 79