[CMake] How does :: actually works?

Klaim - Joël Lamotte mjklaim at gmail.com
Mon Jun 15 16:43:41 EDT 2015


On 15 June 2015 at 18:20, Johannes Zarl-Zierl <johannes.zarl-zierl at jku.at>
wrote:

> On Monday 15 June 2015 16:40:10 Klaim - Joël Lamotte wrote:
> > So far I didn't get what imported targets helps with, so I'm a bit lost
> on
> > the usefulness of "namespaces"
> > but I am sure that I am missing something.
>
> Imported targets improve the handling of find_package stuff. In the "old
> days",
> the common pattern for using another library as dependency was as follows:
>
> find_package(XXX)
> include_directories( ${XXX_INCLUDE_DIR} )
> add_definitions( ${XXX_DEFINITIONS} )
> target_link_library(YourTarget ${XXX_LIBRARIES} )
>
> Sometimes you don't need the add_definitions part, and sometimes the
> variable
> names are a little bit different. Most of the time you inadvertedly add
> definitions and include directories for other targets, too.
>
>
> With imported targets, you can combine everything that's needed to use a
> library into an imported target, making the above pattern simpler and less
> error-prone:
>
> find_package(XXX)
> target_link_library(YourTarget XXX)
>
> With more complex libraries, you often have different components, and
> that's
> when namespaces come in handy:
>
> find_package(XXX COMPONENTS Base Advanced)
> target_link_library(YourTarget XXX::Base)
> Find_package(YYY COMPONENTS Base)
> target_link_library(YourOtherTarget XXX::Advanced YYY::Base)
>
> Does this answer your question?
>
> Cheers,
>   Johannes
>
>
Yes! Thanks a lot!
I was only getting half of the usage but now it's clear.
It's pretty close to how I was working before but I was hacking stuffs in a
hard to update way.
I'll try this way of doing in one project, it seems to fix at least one
issue I have with my dependencies:
help with uprading them.
Thanks again!

Just a last question: I assume that most find module scripts distributed
with cmake are
not using this feature at the moment, right?
After reading your explaination I looked at documentation for FindBoost and
FindGTest
which are both used in all my projects and they dont seem to provide import
targets.
Are there plans to update the cmake scripts distributed with CMake
or is it just assumed that projects willing to use importing targets will
write them somewhere before using them?



>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150615/76fa6757/attachment.html>


More information about the CMake mailing list