1

I have to download zlib to use in my project. I use externlproject_add() to downaload all zlib repository, build and install it. After it, I want do install a lib that is part of zlib repository: minizip.

How to set this dependency on cmake?

zlib module:

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)

With this zlib module I have an error that following directory

/home/lais/Imagens/agent/build/ZLIB/src/ZLIB/contrib/minizip

doesn't exist yet when I run

cmake ..

And it's true. Doesn't exist yet. I should tell cmake it. But I don't know how to do it.

4
  • If you expect that find_package finds your ZLIB installation via ExternalProject_Add, you are wrong. At the time when find_package is executed (configuration stage), zlib sources are even not downloaded. See e.g. this question or that one. Same problem with add_subdirectory. Commented May 5, 2017 at 16:30
  • Is it acceptible for you purpose to build minizip using ExternalProject_Add means instead of add_subdirectory? Commented May 5, 2017 at 16:37
  • The zlib project has a CMakeLists.txt file, so you could also consider bringing it into your build in a similar way to the technique mentioned here. Then you wouldn't have to define any of the libraries, etc. manually and you wouldn't have to convert your project to a superbuild arrangement. Commented May 6, 2017 at 23:30
  • 2
    Please, do not add SOLVED into the title. When there is an accepted answer, the question is highlighted as "resolved" automatically. Commented May 8, 2017 at 17:08

1 Answer 1

0

I solved it download a zip file that have minizip.

cmake_minimum_required ( VERSION 2.8.7 ) include (ExternalProject) project (zlib) if(UNIX) # An external project for zlib SET (URL http://www.winimage.com/zLibDll/unzip101e.zip) SET (MINIZIP_INSTALL ${CMAKE_CURRENT_BINARY_DIR}) SET (MINIZIP_STATIC ${CMAKE_BINARY_DIR}/lib/minizip.a ) message ("zlib = ${zlib}") ExternalProject_Add(minizip DEPENDS zlib PREFIX minizip URL ${URL} INSTALL_DIR ${MINIZIP_INSTALL} BUILD_IN_SOURCE make CONFIGURE_COMMAND "" ) SET (MINIZIP_LIBRARY "${MINIZIP_INSTALL}") ADD_LIBRARY (MINIZIP_LIB STATIC IMPORTED DEPENDS minizip, zlib) SET_TARGET_PROPERTIES (MINIZIP_LIB PROPERTIES IMPORTED_LOCATION "${MINIZIP_STATIC}") endif(UNIX) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.