DanBloomberg / leptonica

Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
Other
1.81k stars 393 forks source link

Leptonica_FOUND not being set in exported cmake config #755

Closed dr-matt closed 1 month ago

dr-matt commented 1 month ago

I'm trying to build tesseract, which depends on leptonica. I built leptonica successfully via cmake, but when I try to build tesseract, cmake emits the following complaint and can't proceed:

CMake Error at CMakeLists.txt:8 (find_package):
  Found package configuration file:

    /tmp/leptonica/lib/cmake/leptonica/LeptonicaConfig.cmake

  but it set Leptonica_FOUND to FALSE so package "Leptonica" is considered to
  be NOT FOUND.

Note that this is not tesseract-specific. If I create a minimal cmake project with the line:

find_package(Leptonica REQUIRED)

it fails in the same way.

From what I can tell, this is because Leptonica_FOUND is not explicitly set to TRUE or FALSE in leptonica's generated cmake configs. A workaround/fix is to simply add the following line at the end of cmake/templates/LeptonicaConfig.cmake.in:

set(Leptonica_FOUND TRUE)

After doing so, tesseract is able to successfully find leptonica and all is well.

zdenop commented 1 month ago

Please provide information about OS and exact commands you use to build and install leptonica and tesseract.

We run GA for cmake builds and they are working for windows, linux(ubuntu) and mac:

(MacOS macos-12-clang-14-cmake build fails for some reason at baseapi test, but rest macos build are ok)

dr-matt commented 1 month ago

Thank you for that. I'm on ubuntu 24.04, cmake version 3.28.3.

Command to build leptonica:

cmake <srcdir> -DCMAKE_INSTALL_PREFIX=/tmp/leptonica
make install

Command to build tesseract:

cmake <srcdir> -DLeptonica_DIR=/tmp/leptonica/lib/cmake/leptonica -DGRAPHICS_DISABLED=on -DBUILD_TRAINING_TOOLS=off

In trying to reproduce this cleanly, I discovered some strange behavior. In certain situations the error does not show up. However, if cmake is run multiple times with different arguments, without first clearing the cache, then we can see the error.

For instance, if just before running the above cmake command for tesseract, we just do cmake <srcdir>, then the second cmake command fails.

This came up when we configured the tesseract build using cmake-gui, which by default first runs cmake without any arguments. After we filled in Leptonica_DIR and re-ran, we saw the error mentioned above, and it persisted until we deleted the entire cache, build tree, and install tree.

Doing fully clean builds, we can't reproduce this issue. So perhaps it's just related to some sticky state related to tesseract and/or cmake.

zdenop commented 1 month ago

AFAIR Leptonica_DIR is the tesseract relic from a time when leptonica did not create files needed for find_package.

Can you please try to use the standard cmake setting -DCMAKE_PREFIX_PATH=/tmp?

dr-matt commented 1 month ago

It may be moot, as the error isn't reproducible if everything is done from a clean install. Closing this issue, thanks for the review.