CMP0060.rst 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. CMP0060
  2. -------
  3. Link libraries by full path even in implicit directories.
  4. Policy :policy:`CMP0003` was introduced with the intention of always
  5. linking library files by full path when a full path is given to the
  6. :command:`target_link_libraries` command. However, on some platforms
  7. (e.g. HP-UX) the compiler front-end adds alternative library search paths
  8. for the current architecture (e.g. ``/usr/lib/<arch>`` has alternatives
  9. to libraries in ``/usr/lib`` for the current architecture).
  10. On such platforms the :command:`find_library` may find a library such as
  11. ``/usr/lib/libfoo.so`` that does not belong to the current architecture.
  12. Prior to policy :policy:`CMP0003` projects would still build in such
  13. cases because the incorrect library path would be converted to ``-lfoo``
  14. on the link line and the linker would find the proper library in the
  15. arch-specific search path provided by the compiler front-end implicitly.
  16. At the time we chose to remain compatible with such projects by always
  17. converting library files found in implicit link directories to ``-lfoo``
  18. flags to ask the linker to search for them. This approach allowed existing
  19. projects to continue to build while still linking to libraries outside
  20. implicit link directories via full path (such as those in the build tree).
  21. CMake does allow projects to override this behavior by using an
  22. :ref:`IMPORTED library target <Imported Targets>` with its
  23. :prop_tgt:`IMPORTED_LOCATION` property set to the desired full path to
  24. a library file. In fact, many :ref:`Find Modules` are learning to provide
  25. :ref:`Imported Targets` instead of just the traditional ``Foo_LIBRARIES``
  26. variable listing library files. However, this makes the link line
  27. generated for a library found by a Find Module depend on whether it
  28. is linked through an imported target or not, which is inconsistent.
  29. Furthermore, this behavior has been a source of confusion because the
  30. generated link line for a library file depends on its location. It is
  31. also problematic for projects trying to link statically because flags
  32. like ``-Wl,-Bstatic -lfoo -Wl,-Bdynamic`` may be used to help the linker
  33. select ``libfoo.a`` instead of ``libfoo.so`` but then leak dynamic linking
  34. to following libraries. (See the :prop_tgt:`LINK_SEARCH_END_STATIC`
  35. target property for a solution typically used for that problem.)
  36. When the special case for libraries in implicit link directories was first
  37. introduced the list of implicit link directories was simply hard-coded
  38. (e.g. ``/lib``, ``/usr/lib``, and a few others). Since that time, CMake
  39. has learned to detect the implicit link directories used by the compiler
  40. front-end. If necessary, the :command:`find_library` command could be
  41. taught to use this information to help find libraries of the proper
  42. architecture.
  43. For these reasons, CMake 3.3 and above prefer to drop the special case
  44. and link libraries by full path even when they are in implicit link
  45. directories. Policy ``CMP0060`` provides compatibility for existing
  46. projects.
  47. The OLD behavior for this policy is to ask the linker to search for
  48. libraries whose full paths are known to be in implicit link directories.
  49. The NEW behavior for this policy is to link libraries by full path even
  50. if they are in implicit link directories.
  51. This policy was introduced in CMake version 3.3. Unlike most policies,
  52. CMake version |release| does *not* warn by default when this policy
  53. is not set and simply uses OLD behavior. See documentation of the
  54. :variable:`CMAKE_POLICY_WARNING_CMP0060 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
  55. variable to control the warning.
  56. .. include:: DEPRECATED.txt