[libcamera-devel] meson.build: Silence the C99 designators warning

Message ID 20200212235451.6206-1-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel] meson.build: Silence the C99 designators warning
Related show

Commit Message

Laurent Pinchart Feb. 12, 2020, 11:54 p.m. UTC
We use array designators for array initialization, which is a C99
extension. clang-10 warns about it, causing a build failure.

As this is a useful extension, silence the warning. This needs to be
done only if the compiler supports the -Wno-c99-designator argument,
otherwise a -Wunknown-warning-option will be generated.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 meson.build | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Kieran Bingham Feb. 13, 2020, 10:35 a.m. UTC | #1
Hi Laurent,

On 12/02/2020 23:54, Laurent Pinchart wrote:
> We use array designators for array initialization, which is a C99
> extension. clang-10 warns about it, causing a build failure.
> 
> As this is a useful extension, silence the warning. This needs to be
> done only if the compiler supports the -Wno-c99-designator argument,
> otherwise a -Wunknown-warning-option will be generated.
> 

As we actively use the feature, why not then set the standard
appropriately instead...

index 0bbd24b2a295..7d572fa9a47a 100644
--- a/meson.build
+++ b/meson.build
@@ -5,6 +5,7 @@ project('libcamera', 'c', 'cpp',
         'werror=true',
         'warning_level=2',
         'cpp_std=c++14',
+        'c_std=c99',          # or =c11, or higher if desired [0]
     ],
     license : 'LGPL 2.1+')

Or will that not apply because we're using C++ compilers... but then if
that's the case, why is our c++ compiler complaining about C features...

[0] https://mesonbuild.com/Builtin-options.html#compiler-options

--
Kieran



> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  meson.build | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/meson.build b/meson.build
> index 0bbd24b2a295..aceba997aebd 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -60,6 +60,12 @@ if cc.get_id() == 'clang'
>      endif
>  endif
>  
> +if cc.has_argument('-Wno-c99-designator')
> +    common_arguments += [
> +        '-Wno-c99-designator',
> +    ]
> +endif
> +
>  c_arguments += common_arguments
>  cpp_arguments += common_arguments
>  
>
Laurent Pinchart Feb. 13, 2020, 10:52 a.m. UTC | #2
Hi Kieran,

On Thu, Feb 13, 2020 at 10:35:37AM +0000, Kieran Bingham wrote:
> On 12/02/2020 23:54, Laurent Pinchart wrote:
> > We use array designators for array initialization, which is a C99
> > extension. clang-10 warns about it, causing a build failure.
> > 
> > As this is a useful extension, silence the warning. This needs to be
> > done only if the compiler supports the -Wno-c99-designator argument,
> > otherwise a -Wunknown-warning-option will be generated.
> > 
> 
> As we actively use the feature, why not then set the standard
> appropriately instead...
> 
> index 0bbd24b2a295..7d572fa9a47a 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -5,6 +5,7 @@ project('libcamera', 'c', 'cpp',
>          'werror=true',
>          'warning_level=2',
>          'cpp_std=c++14',
> +        'c_std=c99',          # or =c11, or higher if desired [0]
>      ],
>      license : 'LGPL 2.1+')
> 
> Or will that not apply because we're using C++ compilers... but then if
> that's the case, why is our c++ compiler complaining about C features...

The option is indeed for C sources only. I'm not sure what the rationale
is for clang++ to complain about this, but it does.

For what it's worth, ChromeOS also sets -Wno-c99-designator.

> [0] https://mesonbuild.com/Builtin-options.html#compiler-options
> 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  meson.build | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/meson.build b/meson.build
> > index 0bbd24b2a295..aceba997aebd 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -60,6 +60,12 @@ if cc.get_id() == 'clang'
> >      endif
> >  endif
> >  

I'll add a comment here:

# We use C99 designated initializers for arrays as C++ has no equivalent
# feature. Both gcc and clang support this extension, but recent
# versions of clang generate a warning that needs to be disabled.

> > +if cc.has_argument('-Wno-c99-designator')
> > +    common_arguments += [
> > +        '-Wno-c99-designator',
> > +    ]
> > +endif
> > +
> >  c_arguments += common_arguments
> >  cpp_arguments += common_arguments
> >
Kieran Bingham Feb. 13, 2020, 11:46 a.m. UTC | #3
Hi Laurent,

On 13/02/2020 10:52, Laurent Pinchart wrote:
> Hi Kieran,
> 
> On Thu, Feb 13, 2020 at 10:35:37AM +0000, Kieran Bingham wrote:
>> On 12/02/2020 23:54, Laurent Pinchart wrote:
>>> We use array designators for array initialization, which is a C99
>>> extension. clang-10 warns about it, causing a build failure.
>>>
>>> As this is a useful extension, silence the warning. This needs to be
>>> done only if the compiler supports the -Wno-c99-designator argument,
>>> otherwise a -Wunknown-warning-option will be generated.
>>>
>>
>> As we actively use the feature, why not then set the standard
>> appropriately instead...
>>
>> index 0bbd24b2a295..7d572fa9a47a 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -5,6 +5,7 @@ project('libcamera', 'c', 'cpp',
>>          'werror=true',
>>          'warning_level=2',
>>          'cpp_std=c++14',
>> +        'c_std=c99',          # or =c11, or higher if desired [0]
>>      ],
>>      license : 'LGPL 2.1+')
>>
>> Or will that not apply because we're using C++ compilers... but then if
>> that's the case, why is our c++ compiler complaining about C features...
> 
> The option is indeed for C sources only. I'm not sure what the rationale
> is for clang++ to complain about this, but it does.
> 
> For what it's worth, ChromeOS also sets -Wno-c99-designator.
> 
>> [0] https://mesonbuild.com/Builtin-options.html#compiler-options
>>
>>> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>> ---
>>>  meson.build | 6 ++++++
>>>  1 file changed, 6 insertions(+)
>>>
>>> diff --git a/meson.build b/meson.build
>>> index 0bbd24b2a295..aceba997aebd 100644
>>> --- a/meson.build
>>> +++ b/meson.build
>>> @@ -60,6 +60,12 @@ if cc.get_id() == 'clang'
>>>      endif
>>>  endif
>>>  
> 
> I'll add a comment here:
> 
> # We use C99 designated initializers for arrays as C++ has no equivalent
> # feature. Both gcc and clang support this extension, but recent
> # versions of clang generate a warning that needs to be disabled.


Great, I think the comment helps a lot there.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>


>>> +if cc.has_argument('-Wno-c99-designator')
>>> +    common_arguments += [
>>> +        '-Wno-c99-designator',
>>> +    ]
>>> +endif
>>> +
>>>  c_arguments += common_arguments
>>>  cpp_arguments += common_arguments
>>>  
>
Niklas Söderlund Feb. 13, 2020, 12:05 p.m. UTC | #4
Hi Laurent,

Thanks for your patch.

On 2020-02-13 01:54:51 +0200, Laurent Pinchart wrote:
> We use array designators for array initialization, which is a C99
> extension. clang-10 warns about it, causing a build failure.
> 
> As this is a useful extension, silence the warning. This needs to be
> done only if the compiler supports the -Wno-c99-designator argument,
> otherwise a -Wunknown-warning-option will be generated.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  meson.build | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/meson.build b/meson.build
> index 0bbd24b2a295..aceba997aebd 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -60,6 +60,12 @@ if cc.get_id() == 'clang'
>      endif
>  endif
>  
> +if cc.has_argument('-Wno-c99-designator')
> +    common_arguments += [
> +        '-Wno-c99-designator',
> +    ]
> +endif
> +
>  c_arguments += common_arguments
>  cpp_arguments += common_arguments
>  
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/meson.build b/meson.build
index 0bbd24b2a295..aceba997aebd 100644
--- a/meson.build
+++ b/meson.build
@@ -60,6 +60,12 @@  if cc.get_id() == 'clang'
     endif
 endif
 
+if cc.has_argument('-Wno-c99-designator')
+    common_arguments += [
+        '-Wno-c99-designator',
+    ]
+endif
+
 c_arguments += common_arguments
 cpp_arguments += common_arguments