CMP0060.rst 3.5 KB

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