2

I'm facing the following problem. I want to build xzing-cpp from source to integrate it with one of my projects - I don't want to install it to (/usr/...).

This is what my CMakeList looks like:

cmake_minimum_required(VERSION 3.0)
project(sample)
set(CMAKE_CXX_STANDARD 20)

set(ZXing_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/zxing/build")
find_package(ZXing REQUIRED)

add_executable(sample main.cpp ZXingOpenCV.h)

target_link_libraries(sample ZXing)

But when I do so I get the following error:

CMake Error at dependencies/zxing/build/ZXingConfig.cmake:26 (include):
include could not find requested file:
/home/code/crepo/sample/dependencies/zxing/build/ZXingTargets.cmake

Call Stack (most recent call first):
  CMakeLists.txt:11 (find_package)

But why there is no ZXingTargets.cmake file?

I downloaded the source got from the offical repo and did cmake build & make.

What is wrong there, anyone can help?

Thanks

repo: https://github.com/nu-book/zxing-cpp

Merit
  • 21
  • 2
  • 2
    Does this answer your question? [CMake link to external library](https://stackoverflow.com/questions/8774593/cmake-link-to-external-library) – zerocukor287 Dec 06 '21 at 16:37
  • No I want to build & compile the source code from source and then I want to integrate the library into my project - I don't want to install the build to /usr/local/include or something like that. The library should be included from the project directory itself. – Merit Dec 06 '21 at 16:39
  • @drecherjm Edited sorry it should be sample in both cases – Merit Dec 06 '21 at 16:40
  • 5
    For `find_package(ZXing)` to work, the project `ZXing` needs to be **installed**. Just building it is insufficient. You could install the project into custom location (by passing `-DCMAKE_INSTALL_PREFIX=<...>` to `cmake` command which configures the project). Variable `ZXing_DIR` should refer to the **installation directory**. – Tsyvarev Dec 06 '21 at 17:52
  • you should try ExternalProject src: https://cmake.org/cmake/help/latest/module/ExternalProject.html – Mizux Dec 07 '21 at 07:51

0 Answers0