[cmake-developers] Mixing generator expressions and debug|optimized|general keywords in target_link_libraries()

Brad King brad.king at kitware.com
Tue Sep 2 10:12:21 EDT 2014


On 08/29/2014 05:26 AM, Nils Gladitz wrote:
> I tried wrapping the libraries returned by FindBoost.cmake in 
> $<BUILD_INTERFACE> in a target_link_libraries() call and noticed that 
> this breaks because of the debug/optimized keywords that the find module 
> inserts.
> 
> Specifically it results in CMake trying to link e.g. "optimized.lib".
> 
> Should/could these keywords be handled at generation time (after 
> generator expressions expansion)?

These keywords are meaningful to target_link_libraries and nothing
else, just like the PRIVATE/PUBLIC/INTERFACE keywords.  It is the
responsibility of that command to handle them.  One can put a genex
in the value after the keyword: "optimized $<...>", but otherwise
they are not really meant to mix.

The use of generator expressions and imported targets is supposed
to supersede use of the old keywords.  There was recent work posted
on this list to add imported targets to the FindBoost results.

> There don't seem to be generator expressions that correspond to the 
> debug/optimized keywords exactly. Can/should there be?

Steve K and I discussed this once.  Since DEBUG_CONFIGURATIONS can be
set differently in exporting and importing projects so there is no
global meaning across all targets.  See the
cmTarget::GetDebugGeneratorExpressions method:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmTarget.cxx;hb=v3.0.1#l908

It constructs a $<OR:...> expression of $<CONFIG:...> expressions
for each entry in DEBUG_CONFIGURATIONS.  This is how
target_link_libraries transforms debug/optimized keywords when
constructing the INTERFACE_LINK_LIBRARIES value.

-Brad



More information about the cmake-developers mailing list