Bug 259930 - graphics/opencv: cmake fails, if graphics/tesseract installed
Summary: graphics/opencv: cmake fails, if graphics/tesseract installed
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Tobias C. Berner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-19 07:08 UTC by Rainer Hurling
Modified: 2022-04-09 18:39 UTC (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rainer Hurling freebsd_committer freebsd_triage 2021-11-19 07:08:08 UTC
I have encountered a problem on my system that seems to be related to graphics/opencv and graphics/tesseract.

If the system already has graphics/tesseract installed, configure does not work for graphics/opencv: 


-----------------------------------------
CMake Error at /usr/local/cmake/TesseractConfig.cmake:24 (find_package):
  By not providing "FindLeptonica.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "Leptonica", but CMake did not find one.

  Could not find a package configuration file provided by "Leptonica" with
  any of the following names:

    LeptonicaConfig.cmake
    leptonica-config.cmake

  Add the installation prefix of "Leptonica" to CMAKE_PREFIX_PATH or set
  "Leptonica_DIR" to a directory containing one of the above files.  If
  "Leptonica" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  contrib/modules/text/cmake/init.cmake:8 (find_package)
  cmake/OpenCVModule.cmake:298 (include)
  cmake/OpenCVModule.cmake:364 (_add_modules_1)
  modules/CMakeLists.txt:7 (ocv_glob_modules)

-- Configuring incomplete, errors occurred!
See also "/usr/ports/graphics/opencv/work/.build/CMakeFiles/CMakeOutput.log".
See also "/usr/ports/graphics/opencv/work/.build/CMakeFiles/CMakeError.log".
*** Error code 1
-----------------------------------------



The mentioned log file CMakeError.log contains:
-----------------------------------------
Determining if the include file sys/videoio.h exists failed with the following output:
Change Dir: /usr/ports/graphics/opencv/work/.build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/local/bin/ninja cmTC_73ae6 && [1/2] Building C object CMakeFiles/cmTC_73ae6.dir/CheckIncludeFile.c.o
FAILED: CMakeFiles/cmTC_73ae6.dir/CheckIncludeFile.c.o 
/usr/bin/cc   -O2 -pipe  -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Wno-long-long -pthread -Qunused-arguments -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden  -O2 -pipe  -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing  -DNDEBUG -fPIE -MD -MT CMakeFiles/cmTC_73ae6.dir/CheckIncludeFile.c.o -MF CMakeFiles/cmTC_73ae6.dir/CheckIncludeFile.c.o.d -o CMakeFiles/cmTC_73ae6.dir/CheckIncludeFile.c.o -c /usr/ports/graphics/opencv/work/.build/CMakeFiles/CMakeTmp/CheckIncludeFile.c
/usr/ports/graphics/opencv/work/.build/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:10: fatal error: 'sys/videoio.h' file not found
#include <sys/videoio.h>
         ^~~~~~~~~~~~~~~
1 error generated.

ninja: build stopped: subcommand failed.
-----------------------------------------



OpenCV seems to use an internal tesseract if no external one is found on the system. Once tesseract is present, the file FindLeptonica.cmake is also needed, but it is not installed by graphics/leptonica, graphics/tesseract or graphics/opencv.

This all seems to have become a problem only since graphics/tesseract switched from autoconf to cmake [1]

[1] https://cgit.freebsd.org/ports/commit/?id=3f1cf94980fdec66bdb115c46c94635ec3b54572


You can easily reproduce the erroneous behavior in Poudriere by temporarily defining the following dependency in the graphics/opencv Makefile and then building it:

LIB_DEPENDS+=libtesseract.so:graphics/tesseract
Comment 1 Oleg Sidorkin 2021-11-22 22:08:25 UTC
Our graphics/leptonica port is quite outdated. I think it is the real cause of the problem
Comment 2 Tobias C. Berner freebsd_committer freebsd_triage 2021-11-23 07:17:16 UTC
Moin moin

Could you give me the `make showconfig` output from graphics/opencv?


mfg Tobias
Comment 3 Rainer Hurling freebsd_committer freebsd_triage 2021-11-23 07:29:02 UTC
(In reply to Tobias C. Berner from comment #2)

Hi Tobias,

Sure, on my system this is

#make showconfig
===> The following configuration options are available for opencv-4.5.3_5:
     EIGEN=on: Add Eigen v3 Support, builds sfm modules
     GDAL=on: Add Geospatial Data Abstraction Library Support
     GDCM=on: Add Open source DICOM library Support
     HARDENING=off: Enables Build Hardening
     JAVA=off: Enable Java Support
     LTO=off: Enables Link Time Optimizations
     OPENCL=on: Add OpenCL Support
     PATENTED=off: Enable patented 2d feature detection USE AT OWN RISK
     PROTOBUF=on: Enable protobuf support, builds dnn modules
     PYTHON=on: Enable Python Support 3.6 or greater
     TBB=off: Add Intel Threading Building Blocks Support
     VTK=off: Include VTK library support (build opencv_viz module)
====> Options available for the group IMAGE
     GPHOTO2=on: Add Gphoto2 Support
     JPEG=on: Add LibJpeg Support
     OPENEXR=on: Add OpenEXR Support
     PNG=on: Add LibPNG Support
     TIFF=on: Add LibTIFF Support
====> Video support
     DC1394=on: IEEE 1394 camera support
     FFMPEG=off: Link with ffmpeg
     GSTREAMER=on: Add GSTREAMER Support
     V4L=on: Enable support for Video for Linux
     VULKAN=on: Add Vulkan Support
     WEBP=on: Add Webp Support
     XINE=off: Add Xine Support
====> Options available for the single BLAS: you have to select exactly one of them
     ATLAS=off: ATLAS blas implementation with lapacke
     OPENBLAS=on: OpenBLAS blas implementation with lapacke
     NOBLAS=off: Disable support for lapack/blas
====> Options available for the radio JPEG2K: you can only select none or one of them
     JASPER=off: Add Jasper Support for JPEG2000
     OPENJPEG=on: Add OpenJPEG Support for JPEG2000, OpenCV preferred
===> Use 'make config' to modify these settings
Comment 4 commit-hook freebsd_committer freebsd_triage 2021-11-23 10:17:08 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=7d1ed4c1a3936a37890aad7b07094eb1904be02a

commit 7d1ed4c1a3936a37890aad7b07094eb1904be02a
Author:     Tobias C. Berner <tcberner@FreeBSD.org>
AuthorDate: 2021-11-23 08:19:43 +0000
Commit:     Tobias C. Berner <tcberner@FreeBSD.org>
CommitDate: 2021-11-23 10:15:48 +0000

    graphics/opencv: explicitely disable support for graphics/tesseract

    Since the update of graphics/tesseract to 4.1.3 in 3f1cf94980fdec66bdb115c46c94635ec3b54572
    the configure script of opencv now can find tesseract support,
    however in a broken state.

    For now, disable tesseract in graphics/opencv explicitely, so that
    people building in an unclean environment with tesseract possibly
    installed can still build opencv.

    In the future, this will be replaced by an option toggle and fixed
    properly.

    PR:             259930
    Reported by:    rhurlin

 graphics/opencv/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Comment 5 Rainer Hurling freebsd_committer freebsd_triage 2022-01-07 17:40:14 UTC
Now that Tesseract v5.0.1 is committed in #bef8c787cf76, the OpenCV port is able to find and use it again:

-- Checking for module 'tesseract'
--   Found tesseract, version 5.0.1
-- Tesseract:   YES (ver 5.0.1)


Seems, it can be reenabled :)
Comment 6 commit-hook freebsd_committer freebsd_triage 2022-04-09 18:04:46 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=9205101df1ed3f52d833805bd2ba49b986462261

commit 9205101df1ed3f52d833805bd2ba49b986462261
Author:     Adriaan de Groot <adridg@FreeBSD.org>
AuthorDate: 2022-04-09 18:00:19 +0000
Commit:     Adriaan de Groot <adridg@FreeBSD.org>
CommitDate: 2022-04-09 18:03:54 +0000

    graphics/opencv: add TESSERACT option

    Tesseract support was explicitly turned off previously,
    because in a dirty build environment it would pick up
    an existing installation and then break. In the meantime,
    opencv and leptonica have been updated, and Tesseract
    behaves well in combination with opencv.

    Make it an option, default off (corresponding to previous
    behavior). While here, hand off to desktop@ at tcberner's request.

    PR:             259930

 graphics/opencv/Makefile | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)