[CMake] using fetch_content imported modules and not system one

Craig Scott craig.scott at crascit.com
Thu Aug 29 18:02:51 EDT 2019


On Thu, Aug 29, 2019 at 11:14 PM Stéphane Ancelot <sancelot at numalliance.com>
wrote:

> hi,
>
> i used fetch_content to download bullet library , but I cant use it.
>
> FetchContent_Declare(
>   bullet
>   GIT_REPOSITORY https://github.com/bulletphysics/bullet3.git
>   GIT_TAG        2.88
>
> )
>
> FetchContent_GetProperties(bullet)
> if(NOT bullet_POPULATED)
>   FetchContent_Populate(bullet)
>   add_subdirectory(${bullet_SOURCE_DIR} ${bullet_BINARY_DIR})
> endif()
>
> linking using bullet does not permit to find any include or lib file
>
Your FetchContent usage looks fine. I had a quick scan through the bullet
project and it uses very old CMake patterns. In particular, it doesn't use
any of the target-centered commands like target_include_directories(), etc.
This means it doesn't define PUBLIC or INTERFACE properties on targets,
which is why when you try to link to the bullet targets and include its
headers, they aren't being found. Nothing is telling consumers of those
libraries where to look.

Ideally, the bullet project would update to more modern CMake practices,
but that's not always a priority for projects that others manage. If you
need to get this working for your build, you will have to manually add the
missing header search paths and inter-library dependencies in your own
project. You can still call target_include_directories() on the bullet
targets from outside of the bullet source tree. You would do this
immediately after the add_subdirectory() call, something like the following
structure:

if(NOT bullet_POPULATED)
  FetchContent_Populate(bullet)
  add_subdirectory(${bullet_SOURCE_DIR} ${bullet_BINARY_DIR}
  target_include_directories(Bullet3Common INTERFACE
    ${bullet_SOURCE_DIR}/src
    ${bullet_SOURCE_DIR}/src/Bullet3Common
    ... more as you work out what is needed
  )
endif()

-- 
Craig Scott
Melbourne, Australia
https://crascit.com

Get the hand-book for every CMake user: Professional CMake: A Practical
Guide <https://crascit.com/professional-cmake/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190830/831c30c9/attachment.html>


More information about the CMake mailing list