[cmake-developers] Target usage requirements and conventions
Alexander Neundorf
neundorf at kde.org
Tue May 1 06:12:47 EDT 2012
On Sunday 29 April 2012, Stephen Kelly wrote:
> Hi there,
>
> The topic of 'target usage requirements' has come up several times. It's
> something I'd like to work further towards in CMake 2.8.9.
>
> I have created a wiki page on the KDE wiki (there for my convenience
> mostly) so that we can discuss the design, implementation and
> implications.
>
> http://community.kde.org/Frameworks/Epics/CMake_target_usage_requirements
>
> Thanks for any comments,
Some comments:
You propose target_use_package(Foo Bar) to state that the target Foo should
use the include dirs and libraries from Bar. I like the idea of having a
separate command for that.
I do not like the idea that target_use_package() should automatically do a
find_package() for several reasons.
* find_package() has many options, in the end they would all have to be
present there too
* find_package() is an important part of the CMakeLists.txt, it should not be
hidden
* wouldn't this fall back to a find_package() call with its associated error
messages at cmake-time for every typo in the package name ?
Looking at other cmake commands, many of them now have two modes, an old one,
where simply the options are listed without separating keywords:
find_library(FOO_LIBRARY foo /opt/foo /usr/foo/lib)
and a new, more powerful one with additional keywords:
find_library(FOO_LIBRARY NAMES foo PATHS /opt/foo /usr/foo/lib)
When adding a new command, we should start with the keyword-based variant, to
avoid having two signatures in the future.
This also makes the code more explicit about what it does, less guessing
involved for readers:
target_use_package(Foo IMPORTED_TARGETS Bar Blub)
or
target_use_package(Foo VIA_PREFIX Bar_Bat )
or
target_use_package(Foo PACKAGE Bar)
Doing it this way would also solve the problem that your prefix-based example:
target_use_package(Foo ${Bar_Bat_LIBRARIES})
"... Otherwise, the variables with the appropriate naming conventions (eg
Bar_Bat_LIBRARIES Bar_Bat_INCLUDE_DIRS) are used."
the target_use_package() implementation would get to see that value of
${Bar_Bat_LIBRARIES}, which might be "/usr/lib/libbat.so;/usr/lib/libbar.so",
and wouldn't be able to find out about prefixes anymore.
Alex
More information about the cmake-developers
mailing list