[cmake-developers] Linking Apple frameworks

Brad King brad.king at kitware.com
Mon Aug 7 09:34:26 EDT 2017


On 08/05/2017 07:58 PM, Craig Scott wrote:
>     target_link_libraries(foo PRIVATE "-framework AppKit")
> 
> Strangely, with the library quoted as above, the embedded space
> is not escaped, leading to the (desirable but surprising) result

Link flags starting in `-` are treated as a raw part of the command
line.  That's how it evolved historically.

> As extra context, a correct final linker command line can also be achieved like this:
> 
>     find_library(APPKIT_LIB AppKit)
>     target_link_libraries(foo PRIVATE ${APPKIT_LIB})
> 
> In this case, while APPKIT_LIB contains a full absolute path to the
> framework, CMake manages to recognise it as a framework and shortens
> the linker flags to just -framework AppKit.

There is special case logic for this, but IMO it was a mistake.
Ideally when find_library finds a framework library it should
return the absolute path to the library file within the framework,
e.g. `/path/to/foo.framework/foo`.  Then no special logic would
be needed to recognize it and the library file can be passed
directly on link lines.  All the Modules/Find*.cmake modules
that provide imported targets have special logic to transform
the find_library result in this way.  Perhaps we should fix this
with a policy.

Also the points raised in Eric Wing's response are valid concerns.

-Brad


More information about the cmake-developers mailing list