prefer openssl and zlib targets over library paths
diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt
index 13b41c5..6a66e5a 100644
--- a/lib/cpp/CMakeLists.txt
+++ b/lib/cpp/CMakeLists.txt
@@ -182,11 +182,17 @@
if(WITH_ZLIB)
find_package(ZLIB REQUIRED)
- include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
ADD_LIBRARY_THRIFT(thriftz ${thriftcppz_SOURCES})
target_link_libraries(thriftz PUBLIC thrift)
- target_link_libraries(thriftz PUBLIC ${ZLIB_LIBRARIES})
+
+ if(TARGET ZLIB::ZLIB)
+ target_link_libraries(thriftz PUBLIC ZLIB::ZLIB)
+ else()
+ include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
+ target_link_libraries(thriftz PUBLIC ${ZLIB_LIBRARIES})
+ endif()
+
ADD_PKGCONFIG_THRIFT(thrift-z)
endif()