strukturag / libheif

libheif is an HEIF and AVIF file format decoder and encoder.
Other
1.76k stars 302 forks source link

Cmake doesn't fail on unsupported version of AOM (e.g. 1.0.0.errata1-3build1 from Ubuntu Focal) #989

Closed fancycode closed 1 year ago

fancycode commented 1 year ago

Found this while building on Focal for our PPA (where we only have aom 2.0.0):

/build/libheif-1.17.0/libheif/plugins/encoder_aom.cc: In function 'heif_error aom_encode_image(void*, const heif_image*, heif_image_input_class)':
/build/libheif-1.17.0/libheif/plugins/encoder_aom.cc:873:27: error: 'AOM_USAGE_GOOD_QUALITY' was not declared in this scope
  873 |   unsigned int aomUsage = AOM_USAGE_GOOD_QUALITY;
      |                           ^~~~~~~~~~~~~~~~~~~~~~
/build/libheif-1.17.0/libheif/plugins/encoder_aom.cc:876:16: error: 'AOM_USAGE_REALTIME' was not declared in this scope
  876 |     aomUsage = AOM_USAGE_REALTIME;
      |                ^~~~~~~~~~~~~~~~~~
make[3]: Leaving directory '/build/libheif-1.17.0/obj-x86_64-linux-gnu'
make[3]: *** [libheif/plugins/CMakeFiles/heif-aomenc.dir/build.make:66: libheif/plugins/CMakeFiles/heif-aomenc.dir/encoder_aom.cc.o] Error 1

As there are already checks for other symbols, e.g. https://github.com/strukturag/libheif/blob/588b096027d620a9b9a617d1111e5a25d02d48e5/libheif/plugins/encoder_aom.cc#L868 these symbols should also be checked, or the CMakeLists.txt should enforce the minimum required version of AOM.

For now I'll upgrade to 3.3.0 (as with Jammy) in the PPA to be able to continue but this probably should be resolved anyway.

farindk commented 1 year ago

Strange that this happened despite https://github.com/strukturag/libheif/pull/812.

fancycode commented 1 year ago

This is the output in CMakeFiles/CMakeError.log:

Determining if the AOM_USAGE_GOOD_QUALITY exist failed with the following output:
Change Dir: /build/libheif-1.17.0/obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_1bd18/fast && make[2]: Entering directory '/build/libheif-1.17.0/obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTC_1bd18.dir/build.make CMakeFiles/cmTC_1bd18.dir/build
make[3]: Entering directory '/build/libheif-1.17.0/obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_1bd18.dir/CheckSymbolExists.c.o
/usr/bin/cc   -g -O2 -fdebug-prefix-map=/build/libheif-1.17.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -fPIE   -o CMakeFiles/cmTC_1bd18.dir/CheckSymbolExists.c.o   -c /build/libheif-1.17.0/obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp/CheckSymbolExists.c
/build/libheif-1.17.0/obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp/CheckSymbolExists.c: In function 'main':
/build/libheif-1.17.0/obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp/CheckSymbolExists.c:8:19: error: 'AOM_USAGE_GOOD_QUALITY' undeclared (first use in this function)
    8 |   return ((int*)(&AOM_USAGE_GOOD_QUALITY))[argc];
      |                   ^~~~~~~~~~~~~~~~~~~~~~
/build/libheif-1.17.0/obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp/CheckSymbolExists.c:8:19: note: each undeclared identifier is reported only once for each function it appears in
make[3]: *** [CMakeFiles/cmTC_1bd18.dir/build.make:66: CMakeFiles/cmTC_1bd18.dir/CheckSymbolExists.c.o] Error 1
make[3]: Leaving directory '/build/libheif-1.17.0/obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp'
make[2]: *** [Makefile:121: cmTC_1bd18/fast] Error 2
make[2]: Leaving directory '/build/libheif-1.17.0/obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp'

File /build/libheif-1.17.0/obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include </usr/include/aom/aom_encoder.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef AOM_USAGE_GOOD_QUALITY
  return ((int*)(&AOM_USAGE_GOOD_QUALITY))[argc];
#else
  (void)argc;
  return 0;
#endif
}

So the detection worked, but it didn't fail the cmake invocation.

cmake output:

-- Looking for AOM_USAGE_GOOD_QUALITY
-- Looking for AOM_USAGE_GOOD_QUALITY - not found
-- Found AOM 
-- Found AOM: /usr/include  
farindk commented 1 year ago

BTW: According to this https://github.com/strukturag/libheif/pull/694 I thought that AOM_USAGE_GOOD_QUALITY was only missing in v1.x versions of AOM.

fancycode commented 1 year ago

Sorry, just noticed that my testing build environment didn't use the libheif PPA as dependency, so it was still stuck at aom 1.0.0.errata1-3build1 from upstream Ubuntu Focal :see_no_evil:

Anyway, the problem with cmake not failing on the unsupported version of aom still applies.

farindk commented 1 year ago

While you still have the old AOM installed, could you please check whether the above change fixes the detection? It should only disable the AOM encoder, as the AOM decoder can still be built without that flag.

kleisauke commented 1 year ago

The changes in libheif/plugins/CMakeLists.txt made in commit https://github.com/strukturag/libheif/commit/e7d8563db4bce31b21abd24aa1b106ad114d2274 should probably be reverted. https://github.com/strukturag/libheif/actions/runs/6531869362/job/17733924429 https://github.com/libvips/libvips/actions/runs/6533627028/job/17739177761#step:4:2481

farindk commented 1 year ago

@kleisauke It should work again with the above change.