Skip to content

target_link_libraries: Improve tolerance of unquoted generator expressions

Brad King requested to merge brad.king/cmake:tll-genex-concat into master

Prior to !6805 (merged), the value of INTERFACE_LINK_LIBRARIES was a single string. If an unquoted generator expression passed to target_link_libraries contained ; and became multiple arguments, they would all accumulate as a single ;-separated list in the value of INTERFACE_LINK_LIBRARIES. Since that commit, each argument to target_link_libraries is placed in INTERFACE_LINK_LIBRARIES as a separate entry, as has long been the case for LINK_LIBRARIES. That behavior change broke projects that were accidentally relying on accumulation in INTERFACE_LINK_LIBRARIES to produce complete generator expressions containing ;.

Teach target_link_libraries to accumulate consecutive non-keyword arguments into a single entry before placing them in LINK_LIBRARIES or INTERFACE_LINK_LIBRARIES. For example, treat a b c as if they were written as "a;b;c". This restores the previously accidental support for unquoted generator expressions in INTERFACE_LINK_LIBRARIES, and also enables it for LINK_LIBRARIES.

For now, do not drop the target_link_libraries documentation that recommends quoting generator expressions. Quoting is still important to populate LINK_LIBRARIES in CMake 3.22 and below, and is also good practice to keep generator expressions whole.

Fixes: #23203 (closed)
Backport: release

Merge request reports