2

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)
dipatov
  • 23
  • 1
  • 5

1 Answers1

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})
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • Thanks. Can you help me, please, how to include JlCompress in my project? – dipatov Jan 16 '19 at 21:24
  • What is wrong with `#include `, as shown [there](http://quazip.sourceforge.net/classJlCompress.html)? – Tsyvarev Jan 16 '19 at 21:38
  • Exception, that "No such file or directory" – dipatov Jan 16 '19 at 21:47
  • Strange. What content of `QUAZIP_INCLUDE_DIRS` is? (You may print the variable's value with `message("${QUAZIP_INCLUDE_DIRS}")`. Check that one of the directories, listed in that variable, contains `JlCompress.h` file. – Tsyvarev Jan 16 '19 at 21:59
  • I wrote D:\quazip-0.7.3\quazip – dipatov Jan 16 '19 at 22:07
  • "I wrote D:\quazip-0.7.3\quazip" - What does it mean in the context of my previous comment? – Tsyvarev Jan 17 '19 at 08:11
  • I have corrected to `${QUAZIP_LIBRARIES}`, but now my project found ` , but when I was building, my project had a lot of exceptions, but when I was building with qMake, I didn't have exceptions – dipatov Jan 17 '19 at 09:22