swex / QZXingNu

simple Qt wrapper library for zxing-cpp rewrite by nu-book
Apache License 2.0
8 stars 2 forks source link

Linking to ZXing::Core instead of ZXingCore #4

Open tanius opened 4 years ago

tanius commented 4 years ago

Currently, linker configuration in this project is done like this, from here in CMakeLists.txt:

target_link_libraries(${PROJECT_NAME} 
    Qt5::Core Qt5::Multimedia Qt5::Gui Qt5::Concurrent 
    ZXingCore
)

That is the internal target name in ZXing and it works because ZXing is built as part of the same build tree via add_subdirectory(zxing-cpp/core).

However ZXing also provides an alias target name "ZXing::Core" (see), the same as their exported target name to use after find_package(ZXing).

Using such an alias is often done to allow users to decide if they want to build a component (here: ZXing) as part of the same CMake call or separately:

A primary use-case for ALIAS targets is for example or unit test executables accompanying a library, which may be part of the same buildsystem or built separately based on user configuration. […]

[After providing] add_library(Upstream::lib1 ALIAS lib1) in another directory, we can link unconditionally to the Upstream::lib1 target, which may be an IMPORTED target from a package, or an ALIAS target if built as part of the same buildsystem.

(Source: cmake-builsystem(7) → Pseudo Targets → Alias Targets)

In this repository, making it possible to build ZXing separately and importing its targets with find_package(…) would need some more changes. But this would be a preparation. The code quoted above would then be:

target_link_libraries(${PROJECT_NAME} 
    Qt5::Core Qt5::Multimedia Qt5::Gui Qt5::Concurrent 
    ZXing::Core
)

Background: I integrated QZXingNu into an application because it's the most up-to-date barcode reader component for Qt. It works great! :+1: :+1: I then switched to building ZXing separately. Doing so it took me some hours to figure out that I had to change the library target from ZXingCore to ZXing::Core (see) :smile:

axxel commented 4 years ago

A suggestion from upstream: please use ZXing::ZXing as I consider that to be the default name now. ZXing::Core is provided for backward compatibility, at the moment.