如何在externalproject_add()之后添加add_subdirectory?

时间:2017-05-05 13:00:32

标签: cmake zlib

我必须下载zlib才能在我的项目中使用。 我使用externlproject_add()来下载所有zlib存储库,构建并安装它。 之后,我想安装一个lib,它是zlib存储库的一部分:minizip。

如何设置对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 )
SET (MINIZIP_DIR ${CMAKE_CURRENT_BINARY_DIR}/ZLIB/src/ZLIB/contrib/minizip)

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

 find_package(ZLIB REQUIRED)
 if(ZLIB_FOUND)
      add_subdirectory (${MINIZIP_DIR})
 endif(ZLIB_FOUND)

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)

使用这个zlib模块,我有一个错误,跟在目录

之后
  

/家庭/ LAIS / Imagens /剂/建造/ ZLIB / SRC / ZLIB /了contrib / minizip

我跑

还不存在

  

cmake ..

这是真的。还不存在。我应该告诉cmake它。但我不知道该怎么做。

0 个答案:

没有答案