2

So far I've seen the INTERFACE library type used to describe header-only libraries, as it does not compile sources and does not produce library artifacts. The IMPORTED library type I've seen less of, but from what I've read it is used to describe precompiled libraries that are already on-disk.

I recently saw some code with the IMPORTED INTERFACE library type, and was confused as to why it was used. What properties does this type have, and what are some typical use-cases of this type?

Jeff L
  • 491
  • 5
  • 14

1 Answers1

2

It's referring to a header-only library whose sources you don't control or are found in another build tree / in the system. Will most commonly be created in a Find module or CMake package config module.

Like other imported targets, and unlike non-imported targets, it doesn't have to be (and indeed cannot be) install()-ed if it appears in the INTERFACE_LINK_LIBRARIES property of an install()ed target transitively; instead, the resulting package will need to find_dependency the package.

Alex Reinking
  • 16,724
  • 5
  • 52
  • 86
  • "a header-only library whose sources you don't control ..." - Usually, "sources" means "source files", which are definitely absent for a header-only library. May be, "headers" would be a better word for that case? "it doesn't have to be `install()`-ed" - And, like any other IMPORTED targets, IMPORTED INTERFACE ones simply **cannot** be installed too. – Tsyvarev Feb 07 '22 at 22:28
  • @Tsyvarev - The "sources" of a header-only library are the header files... "sources" does not equal "translation units" or ".c(pp)" files. Would you say that a header-only library lacks "source code"? Of course not. It's also the nomenclature CMake itself uses when adding header files to interface libraries for the sake of IDE display... it adds them to the `SOURCES` property. – Alex Reinking Feb 08 '22 at 00:17