# Retrieving imported preprocessor definition

**URL:** https://discourse.cmake.org/t/retrieving-imported-preprocessor-definition/4342
**Category:** Usage
**Created:** [October 26, 2021, 7:11am UTC](https://discourse.cmake.org/t/retrieving-imported-preprocessor-definition/4342 "2021-10-26T07:11:16Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [October 26, 2021, 7:11am UTC](https://discourse.cmake.org/t/retrieving-imported-preprocessor-definition/4342/1 "2021-10-26T07:11:16Z")

</div>

Hi,

I’ve got a library L that may define some preprocessor definition MYDEF with target\_compile\_definitions(L PUBLIC MYDEF).

How do I check, in the cmake file of a client application A, if MYDEF is defined ?

L is properly installed and imported through find\_package(L)

Thanks  
A.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [October 26, 2021, 7:43am UTC](https://discourse.cmake.org/t/retrieving-imported-preprocessor-definition/4342/2 "2021-10-26T07:43:29Z")

</div>

My issue may be a bit more complicated than anticipated and related to another issue: [Findmodule transitivity?](https://discourse.cmake.org/t/findmodule-transitivity/4333)  
What I want exactly do is:  
L may depend on a third party library TP that is not properly packaged.  
If L uses TP, it imports TP with a FindTP.cmake file and defines a compile definition TPNEEDED

What I’d like to do is, when, in A, I find\_package(L) then TP is automatically linked with A, but only if L actually needed TP.

the FindTP.cmake does not seem to be used “transitively”, and I can’t retrieve if TPNEEDED is defined so far. Besides, I suppose that it may be only defined after find\_package(L) that will generate an error because TP is not found, before I can do anything about it.

Thus, what would be the proper way to manage this optional dependency?

Thanks,  
A.

---

<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: [October 26, 2021, 7:21pm UTC](https://discourse.cmake.org/t/retrieving-imported-preprocessor-definition/4342/3 "2021-10-26T19:21:20Z")

</div>

maybe you will read this: [It’s Time To Do CMake Right | Pablo Arias](https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/)

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [October 28, 2021, 3:41pm UTC](https://discourse.cmake.org/t/retrieving-imported-preprocessor-definition/4342/4 "2021-10-28T15:41:53Z")

</div>

Hi,

Also an interesting link that rises some questions:  
1- target\_include\_directories(JSONUtils … PRIVATE ${CMAKE\_CURRENT\_SOURCE\_DIR}/src)  
Why is not the PRIVATE part within the BUILD\_INTERFACE)  
2- in the FindModule.cmake example, what does the pkg\_check\_modules function (I’ve just looked at [https://cmake.org/cmake/help/v3.22/module/FindPkgConfig.html](https://cmake.org/cmake/help/v3.22/module/FindPkgConfig.html) but have nor really understood its usage)  
3- what is the difference between RapidJSON\_INCLUDE\_DIR and RapidJSON\_INCLUDE\_DIRS and why are they not set in the same way?

I’m now checking if my practice is on line with the rest of the post but it seems to.

Anyway, it does not enlight me on my optional dependency issue…

Thanks by advance for more insights,  
A.

---

<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: [October 30, 2021, 5:30am UTC](https://discourse.cmake.org/t/retrieving-imported-preprocessor-definition/4342/5 "2021-10-30T05:30:47Z")

</div>

Hi,

extract the `properties` you are interesing in form your [imported target](https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets)  
but you are on the wrong way if you do it.

You should fix the required packages or build them yourself with `fetch contents` or `CPM.cmake`.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [November 2, 2021, 10:43am UTC](https://discourse.cmake.org/t/retrieving-imported-preprocessor-definition/4342/6 "2021-11-02T10:43:07Z")

</div>

Hi, I didn’t know about CPM. I’ll look into it as it seems interesting.

Regards  
A.
