simple find_package example

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

simple find_package example

Randy Heiland-2
Hi,

I'd like to figure out how to modify the simple "hello" demo (https://cmake.org/examples/) so that the Hello project is a library with an accompanying FindHello.cmake and then the Demo project uses that information and "find_package" to discover/use it.

Hopefully that makes sense. Basically, I'm looking for a simple tutorial on how I can make my library easily accessible to a CMake project. Fwiw, my library is not (currently) built with CMake.

thanks for suggestions,
Randy

--

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

Re: simple find_package example

Alexander Neundorf
On 2018 M08 2, Thu 10:01:39 CEST Randy Heiland wrote:
> Hi,
>
> I'd like to figure out how to modify the simple "hello" demo (
> https://cmake.org/examples/) so that the Hello project is a library with an
> accompanying FindHello.cmake and then the Demo project uses that
> information and "find_package" to discover/use it.
>
> Hopefully that makes sense. Basically, I'm looking for a simple tutorial on
> how I can make my library easily accessible to a CMake project.

for that, you don't want a FindHello.cmake (which would typically be shipped
either by cmake or by the consuming application), instead you want to generate
and install a HelloConfig.cmake file.

Alex

--

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

Re: simple find_package example

Randy Heiland-2
Hmm, well if that's the case, how does one generate the HelloConfig.cmake file? 

Although, for my particular situation, my question about wanting to generate a "Find" file still remains, I think. I have a library which is, potentially, useful to several projects. I assume there's some sort of "Find" template for any such lib, i.e., a project needs to be able to locate a lib (static or dynamic) and headers, cross-platform.

thanks, Randy

On Mon, Aug 6, 2018 at 4:09 PM, Alexander Neundorf <[hidden email]> wrote:
On 2018 M08 2, Thu 10:01:39 CEST Randy Heiland wrote:
> Hi,
>
> I'd like to figure out how to modify the simple "hello" demo (
> https://cmake.org/examples/) so that the Hello project is a library with an
> accompanying FindHello.cmake and then the Demo project uses that
> information and "find_package" to discover/use it.
>
> Hopefully that makes sense. Basically, I'm looking for a simple tutorial on
> how I can make my library easily accessible to a CMake project.

for that, you don't want a FindHello.cmake (which would typically be shipped
either by cmake or by the consuming application), instead you want to generate
and install a HelloConfig.cmake file.

Alex



--

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

Re: simple find_package example

Johannes Zarl-Zierl-2
Am Dienstag, 7. August 2018, 14:48:26 CEST schrieb Randy Heiland:
> Hmm, well if that's the case, how does one generate the HelloConfig.cmake
> file?

The official documentation is here:
https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html

> Although, for my particular situation, my question about wanting to
> generate a "Find" file still remains, I think. I have a library which is,
> potentially, useful to several projects. I assume there's some sort of
> "Find" template for any such lib, i.e., a project needs to be able to
> locate a lib (static or dynamic) and headers, cross-platform.

Im almost positively sure that you don't want a FindXYZ.cmake, but a
XYZConfig.cmake file instead. These are the main differences between Find-
module packages and config-file packages:

Find-Module packages:
- are written and maintained independently of the "consumed" project
  (usually because the project does not support CMake)
- are usually shipped by the consuming project
- are hard to get right (they have to deal with strange installations, or old
versions of the software, etc.)

Config-file packages:
- are generated by the "consumed" project
- are shipped by the consumed project
- have tooling to ensure correctness


For the consuming project, there's no visible difference between both (you
call "find_package(XYZ)" and cmake uses whatever it finds. In principle, it's
even possible to use both together (note: please don't).

That said, the official documentation can be a bit overwhelming at first.
You probably can write some kind of cmake-2.6-style Find-Module package in
less time, but the time to do it "right" is worth your effort.

Just start by reading the documentation and don't hesitate to ask when you hit
a problem…

Cheers,
  Johannes



--

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