macro(find_zlib)
    if(MSVC)
        if (ZLIB_LIB_DIR AND ZLIB_INCLUDE_DIR)
            # Legacy manual path override
            find_library(ZLIB NAMES zlib zlib1 z PATHS ${ZLIB_LIB_DIR})
            set(ZLIB_LIBS ${ZLIB})
            include_directories(${ZLIB_INCLUDE_DIR})
        else(ZLIB_LIB_DIR AND ZLIB_INCLUDE_DIR)
            # Use vcpkg toolchain or system find_package
            find_package(ZLIB REQUIRED)
            set(ZLIB_LIBS ZLIB::ZLIB)
        endif(ZLIB_LIB_DIR AND ZLIB_INCLUDE_DIR)
    else (MSVC)
        find_package(ZLIB REQUIRED)
        set(ZLIB_LIBS ${ZLIB_LIBRARIES})
        include_directories(${ZLIB_INCLUDE_DIRS})
    endif (MSVC)
endmacro()