# Obtain compile and link flags for a package

**URL:** https://discourse.cmake.org/t/obtain-compile-and-link-flags-for-a-package/6538
**Category:** Usage
**Created:** [September 21, 2022, 8:03am UTC](https://discourse.cmake.org/t/obtain-compile-and-link-flags-for-a-package/6538 "2022-09-21T08:03:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![szhorvat](https://discourse.cmake.org/user_avatar/discourse.cmake.org/szhorvat/32/1906_2.png) [@szhorvat](https://discourse.cmake.org/u/szhorvat)
#### Post date: [September 21, 2022, 8:03am UTC](https://discourse.cmake.org/t/obtain-compile-and-link-flags-for-a-package/6538/1 "2022-09-21T08:03:35Z")

</div>

I am looking for a way to get the compilation and linking flags for an installed CMake package (that can be found with `find_package`), and use them in a non-CMake project. Does CMake provide a reasonably simple way to do this?

I found the `cmake --find-package` option, but the documentation states that it should not be used. Also, it does not seem to work in all cases.

I am not looking for a universal solution that will print the flags for _any_ package, merely a starting point to implement a solution that can get the flags for one particular package.

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [September 21, 2022, 10:23am UTC](https://discourse.cmake.org/t/obtain-compile-and-link-flags-for-a-package/6538/2 "2022-09-21T10:23:21Z")

</div>

Your package must expose them in some way from the config file. Ideally via INTERFACE\_\* properties on imported target(s). Otherwise via variable.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 21, 2022, 1:18pm UTC](https://discourse.cmake.org/t/obtain-compile-and-link-flags-for-a-package/6538/3 "2022-09-21T13:18:04Z")

</div>

ParaView has a tool which can extract out the information for its own package [here](https://gitlab.kitware.com/paraview/paraview/-/blob/master/CMake/paraview-config.cmake.in). Something like this is the most robust way of doing it (but does require per-package logic).
