# How to consume exported static library

**URL:** <https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303>\
**Category:** Code\
**Created:** [July 2, 2025, 2:59am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303 "2025-07-02T02:59:33Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [July 2, 2025, 10:45am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/14 "2025-07-02T10:45:00Z")

</div>

> [@thetic](#):
>
> How would I consume it in another project

By downloading it with [file(DOWNLOAD …)](https://cmake.org/cmake/help/latest/command/file.html#download):

```cmake
set(SOME_FILE "some.tgz")
message(STATUS "Downloading the file...")
file(DOWNLOAD "https://your.domain/data/${SOME_FILE}"
    "${CMAKE_CURRENT_SOURCE_DIR}/external/${SOME_FILE}"
    #SHOW_PROGRESS
    EXPECTED_HASH SHA1=b28c4cdfd737c41d1252945224aaddf97e45dc27 # should be the actual hash
    STATUS DOWNLOAD_DATASETS_RESULTS
)
list(GET DOWNLOAD_DATASETS_RESULTS 0 DOWNLOAD_STATUS_CODE)
list(GET DOWNLOAD_DATASETS_RESULTS 1 DOWNLOAD_ERROR_MESSAGE)
if(${DOWNLOAD_STATUS_CODE} EQUAL 0)
    message(STATUS "...successfully downloaded the file")
else()
    file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/external/${SOME_FILE}")
    message(WARNING "...failed to download the file. ${DOWNLOAD_ERROR_MESSAGE}") # might want to use FATAL_ERROR instead of WARNING
endif()

```

But since it’s a `.tgz` archive, you’ll also need to unpack it, perhaps with a [cmake -E](https://cmake.org/cmake/help/latest/manual/cmake.1.html#run-a-command-line-tool). And then, as many have already mentioned, ideally you’d need to have a CMake config for your package (_which is auto-generated if you have a [proper installation procedure](https://discourse.cmake.org/t/modifying-cmake-file-to-create-packageconfig-cmake-and-friends/14270)_), otherwise you’d need to manually add its headers and binaries to your project.

I’d recommend you to use a package manager (_such as [vcpkg](https://vcpkg.io/)_) for all this. Higher entry level, for sure, but then such tasks will get much more simpler for you going forward.

---

_[View the full topic](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303)._
