tesseract: CMake install is broken

Environment

  • Tesseract Version: master branch (cloned today)
  • Commit Number: c6539e21a04aa2a9e89c91e48f67f7dc28d0a44f
  • Platform: Linux hostname 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Current Behavior:

I run the following commands to build Tesseract and install it into a local directory:

$ git clone git@github.com:tesseract-ocr/tesseract.git
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S tesseract -B tesseract-build
$ cmake --build tesseract-build
$ cmake --install tesseract-build --prefix tesseract-install

Then I create the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)
project(test)
find_package(Tesseract 5 REQUIRED)

in the directory test. I then try to build it:

$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$(readlink -f tesseract-install) -DLeptonica_DIR=$(readlink -f leptonica-install/lib/cmake) -S test -B test-build
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /path/to/tesseract-install/lib/cmake/tesseract/TesseractConfig.cmake:33 (message):
  File or directory
  /path/to/tesseract-install/include;/path/to/tesseract-install/include/tesseract
  referenced by variable Tesseract_INCLUDE_DIRS does not exist !
Call Stack (most recent call first):
  /path/to/tesseract-install/lib/cmake/tesseract/TesseractConfig.cmake:49 (set_and_check)
  CMakeLists.txt:4 (find_package)

Looking in /path/to/tesseract-install/lib/cmake/tesseract/TesseractConfig.cmake, I see:

set_and_check(Tesseract_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include;${PACKAGE_PREFIX_DIR}/include/tesseract")

Which is obviously wrong (contains a ;).

Expected Behavior:

For find_package to succeed.

Suggested Fix:

Do not use CMakePackageConfigHelpers’s set_and_check macro. It only works with one path, not several. Here, INCLUDE_DIR is set to a list of two directories:

https://github.com/tesseract-ocr/tesseract/blob/c6539e21a04aa2a9e89c91e48f67f7dc28d0a44f/CMakeLists.txt#L364

Here it is passed to configure_package_config_file. The option NO_SET_AND_CHECK_MACRO should be given here.

https://github.com/tesseract-ocr/tesseract/blob/c6539e21a04aa2a9e89c91e48f67f7dc28d0a44f/CMakeLists.txt#L372-L376

And here it is passed to set_and_check. This should just be replaced with normal set or custom checking logic should be implemented.

https://github.com/tesseract-ocr/tesseract/blob/c6539e21a04aa2a9e89c91e48f67f7dc28d0a44f/cmake/templates/TesseractConfig.cmake.in#L25

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (9 by maintainers)

Most upvoted comments

See https://github.com/tesseract-ocr/tesseract/actions/runs/522034896/workflow

for cmake builds which work.

On Sat, Jan 30, 2021, 22:29 Alex Reinking notifications@github.com wrote:

Environment

Current Behavior:

I run the following commands to build Tesseract and install it into a local directory:

$ git clone git@github.com:tesseract-ocr/tesseract.git $ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S tesseract -B tesseract-build $ cmake --build tesseract-build $ cmake --install tesseract-build --prefix tesseract-install

Then I create the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.16) project(test) find_package(Tesseract 5 REQUIRED)

in the directory test. I then try to build it:

$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$(readlink -f tesseract-install) -DLeptonica_DIR=$(readlink -f leptonica-install/lib/cmake) -S test -B test-build – The C compiler identification is GNU 9.3.0 – The CXX compiler identification is GNU 9.3.0 – Detecting C compiler ABI info – Detecting C compiler ABI info - done – Check for working C compiler: /usr/bin/cc - skipped – Detecting C compile features – Detecting C compile features - done – Detecting CXX compiler ABI info – Detecting CXX compiler ABI info - done – Check for working CXX compiler: /usr/bin/c++ - skipped – Detecting CXX compile features – Detecting CXX compile features - done CMake Error at /path/to/tesseract-install/lib/cmake/tesseract/TesseractConfig.cmake:33 (message): File or directory /path/to/tesseract-install/include;/path/to/tesseract-install/include/tesseract referenced by variable Tesseract_INCLUDE_DIRS does not exist ! Call Stack (most recent call first): /path/to/tesseract-install/lib/cmake/tesseract/TesseractConfig.cmake:49 (set_and_check) CMakeLists.txt:4 (find_package)

Looking in /path/to/tesseract-install/lib/cmake/tesseract/TesseractConfig.cmake, I see:

set_and_check(Tesseract_INCLUDE_DIRS “${PACKAGE_PREFIX_DIR}/include;${PACKAGE_PREFIX_DIR}/include/tesseract”)

Which is obviously wrong (contains a 😉. Expected Behavior:

For find_package to succeed. Suggested Fix:

Fix the set_and_check macro to loop over its arguments:

function (set_and_check var files) foreach (file IN LISTS files) if (NOT EXISTS “${file}”) message(FATAL_ERROR “File or directory ${file} referenced by variable ${var} does not exist!”) endif () endforeach () set(${var} “${files}” PARENT_SCOPE) endfunction ()

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tesseract-ocr/tesseract/issues/3269, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABG37I2TITKRP76LQ7YYHFTS4Q3FTANCNFSM4W2PDJYQ .