[CMake] Calling find_package(self) for in-project builds

Walter Gray chrysalisx at gmail.com
Thu Jun 2 21:06:51 EDT 2016


I'm currently working on protobuf-3.0.0's cmake scripts, and I've hit a bit
of a chicken and egg problem.

There is an examples directory containing a CMakeLists.txt which we would
like to work as both a standalone examples directory and include as a sub
directory of the full build. For obvious reasons, the CMakeLists.txt file
contains a call to find_package(protobuf).

I can call find_package(protobuf HINTS ${CMAKE_BINARY_DIR}) outside of the
examples/CMakeLists.txt file to ensure that we've already found the correct
version, but the problem is that the protobuf-config.cmake file includes
the export-generated file protobuf-targets.cmake, as well as implementing
some custom functions that we want to show off as part of the examples.

The obvious solution to me was to use the export command to generate
protobuf-targets.cmake, but there are 2 problems. First, export(EXPORT)
doesn't create a file until generation time, but I can get around this
using export(TARGETS). The second is that, reading CMP0024, this appears to
be not garunted behavior, and actively discouraged.

What would be the suggested way to handle this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160603/d8f17806/attachment.html>


More information about the CMake mailing list