# 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:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![thetic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/thetic/32/5632_2.png) [@thetic](https://discourse.cmake.org/u/thetic)\
**Post date:** [July 2, 2025, 2:59am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/1 "2025-07-02T02:59:33Z")

</div>

I’ve worked thru packaging a static library using the TGZ generator. If I were to host this file somewhere. How would I consume it in another project. I know FetchContent can handle remote archives, but they need to contain a CMakeLists.txt.

---

<div class="post-metadata">

**Author:** ![LegalizeAdulthood](https://discourse.cmake.org/user_avatar/discourse.cmake.org/legalizeadulthood/32/5282_2.png) [@LegalizeAdulthood](https://discourse.cmake.org/u/LegalizeAdulthood)\
**Post date:** [July 2, 2025, 3:36am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/2 "2025-07-02T03:36:47Z")

</div>

If I understand the situation correctly, isn’t it just a matter of using find\_package to locate the library once it’s installed locally?

---

<div class="post-metadata">

**Author:** ![thetic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/thetic/32/5632_2.png) [@thetic](https://discourse.cmake.org/u/thetic)\
**Post date:** [July 2, 2025, 3:39am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/3 "2025-07-02T03:39:29Z")

</div>

I only want to use it in the local project. I do not want to affect the global system state. Ideally I wouldn’t have to do any extra steps before calling CMake and it would work like FetchContent.

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [July 2, 2025, 3:55am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/4 "2025-07-02T03:55:47Z")

</div>

This exported cmake config package is not right!

See [Is beman.exemplar/beman.exemplar-version.cmake a vallid package name? - #2 by ClausKlein](https://discourse.cmake.org/t/is-beman-exemplar-beman-exemplar-version-cmake-a-vallid-package-name/14188/2)

---

<div class="post-metadata">

**Author:** ![thetic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/thetic/32/5632_2.png) [@thetic](https://discourse.cmake.org/u/thetic)\
**Post date:** [July 2, 2025, 3:58am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/5 "2025-07-02T03:58:26Z")

</div>

what?

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [July 2, 2025, 4:03am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/6 "2025-07-02T04:03:58Z")

</div>

If you install it, cmake will not find it.

---

<div class="post-metadata">

**Author:** ![thetic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/thetic/32/5632_2.png) [@thetic](https://discourse.cmake.org/u/thetic)\
**Post date:** [July 2, 2025, 4:46am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/7 "2025-07-02T04:46:14Z")

</div>

Let me reframe the question. Given a URL to a tarball created with CPack with the TGZ generator. How would I use it in a CMake project? Is there any way to directly reference the URL in the CMakeLists.txt? If not, how can I reference it after downloading it and extracting it?

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [July 2, 2025, 4:55am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/8 "2025-07-02T04:55:15Z")

</div>

With this `cmake file names` in the tar file, you can’t use it!

---

<div class="post-metadata">

**Author:** ![thetic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/thetic/32/5632_2.png) [@thetic](https://discourse.cmake.org/u/thetic)\
**Post date:** [July 2, 2025, 5:03am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/9 "2025-07-02T05:03:48Z")

</div>

I’ve removed the example from my question. I’m looking for help figuring out the workflow for consuming packaged CMake projects.

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [July 2, 2025, 5:15am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/10 "2025-07-02T05:15:17Z")

</div>

you may use [find\_package()](https://cmake.org/cmake/help/latest/command/find_package.html#id21) after installing your package.

---

<div class="post-metadata">

**Author:** ![thetic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/thetic/32/5632_2.png) [@thetic](https://discourse.cmake.org/u/thetic)\
**Post date:** [July 2, 2025, 5:16am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/11 "2025-07-02T05:16:54Z")

</div>

Can you explain what “installing” means in this context?

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [July 2, 2025, 5:19am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/12 "2025-07-02T05:19:13Z")

</div>

extracting the tar file to the right place.

or ` cmake --install ...`

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [July 2, 2025, 7:10am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303/13 "2025-07-02T07:10:57Z")

</div>

Assuming that you have a config file suitable for find\_package, you can download the tgz, unpack it, add the path to CMAKE\_ MODULE\_PATH and call find\_ package.

Without the config file, you can create the imported library target in your own.

---

<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.
