Tom Macdonald
Tom Macdonald

Reputation: 6593

cmake minizip linking

I need to add a dependency in my project to minizip, which is part of zlib. I have the library on my system, so I can do

target_link_libraries (myproject /usr/lib64/libminizip.so)

but I cannot find out what is the portable way to do it. I can find and link zlib itself with no problems using

find_package(ZLIB REQUIRED)

but that does not link to the minizip library, as the ${ZLIB_LIBRARIES} variable is set to /usr/lib64/libz.so and I need /usr/lib64/libminizip.so.

Upvotes: 3

Views: 2684

Answers (1)

Tom Macdonald
Tom Macdonald

Reputation: 6593

One uses the package-config macros in this case.

First add

INCLUDE (FindPkgConfig)

then before the linking step we need to fill the UNZIP_LIBRARIES variable with the right information:

if (PKG_CONFIG_FOUND)
        PKG_CHECK_MODULES(UNZIP minizip)
endif (PKG_CONFIG_FOUND)

and finally, the linking step:

target_link_libraries (myproject ${UNZIP_LIBRARIES})

Upvotes: 4

Related Questions