[Config-file Package] The best practice of finding package dependencies?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Config-file Package] The best practice of finding package dependencies?

Konstantin Podsvirov
Hello community!

I want to give a little discussion :)

If I export a package containing several targets.
And these target are publicly linked to the targets imported from another package.
Where is the best place to look for package dependencies?

I assume the following options:
- In the Config-file of the package itself;
- The user himself must find them in his project.

It seems to me that to force the user to look for the dependencies of the package, which he himself seeks there is bad tone, but also to impose on the user, then how I myself found these dependencies in Config-file may not appeal to everyone.

Perhaps there should be some option for setting the behavior of the `find_package` command in the part of finding package dependencies? Or she already is, but I have not yet studied it.

--
Regards,
Konstantin Podsvirov
--

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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Config-file Package] The best practice of finding package dependencies?

CMake mailing list

> On Jun 20, 2017, at 10:46 PM, Konstantin Podsvirov <[hidden email]> wrote:
>
> Hello community!
>
> I want to give a little discussion :)
>
> If I export a package containing several targets.
> And these target are publicly linked to the targets imported from another package.
> Where is the best place to look for package dependencies?
>
> I assume the following options:
> - In the Config-file of the package itself;

I believe this is the best practice, and it is why the `find_dependency` macro exists.

> - The user himself must find them in his project.
>
> It seems to me that to force the user to look for the dependencies of the package, which he himself seeks there is bad tone, but also to impose on the user, then how I myself found these dependencies in Config-file may not appeal to everyone.
>
> Perhaps there should be some option for setting the behavior of the `find_package` command in the part of finding package dependencies? Or she already is, but I have not yet studied it.

The user can either use `<package>_DIR` to tell cmake exactly where the package is, or they can call `find_package(…)` beforehand. However, if the user wants something completely different then they would either need to provide a Find module or override `find_package`.

For example, this is common for projects that build their dependencies in the same project:

set(as_subproject Foo)
macro(find_package)
  if(NOT "${ARG0}" IN_LIST as_subproject)
    _find_package(${ARGV})
  endif()
endmacro()
add_subdirectory(Foo)
add_subdirectory(App)

This makes `find_package(Foo)` do nothing since the target `Foo::Foo` would be part of the project.


--

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
Loading...