Constantin
Constantin

Reputation: 8961

cmake - different library for release and debug (zlib/libpng)

I'm trying to build libpng using cmake. For doing so, an variable for the zlib include directory and zlib library is passed to cmake. Like this:

cmake .. -DZLIB_LIBRARY=../../zlib-1.2.8/build/$(Configuration)/zlib.lib -DZLIB_INCLUDE_DIR=../../zlib-1.2.8/

which works perfect in release build - but not in debug build. It's almost working - I'm using $(Configuration) in the path which will use in MS VS either "Debug" or "Release" depending on the Configuration. But mt problem is, that zlib is using different filenames in Debug & Release Mode. Like:

zlib.lib zlib.dll (Release)

zlibd.lib zlibd.dll (Debug)

If I'm using the command above, it will search for the library:

../../zlib-1.2.8/build/Release/zlib.lib (Release -> works)

../../zlib-1.2.8/build/Debug/zlib.lib (Debug -> works not, because the filename is zlibd.lib)

Any ideas how I can accomplish different library names depending on the configuration with cmake (I don't want to change it in the generated VS Project)?

Upvotes: 0

Views: 2987

Answers (1)

ismail
ismail

Reputation: 47632

Use optimized and debug directives like this

SET(LIBZ_LIB optimized ${PROJECT_SOURCE_DIR}/zlib.lib
             debug ${PROJECT_SOURCE_DIR}/zlibd.lib)

target_link_libraries(your-app ... ${LIBZ_LIB}

Of course you'll have to fix the path to the library files.

Upvotes: 3

Related Questions