How to connect the QuaZip library in CMake

2019-08-19 08:57发布

问题:

My project uses the QuaZip library, and I need to build the project through CMake. How to add this library to CMakeLists? From the library I need JlCompress

My CMakeLists:

cmake_minimum_required(VERSION 3.6)
#set_property(GLOBAL PROPERTY USE_FOLDERS ON)
#set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "cmake")

set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)

project(Archiver LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui)
find_package(zlib)
find_package(QuaZip5)
include_directories(${QUAZIP_INCLUDE_DIRS})

set(project_ui
    mainwindow.ui)
set(project_headers
    archive.h
    mainwindow.h)
set(project_sources
    main.cpp
    archive.cpp
    mainwindow.cpp)

qt5_wrap_ui(project_headers_wrapped ${project_ui})
qt5_wrap_cpp(project_sources_moc ${project_headers})

add_executable(${PROJECT_NAME} ${project_headers} ${project_sources} 
    ${project_sources_moc} ${project_headers_wrapped})

target_link_libraries(${PROJECT_NAME} 
    PUBLIC 
    Qt5::Core
    Qt5::Gui
    Qt5::Widgets
    ${QUAZIP_LIBRARIES}
)

Build error:

CMake Warning at CMakeLists.txt:13 (find_package): By not providing "Findquazip.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "quazip", but CMake did not find one.

Could not find a package configuration file provided by "quazip" with any of the following names:

quazipConfig.cmake
quazip-config.cmake

Add the installation prefix of "quazip" to CMAKE_PREFIX_PATH or set "quazip_DIR" to a directory containing one of the above files. If "quazip" provides a separate development package or SDK, be sure it has been installed.

CMake Error at CMakeLists.txt:37 (target_link_libraries): The keyword signature for target_link_libraries has already been used with the target "Archiver". All uses of target_link_libraries with a target must be either all-keyword or all-plain.

The uses of the keyword signature are here:

  • CMakeLists.txt:31 (target_link_libraries)

回答1:

The find script for quazip is named FindQuaZip5.cmake (it is renamed during installation). So for find quazip you need to use

find_package(QuaZip5)

Meaning of the find script is described in its head:

# QUAZIP_FOUND               - QuaZip library was found
# QUAZIP_INCLUDE_DIR         - Path to QuaZip include dir
# QUAZIP_INCLUDE_DIRS        - Path to QuaZip and zlib include dir (combined from QUAZIP_INCLUDE_DIR + ZLIB_INCLUDE_DIR)
# QUAZIP_LIBRARIES           - List of QuaZip libraries
# QUAZIP_ZLIB_INCLUDE_DIR    - The include dir of zlib headers

That is, for use quazip with zlib in your code, add these lines:

include_directories(${QUAZIP_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${QUAZIP_LIBRARIES})