Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: Set zlib path

Tags:

cmake

I'm trying to compile libzip on Windows using CMake to generate makefiles. Libzip needs zlib so I'm doing the following:

mkdir build
cd build
cmake -DZLIB_LIBRARY=../../../zlib-1.2.11 -DZLIB_INCLUDE_DIR=../../../zlib-1.2.11 ..

This doesn't work, however. I get the following error:

CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)

Why is that? I have defined ZLIB_LIBRARY and ZLIB_INCLUDE_DIR to point to the latest zlib.

I've also tried the following:

mkdir build
cd build
cmake .. -DZLIB_LIBRARY=../../../zlib-1.2.11 -DZLIB_INCLUDE_DIR=../../../zlib-1.2.11

When I run CMake like this, I get the following two warnings:

CMake Warning:
Manually-specified variables were not used by the project:
ZLIB_INCLUDE_DIR
ZLIB_LIBRARY

In comparison to the first approach, however, build files are now written to my build directory. When running nmake, however, only zlib seems to get built. libzip itself isn't built at all.

I'm out of ideas here. What am I doing wrong?

like image 887
Andreas Avatar asked Oct 02 '17 17:10

Andreas


1 Answers

To answer my own question, using relative paths for ZLIB_LIBRARY and ZLIB_INCLUDE_DIR was the problem. When using absolute paths, it works just fine. Furthermore, ZLIB_LIBRARY needs to point to the library itself. Here is my final build line which works:

cmake -DZLIB_INCLUDE_DIR=d:\mystuff\zlib-1.2.11 -DZLIB_LIBRARY=d:\mystuff\zlib-1.2.11\build\zlibstatic.lib -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release ..
like image 149
Andreas Avatar answered Nov 15 '22 08:11

Andreas