Use cmake FetchContent_Declare dependend external libraries

134 views Asked by At

curretnly i am working on a Qt6-based project in which i would like to use the QuaZip-Library. For this, i know that i first need to get zlib, so i used FetchContent_Declare to get both into my cmake build system:

cmake_minimum_required(VERSION 3.16)

# QT6 suchen
find_package(Qt6 REQUIRED COMPONENTS Widgets)

# Erzeuge Einstellungen für qt-projekt
qt_standard_project_setup()

# Festlegen der Output-Directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

# Abrufen von notwendigen Abhängigkeiten
include(FetchContent)
FetchContent_Declare(
    zlib
    PREFIX ${PROJECT_SOURCE_DIR}/vendor/zlib
    GIT_REPOSITORY https://github.com/madler/zlib
    GIT_TAG 09155eaa2f9270dc4ed1fa13e2b4b2613e6e4851 # Master, Release Version 1.3
    FIND_PACKAGE_ARGS NAMES ZLIB
)
FetchContent_MakeAvailable(zlib)

FetchContent_Declare(
    quazip
    PREFIX ${PROJECT_SOURCE_DIR}/vendor/quazip
    GIT_REPOSITORY https://github.com/stachenov/quazip
    GIT_TAG 566fa496649b8cb09018b497575bb3bf2977965f # Master, Release Version 1.4
#   DEPENDS zlib
    FIND_PACKAGE_ARGS NAMES QuaZip
)
FetchContent_MakeAvailable(quazip)

# Subdirectories / Projekte hinzufügen
add_subdirectory(ETEvalT)

However QuaZip cannot link against ZLIB, Visual Studio gives the following error message:

Fehler      CMake Error at out/build/x64-Debug/_deps/quazip-src/quazip/CMakeLists.txt:69 (target_link_libraries):
  Target "QuaZip" links to:

    ZLIB::ZLIB

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.   QuaZip_Library  D:\ExerciseTrackerEvaluationTool\out/build/x64-Debug/_deps/quazip-src/quazip/CMakeLists.txt

Because this is my first time using cmake in a larger project it would be nice if anyone of you could tell me what the problem could be and how to solve this elegant.

Have a nice day Niklas

I have already tried to find a solution by using the documentation and goole, but it seems that noone else hat this issue before or, which is the most probable solution, my english is to bad to formulate a valid search request.

0

There are 0 answers