cmakecmake-language

What is an INTERFACE IMPORTED library in CMake and what are its uses?


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?


Solution

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