CMake import interface link

CMake can add interface linking to imported libraries. For example, a imported library obtained by find_package() or otherwise. Normally, this would work like the following example to say link “stdc++fs” to example imported library “imported::lib” for GCC older than 9.1.

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1.0)
  target_link_libraries(imported::lib INTERFACE stdc++fs)
endif()

Function target_link_libraries() should work, but does not always work for some projects with a configure time error. To workaround this issue if it arises, set target property INTERFACE_LINK_LIBRARIES directly like:

set_property(TARGET imported::lib PROPERTY INTERFACE_LINK_LIBRARIES stdc++fs)