[CMake] Inherited Build Properties: Is this the intent of add_library Interface Libraries?

Brian Davis bitminer at gmail.com
Thu Aug 24 18:17:08 EDT 2017


Is the goal of add_library interface libraries to add the concept of
inherited build properties not dependent on the directory project
inheritance structure of CMake?

This is to say attach any and all cmake properties, flags, etc to a "dummy"
target that can then be used by other target to "inherit" the build config
of the "dummy" target.

Can it be used to get around the inherent folder inheritance mechanism in
CMake?

Does it support all properties, flags, defs?  Say for example:

from: https://cmake.org/pipermail/cmake/2017-August/066122.html

add_library(blah INTERFACE)
set_property(TARGET blah PROPERTY SUFFIX ".mxe")
set_property(TARGET blah PROPERTY CXX_STANDARD 14)
set_property(TARGET blah PROPERTY INSTALL_RPATH "@loader_path/whatever")

without:

CMake Error at CMakeLists.txt:4 (set_property):
INTERFACE_LIBRARY targets may only have whitelisted properties. The
property "SUFFIX" is not allowed.

oh... I know my bad... lets try set_target_properties:

set_target_properties(
    blah
    PROPERTIES
    SUFFIX ".mxe"
    CXX_STANDARD 14
    INSTALL_RPATH "@loader_path/whatever"
)

without say:


CMake Error at CMakeLists.txt:20 (set_target_properties):
INTERFACE_LIBRARY targets may only have whitelisted properties. The
property "SUFFIX" is not allowed.

CMake Error at CMakeLists.txt:20 (set_target_properties):
INTERFACE_LIBRARY targets may only have whitelisted properties. The
property "CXX_STANDARD" is not allowed.

CMake Error at CMakeLists.txt:20 (set_target_properties):
INTERFACE_LIBRARY targets may only have whitelisted properties. The
property "INSTALL_RPATH" is not allowed.

One might want to say create a template (add_project Interface Library) for
all MATLAB mex libraries where say SUFFIX is .mex (above is example from
others) but I would like same functionality for MATLAB Mex plugins then
have plugin target inherit build props via  say:

add_library( mex_interface INTERFACE )
set_target_properties(
    mex_interface
    PROPERTIES
    SUFFIX ".mex64"
    LINK_FLAGS /export:mex_function
)

target_link_libraries(
   targ
   mex_interface).

But what do I get:

CMake Error at CMakeLists.txt:31 (set_target_properties):
INTERFACE_LIBRARY targets may only have whitelisted properties. The
property "SUFFIX" is not allowed.

CMake Error at CMakeLists.txt:31 (set_target_properties):
INTERFACE_LIBRARY targets may only have whitelisted properties. The
property "LINK_FLAGS" is not allowed.


Hmmm I know lets look up whitelisted in CMake doc surely that will tell me
something about INTERFACE whitlisted properties.

https://cmake.org/cmake/help/latest/search.html?q=whitelisted&check_keywords=yes&area=default

Yep... bubkis as expected... in true CMake style.

Since I have the CMake 3.9 source checkout as it is the only way these days
to figure out what CMake does/does not..  I search that for whitelist and
I'll certainly report back on how that goes.


In reading:

https://cmake.org/cmake/help/latest/command/add_library.html?highlight=interface

"An INTERFACE library target does not directly create build output, though
it may have properties set on it and it may be installed, exported and
imported. Typically the INTERFACE_* properties are populated on the
interface target using the commands:"

correction: "it may have WHITELISTED properties that we are not going to
document what they are cuz it's like super secret ... good luck!, but if
you can figure out what they are by trial and error and using eclipse ide
search on the checked out source tree and set on it and it may be
installed, exported and imported."

Huh a library that is just a interface which is not actually a library and
is not a build output... could a worse term "library" been used.  how about
add_interface or add_config or some such not library which I can understand
as an easy hack as libs are consumable by both exe's and libs, but
really... library?  Are command name additions at a premium in CMake?

So I'll ask again what is the intent of add_project interface libraries?

I am getting a pretty good idea what it's not... well i guess better idea
what it isn't once find that whitelist.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170824/faed260b/attachment-0001.html>


More information about the CMake mailing list