我的项目使用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(find_package)上的CMake警告:不提供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处的CMake错误(target_link_libraries):target_link_libraries的关键字签名已与一起使用目标"Archiver"。target_link_libraries与target必须是all关键字或all纯文本。
关键字签名的用途如下:
- CMakeLists.txt:31(target_link_libraries)
quazip的find脚本名为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
也就是说,要在代码中使用quazip
和zlib
,请添加以下行:
include_directories(${QUAZIP_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${QUAZIP_LIBRARIES})