如何在CMake中连接QuaZip库

时间:2019-01-16 18:58:27

标签: c++ qt cmake quazip

我的项目使用QuaZip库,我需要通过CMake构建该项目。如何将此库添加到CMakeLists? 从库中,我需要JlCompress

我的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}
)

构建错误:

  

CMakeLists.txt:13的CMake警告(find_package):不提供   CMAKE_MODULE_PATH中的“ Findquazip.cmake”此项目已询问CMake   查找“ quazip”提供的程序包配置文件,但CMake   没有找到一个。

     

找不到“ quazip”提供的程序包配置文件   具有以下任何名称:

quazipConfig.cmake
quazip-config.cmake
     

将“ quazip”的安装前缀添加到CMAKE_PREFIX_PATH或进行设置   “ quazip_DIR”到包含上述文件之一的目录。如果   “ quazip”提供了单独的开发包或SDK,请确保它   已安装。

     

CMakeLists.txt:37(target_link_libraries)的CMake错误:   target_link_libraries的关键字签名已用于   目标“归档”。将target_link_libraries与   目标必须是全关键字或全格式。

     

此处使用了关键字签名:

     
      
  • CMakeLists.txt:31(target_link_libraries)
  •   

1 个答案:

答案 0 :(得分:0)

quazip的查找脚本名为FindQuaZip5.cmake(在安装过程中重命名)。因此,要查找quazip,您需要使用

find_package(QuaZip5)

查找脚本的含义在其头部进行了描述:

# 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

也就是说,要在您的代码中将quazipzlib一起使用,请添加以下行:

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