CMP0003.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. CMP0003
  2. -------
  3. Libraries linked via full path no longer produce linker search paths.
  4. This policy affects how libraries whose full paths are NOT known are
  5. found at link time, but was created due to a change in how CMake deals
  6. with libraries whose full paths are known. Consider the code
  7. ::
  8. target_link_libraries(myexe /path/to/libA.so)
  9. CMake 2.4 and below implemented linking to libraries whose full paths
  10. are known by splitting them on the link line into separate components
  11. consisting of the linker search path and the library name. The
  12. example code might have produced something like
  13. ::
  14. ... -L/path/to -lA ...
  15. in order to link to library A. An analysis was performed to order
  16. multiple link directories such that the linker would find library A in
  17. the desired location, but there are cases in which this does not work.
  18. CMake versions 2.6 and above use the more reliable approach of passing
  19. the full path to libraries directly to the linker in most cases. The
  20. example code now produces something like
  21. ::
  22. ... /path/to/libA.so ....
  23. Unfortunately this change can break code like
  24. ::
  25. target_link_libraries(myexe /path/to/libA.so B)
  26. where "B" is meant to find "/path/to/libB.so". This code is wrong
  27. because the user is asking the linker to find library B but has not
  28. provided a linker search path (which may be added with the
  29. link_directories command). However, with the old linking
  30. implementation the code would work accidentally because the linker
  31. search path added for library A allowed library B to be found.
  32. In order to support projects depending on linker search paths added by
  33. linking to libraries with known full paths, the OLD behavior for this
  34. policy will add the linker search paths even though they are not
  35. needed for their own libraries. When this policy is set to OLD, CMake
  36. will produce a link line such as
  37. ::
  38. ... -L/path/to /path/to/libA.so -lB ...
  39. which will allow library B to be found as it was previously. When
  40. this policy is set to NEW, CMake will produce a link line such as
  41. ::
  42. ... /path/to/libA.so -lB ...
  43. which more accurately matches what the project specified.
  44. The setting for this policy used when generating the link line is that
  45. in effect when the target is created by an add_executable or
  46. add_library command. For the example described above, the code
  47. ::
  48. cmake_policy(SET CMP0003 OLD) # or cmake_policy(VERSION 2.4)
  49. add_executable(myexe myexe.c)
  50. target_link_libraries(myexe /path/to/libA.so B)
  51. will work and suppress the warning for this policy. It may also be
  52. updated to work with the corrected linking approach:
  53. ::
  54. cmake_policy(SET CMP0003 NEW) # or cmake_policy(VERSION 2.6)
  55. link_directories(/path/to) # needed to find library B
  56. add_executable(myexe myexe.c)
  57. target_link_libraries(myexe /path/to/libA.so B)
  58. Even better, library B may be specified with a full path:
  59. ::
  60. add_executable(myexe myexe.c)
  61. target_link_libraries(myexe /path/to/libA.so /path/to/libB.so)
  62. When all items on the link line have known paths CMake does not check
  63. this policy so it has no effect.
  64. Note that the warning for this policy will be issued for at most one
  65. target. This avoids flooding users with messages for every target
  66. when setting the policy once will probably fix all targets.
  67. This policy was introduced in CMake version 2.6.0. CMake version
  68. |release| warns when the policy is not set and uses OLD behavior. Use
  69. the cmake_policy command to set it to OLD or NEW explicitly.
  70. .. include:: DEPRECATED.txt