[CMake] Generator Expressions and FetchContent

Saad Khattak saadrustam at gmail.com
Sat Mar 17 17:12:51 EDT 2018


Hi,

ExternalProject_Add builds, generates and installs and thus any generator
expressions used will be expanded by the time another library uses it.

For example, if I add a library LibA using ExternalProject_Add, I can then
query the target property INTERFACE_INCLUDE_DIRECTORIES and get the include
directory for the library:

get_target_property(LibA_INCLUDE_DIRECTORIES LibA
  INTERFACE_INCLUDE_DIRECTORIES
  )

This allows me to then use the variable LibA_INCLUDE_DIRECTORIES in my
CMake include(...) statements. However, with FetchContent, this is no
longer possible.

The reason I would like to query a variable is because at project
generation time, I invoke FetchContent only if LibA is not found by
find_package(LibA).

Thus, the include directory for LibA may be in the current build directory
(through FetchContent) OR it may be found in the folder where LibA is
cloned by the user and generated/built OR an INSTALL of LibA.

Perhaps I should not be using `get_target_property` to get the a library's
include directory? Either way, would like some guidance in solving this
issue.

Thank you,
Saad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180317/aecd0b57/attachment.html>


More information about the CMake mailing list