I'm exploring the behaviour of target_link_libraries() where the library to be linked is an Apple framework. As part of this, I noticed that the following does not work:
target_link_libraries(foo PRIVATE -framework AppKit) This fails because the link command ends up with -framework -lAppKit instead of -framework AppKit. Maybe that's expected, but then the following DOES work: 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 -framework AppKit in the linker command line (i.e. the space isn't escaped and the two words are not quoted). *Which of these is the correct way (if either) and are both behaving as expected?* 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. This is mentioned in the find_library() docs: If the library found is a framework, then <VAR> will be set to the full > path to the framework <fullPath>/A.framework. When a full path to a > framework is used as a library, CMake will use a -framework A, and a > -F<fullPath> to link the framework to the target. > So it is clear why the find_library() approach works, but the behaviour of directly specifying the framework without find_library() seems somewhat surprising. -- Craig Scott Melbourne, Australia https://crascit.com
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers