[CMake] Trying to get build info for a target

Robert Dailey rcdailey at gmail.com
Sat Dec 31 18:03:35 EST 2011


Storing the source directory will require the exact idea you had mentioned.
Use an internal cache variable or, even better, a target property. This is
how I have done it. Each target that I create  specifies a list of its
include directories (where other targets that depend on it can find its
header files, and will append this directory to its list of searchable
include directories).

For defines, and I think cflags, you can use get_target_property().

For libraries, I've also maintained a list in a target property. This is
how you build recursive dependencies. CMake will automatically set up build
order based on your dependencies, however you cannot query these libraries
without maintaining them yourself. Also, another benefit to maintaining
dependencies in target properties is that you can throw an error message if
a target depends on another target that does not yet exist (used to ensure
that targets are defined in the proper order in the cmake scripts).

Hope that helps.

---------
Robert Dailey


On Sat, Dec 31, 2011 at 4:45 PM, Gary Kramlich <grim at reaperworld.com> wrote:

> I'm working on a module that needs to interrogate a target, and get
> it's source directory, defines, cflags, and libraries that it links to.
>
> So far, all I've been able to do is get the sources, which are relative
> to the source directory of the target.  I have not been able to get the
> source directory of the target, so I'm essentially stuck.
>
> I've tried using the LOCATION property on the target, but alas that only
> gives me the output location.
>
> I've tried to get the absolute path of a source file using
> get_filename_component for the ABSOLUTE property, but it just tacks on
> the source filename to the current working directory, which obviously
> doesn't work.
>
> There is one idea I've had to fix this, but it's by no means ideal, and
> that's to have each target set a property named SOURCE_LOCATION or
> something, to CMAKE_CURRENT_SOURCE_DIR but that seems like a huge
> inconvenience for potential users.
>
> Any thoughts?
>
> --
> Gary Kramlich <grim at reaperworld.com>
>
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111231/6e674dff/attachment.htm>


More information about the CMake mailing list