CPMAddPackage lib

Hello all,

I am fairly new to CMake but am interested in using the CMake Package Management (CPM) to add a local library/source files. My question is probably simple, so please forgive.

I would like to know how to download and install shared library for zlib via a call(s) to CPMAddPackage call, then link against this downloaded package for some local C++ code. Can anyone point me to an example of this or provide some simple code that illustrates this?

Bonus question, if this is okay, I would was thinking of using Boost.Iostreams for compression/decompression via CPMAddPackage call later on, but have read that there can be issues with ZLIB and Boost.Iostreams in Windows environment. I need my code to run on both Windows and Linux environments. Does anyone have any information on this situation?

Thanks to any help.

I think I might have solved the issue. I am posting it here for anyone else who may run into the same problem.

In a Cmake script called third_party.cmake in cmake/ directory.

# CPM script
include(cmake/CPM.cmake)

# Storage location
set(CPM_SOURCE_CACHE ${CMAKE_SOURCE_DIR}/third_party)

# Add ZLIB
set(ZLIB_REPO "https://github.com/madler/zlib.git"
     CACHE STRING "ZLIB repository location."
)
CPMAddPackage(
    NAME zlib 
    GIT_REPOSITORY ${ZLIB_REPO}
    GIT_TAG "v1.2.13"
    OPTIONS
    "CMAKE_POSITION_INDEPENDENT_CODE True"
)
if(zlib_ADDED)
    target_include_directories(zlib 
                               PUBLIC $<BUILD_INTERFACE:${zlib_BINARY_DIR}>
                               PUBLIC $<INSTALL_INTERFACE:include>)
    target_include_directories(zlibstatic 
                               PUBLIC $<BUILD_INTERFACE:${zlib_BINARY_DIR}>
                               PUBLIC $<INSTALL_INTERFACE:include>)
               
    message(STATUS "Cmake added local zlib: ${zlib_SOURCE_DIR}")

Reposted here: Sorry for repost - CPMAddPackage with ZLIB