如何使用zlib安装minizip?

时间:2017-05-04 13:40:41

标签: c++ cmake zlib

我有以下cmake文件来下载,构建和安装zlib:

cmake_minimum_required ( VERSION 2.8.7 )
include (ExternalProject)

if(UNIX)
  # An external project for zlib 
  SET (GIT_URL https://github.com/madler/zlib.git) 
  SET (ZLIB_INSTALL ${CMAKE_CURRENT_BINARY_DIR}) 
  SET (ZLIB_INCLUDE ${CMAKE_BINARY_DIR}/include/zlib) 
  SET (ZLIB_STATIC  ${CMAKE_BINARY_DIR}/lib/libz.a )

  ExternalProject_Add(zlib     
    PREFIX zlib     
    GIT_REPOSITORY ${GIT_URL}     
    INSTALL_DIR ${ZLIB_INSTALL}     
    PATCH_COMMAND ${CMAKE_COMMAND} -E remove <SOURCE_DIR>/zconf.h     
    BUILD_IN_SOURCE 1     
    PATCH_COMMAND ""     
    CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --includedir=${ZLIB_INCLUDE}     
  )

  SET (ZLIB_INCLUDE_DIR ${ZLIB_INSTALL}/include/zlib) 
  SET (ZLIB_LIBRARY "${ZLIB_INSTALL}")
  ADD_LIBRARY (ZLIB_LIB STATIC IMPORTED DEPENDS zlib)
  SET_TARGET_PROPERTIES (ZLIB_LIB PROPERTIES IMPORTED_LOCATION "${ZLIB_STATIC}")
endif(UNIX)

但是这个cmake文件只安装了zlib。我也想安装minizip。 Minizip是“zlib的一部分”。在zlib存储库中有一个具有minizip的目录。

如何在同一个cmake文件中安装minizip?有可能吗?

minizip位于zlib存储库中:

- zlib
    - contrib
        - minizip
        - ....
    - ...
- ...

我有cmake文件来安装minizip:

cmake_minimum_required(VERSION 2.8)

project(minizip)

set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )

set(BUILD_SHARED_LIBS OFF)

find_package (ZLIB REQUIRED)

if (ZLIB_FOUND) 
  set(ZLIB_LIBRARY ${CMAKE_BINARY_DIR}/ZLIB/src/ZLIB/contrib)
  SET (minizip ${CMAKE_BINARY_DIR}/lib/minizip)

  if(CMAKE_HOST_APPLE)
    set(PLATFORM __APPLE__)
  elseif(CMAKE_HOST_UNIX)
    set(PLATFORM unix)
  elseif(CMAKE_HOST_WIN32)
    set(PLATFORM _WIN32)
  else(CMAKE_HOST_APPLE)
    message(FATAL_ERROR "Not supported Platform")
    endif(CMAKE_HOST_APPLE)

  add_definitions(-D${PLATFORM})

set(SOURCE
  ${ZLIB_LIBRARY}/minizip/ioapi.c
  ${ZLIB_LIBRARY}/minizip/miniunz.c
  ${ZLIB_LIBRARY}/minizip/minizip.c
  ${ZLIB_LIBRARY}/minizip/unzip.c
  ${ZLIB_LIBRARY}/minizip/zip.c
)

if(WIN32)
    set(SOURCE ${SOURCE} ${ZLIB_LIBRARY}/minizip/iowin32.c)
endif(WIN32)

set(HEADERS
  ${ZLIB_LIBRARY}/minizip/crypt.h
  ${ZLIB_LIBRARY}/minizip/ioapi.h 
  ${ZLIB_LIBRARY}/minizip/miniunz.h
  ${ZLIB_LIBRARY}/minizip/unzip.h
)

if(WIN32)
    set(HEADERS ${HEADERS} ${ZLIB_LIBRARY}/minizip/iowin32.h)
endif(WIN32)

add_library(minizip ${SOURCE} ${HEADERS})
target_link_libraries(minizip PUBLIC "-static" ZLIB_STATIC)

add_dependencies ( minizip zlib)

install(
  TARGETS minizip EXPORT minizip-exports
  INCLUDES DESTINATION "include"
  RUNTIME DESTINATION "bin"
  LIBRARY DESTINATION "lib"
  ARCHIVE DESTINATION "lib"
)

install(
  FILES ${HEADERS}
  DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/include/minizip"
)

ADD_LIBRARY (MINIZIP_LIB STATIC IMPORTED DEPENDS minizip)
SET_TARGET_PROPERTIES (MINIZIP_LIB PROPERTIES IMPORTED_LOCATION ${minizip})

ENDIF()

我想在安装minizip之前安装zlib。 但是当我跑步时

  

cmake ..

我有以下错误:

  

在modules / minizip.cmake上生成错误:50(add_library):     找不到源文件:

     

/home/lais/Imagens/agent/build/ZLIB/src/ZLIB/contrib/minizip/ioapi.c

     

尝试扩展.c .C .c ++ .cc .cpp .cxx .m .M .mm .h .hh .h ++ .hm .hpp     .hxx .in .txx   呼叫堆栈(最近一次呼叫):     CMakeLists.txt:59(包括)

     

CMake错误:无法确定目标“minizip”的链接语言。   CMake错误:CMake无法确定目标的链接器语言:minizip

我有一个顶级cmake,需要这两个模块:

cmake_minimum_required( VERSION 2.8.7 )

project( project )

# version number
set ( VERSION_MAJOR 0 )
set ( VERSION_MINOR 0 )

# cpr requires c++11
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")

# src : main + jsoncpp library
file ( GLOB SOURCES src/project/*.cpp )

# src : collect functions - depend on OS
if ( WIN32 )
    file ( GLOB SOURCES ${SOURCES} src/project/windows/*.cpp )
else ()     # if( UNIX )
    file ( GLOB SOURCES ${SOURCES} src/project/linux/*.cpp )
endif ()

# src : curl requests

# options for cpr
# avoid experimental use of openssl
option( CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" OFF )
# avoid building tests
option( BUILD_CPR_TESTS "Set to ON to build cpr tests." OFF )

# options for curl
# avoid building tests
option( BUILD_CURL_TESTS "Set to ON to build cURL tests." OFF )
# avoid running tests - set ON again in download version or if errors occur
option( RUN_CURL_TESTS "Set to ON to run cURL tests." OFF )

add_subdirectory ( lib/cpr )
include_directories ( ${CPR_INCLUDE_DIRS} )
include_directories ( ${CURL_INCLUDE_DIRS} )

# src : DtWinVer - Windows Version/Edition class
if ( WIN32 )
    add_subdirectory ( lib/dtwinver )
endif ()

# headers
include_directories ( "include" )
include_directories ( "${CMAKE_BINARY_DIR}/include" )

# scr = libboost

include ( "modules/boost.cmake" )

# src = zlib
include ( "modules/zlib.cmake" )

# src = minizip
include ( "modules/minizip.cmake" )

# compile
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" )
add_executable ( project-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} )
target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR}     ${CPR_LIBRARIES} ${CURL_LIBRARIES} ${FILESYSTEM_LIB} ${SYSTEM_LIB} ${REGEX_LIB}  ${PROGRAM_OPTIONS_LIB} ${ZLIB_STATIC} ${minizip})

add_dependencies ( project-v${VERSION_MAJOR}.${VERSION_MINOR} Boost)
add_dependencies ( project-v${VERSION_MAJOR}.${VERSION_MINOR} zlib)
add_dependencies ( project-v${VERSION_MAJOR}.${VERSION_MINOR} minizip)


if ( WIN32 )
    target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR} dtwinver )
else ()
    # libudev
    target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR} udev )
endif ()

1 个答案:

答案 0 :(得分:0)

看起来您的源软件包不完整。

minizip只是一个简单的文件minizip.c。为什么需要cmake?只需编译并与zlib链接,一切都会好起来的。