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

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

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

Brian Davis-2

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.
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.




--

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:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Inherited Build Properties: Is this the intent of add_library Interface Libraries?

Brian Davis-2

The answer to what parameters can be specified the "whitelist" as it is refereed to is documented (thanks to Raul's help):

https://cmake.org/cmake/help/v3.9/command/add_library.html?highlight=interface_#interface-libraries

with these key bits:

"Details about the imported library are specified by setting properties whose names begin in IMPORTED_ and INTERFACE_. The most important such property is IMPORTED_LOCATION (and its per-configuration variant IMPORTED_LOCATION_<CONFIG>) which specifies the location of the main library file on disk. See documentation of the IMPORTED_* and INTERFACE_* properties for more information."

Then searching https://cmake.org/cmake/help/v3.9/manual/cmake-properties.7.html?highlight=property

grep'in for IMPORTED_ or INTERFACE_ yields the full white list.  What I have found to be:

    IMPORTED_CONFIGURATIONS
    IMPORTED_IMPLIB_<CONFIG>
    IMPORTED_IMPLIB
    IMPORTED_LIBNAME_<CONFIG>
    IMPORTED_LIBNAME
    IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>
    IMPORTED_LINK_DEPENDENT_LIBRARIES
    IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>
    IMPORTED_LINK_INTERFACE_LANGUAGES
    IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>
    IMPORTED_LINK_INTERFACE_LIBRARIES
    IMPORTED_LINK_INTERFACE_MULTIPLICITY_<CONFIG>
    IMPORTED_LINK_INTERFACE_MULTIPLICITY
    IMPORTED_LOCATION_<CONFIG>
    IMPORTED_LOCATION
    IMPORTED_NO_SONAME_<CONFIG>
    IMPORTED_NO_SONAME
    IMPORTED_OBJECTS_<CONFIG>
    IMPORTED_OBJECTS
    IMPORTED
    IMPORTED_SONAME_<CONFIG>
    IMPORTED_SONAME

    INTERFACE_AUTOUIC_OPTIONS
    INTERFACE_COMPILE_DEFINITIONS
    INTERFACE_COMPILE_FEATURES
    INTERFACE_COMPILE_OPTIONS
    INTERFACE_INCLUDE_DIRECTORIES
    INTERFACE_LINK_LIBRARIES
    INTERFACE_POSITION_INDEPENDENT_CODE
    INTERFACE_SOURCES
    INTERFACE_SYSTEM_INCLUDE_DIRECTORIES


Read -> as maps to and X as nothing, zip, zilch, nadahey, bubkis, etc.  So:

SUFFIX to -> X
INSTALL_RPATH -> X
LINK_FLAGS -> X

I am sure this is useful for some use case I an quite baffled as to what it is and I have request clarification from devs at:

https://gitlab.kitware.com/cmake/cmake/issues/17216

I clearly don't get something here.  I am interested to figure out what it is designed for.

I have also asked that the error:

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

provide better direction to user.
Possibly:

e << "INTERFACE_LIBRARY targets may only have properties beginning with INTERFACE_* or IMPORTED_*.  See cmake-properties for more information."
"The property \""
<< prop << "\" is not allowed.";


--

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:
http://public.kitware.com/mailman/listinfo/cmake