On Sun, Mar 24, 2019 at 1:43 PM Jason Beach <jason.m.be...@gmail.com> wrote:
> Hi, > As I've been learning CMake, it seems the best practice for a library is > for it to export the targets it creates. There is also the relatively new > command FetchContent. It seems that at least in part the FetchContent > command obviates the need for exporting targets. > > I can see that for larger more permanent libraries exporting targets is > still preferred so the library can be installed once and used by multiple > projects on a developers workstation without having to install it on each > project. > > At work we're a bunch of research engineers that happen to write a lot of > software-- exporting targets still seems cumbersome and it seems not > exporting targets and then just have users use FetchContent to pull in a > library is not a bad idea. > > Are there other reasons /advantages of exporting targets? > Exporting targets is a way to allow other projects to easily consume yours via find_package(). If you are 100% confident that no-one is ever going to use your project that way and will only ever build it from source directly (whether that be through FetchContent or some other method), then there's no benefit to exporting targets. As soon as there's a possibility that someone might want to build against an installed version of your project though, having the exported targets available makes for a significantly more convenient and more robust experience. It really comes down to whether in your case you can truly say no-one will ever want to use find_package() to bring your projects into theirs. -- 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/>
-- 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: https://cmake.org/mailman/listinfo/cmake