find_library.rst 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. find_library
  2. ------------
  3. .. |FIND_XXX| replace:: find_library
  4. .. |NAMES| replace:: NAMES name1 [name2 ...] [NAMES_PER_DIR]
  5. .. |SEARCH_XXX| replace:: library
  6. .. |SEARCH_XXX_DESC| replace:: library
  7. .. |prefix_XXX_SUBDIR| replace:: ``<prefix>/lib``
  8. .. |entry_XXX_SUBDIR| replace:: ``<entry>/lib``
  9. .. |FIND_XXX_REGISTRY_VIEW_DEFAULT| replace:: ``TARGET``
  10. .. |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX| replace::
  11. ``<prefix>/lib/<arch>`` if :variable:`CMAKE_LIBRARY_ARCHITECTURE` is set,
  12. and |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX_SUBDIR|
  13. .. |CMAKE_PREFIX_PATH_XXX| replace::
  14. ``<prefix>/lib/<arch>`` if :variable:`CMAKE_LIBRARY_ARCHITECTURE` is set,
  15. and |CMAKE_PREFIX_PATH_XXX_SUBDIR|
  16. .. |CMAKE_XXX_PATH| replace:: :variable:`CMAKE_LIBRARY_PATH`
  17. .. |CMAKE_XXX_MAC_PATH| replace:: :variable:`CMAKE_FRAMEWORK_PATH`
  18. .. |ENV_CMAKE_PREFIX_PATH_XXX| replace::
  19. ``<prefix>/lib/<arch>`` if :variable:`CMAKE_LIBRARY_ARCHITECTURE` is set,
  20. and |ENV_CMAKE_PREFIX_PATH_XXX_SUBDIR|
  21. .. |ENV_CMAKE_XXX_PATH| replace:: :envvar:`CMAKE_LIBRARY_PATH`
  22. .. |ENV_CMAKE_XXX_MAC_PATH| replace:: :envvar:`CMAKE_FRAMEWORK_PATH`
  23. .. |SYSTEM_ENVIRONMENT_PATH_XXX| replace:: The directories in ``LIB``
  24. and ``PATH``.
  25. .. |SYSTEM_ENVIRONMENT_PATH_WINDOWS_XXX| replace::
  26. On Windows hosts, CMake 3.3 through 3.27 searched additional paths:
  27. ``<prefix>/lib/<arch>`` if :variable:`CMAKE_LIBRARY_ARCHITECTURE`
  28. is set, and |SYSTEM_ENVIRONMENT_PREFIX_PATH_XXX_SUBDIR|.
  29. This behavior was removed by CMake 3.28.
  30. .. |CMAKE_SYSTEM_PREFIX_PATH_XXX| replace::
  31. ``<prefix>/lib/<arch>`` if :variable:`CMAKE_LIBRARY_ARCHITECTURE` is set,
  32. and |CMAKE_SYSTEM_PREFIX_PATH_XXX_SUBDIR|
  33. .. |CMAKE_SYSTEM_XXX_PATH| replace::
  34. :variable:`CMAKE_SYSTEM_LIBRARY_PATH`
  35. .. |CMAKE_SYSTEM_XXX_MAC_PATH| replace::
  36. :variable:`CMAKE_SYSTEM_FRAMEWORK_PATH`
  37. .. |CMAKE_FIND_ROOT_PATH_MODE_XXX| replace::
  38. :variable:`CMAKE_FIND_ROOT_PATH_MODE_LIBRARY`
  39. .. include:: FIND_XXX.txt
  40. When more than one value is given to the ``NAMES`` option this command by
  41. default will consider one name at a time and search every directory
  42. for it. The ``NAMES_PER_DIR`` option tells this command to consider one
  43. directory at a time and search for all names in it.
  44. Each library name given to the ``NAMES`` option is first considered
  45. as is, if it contains a library suffix, and then considered with
  46. platform-specific prefixes (e.g. ``lib``) and suffixes (e.g. ``.so``),
  47. as defined by the variables :variable:`CMAKE_FIND_LIBRARY_PREFIXES` and
  48. :variable:`CMAKE_FIND_LIBRARY_SUFFIXES`. Therefore one
  49. may specify library file names such as ``libfoo.a`` directly.
  50. This can be used to locate static libraries on UNIX-like systems.
  51. If the library found is a framework, then ``<VAR>`` will be set to the full
  52. path to the framework ``<fullPath>/A.framework``. When a full path to a
  53. framework is used as a library, CMake will use a ``-framework A``, and a
  54. ``-F<fullPath>`` to link the framework to the target.
  55. .. versionadded:: 3.28
  56. The library found can now be a ``.xcframework`` folder.
  57. If the :variable:`CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX` variable is set all
  58. search paths will be tested as normal, with the suffix appended, and with
  59. all matches of ``lib/`` replaced with
  60. ``lib${CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX}/``. This variable overrides
  61. the :prop_gbl:`FIND_LIBRARY_USE_LIB32_PATHS`,
  62. :prop_gbl:`FIND_LIBRARY_USE_LIBX32_PATHS`,
  63. and :prop_gbl:`FIND_LIBRARY_USE_LIB64_PATHS` global properties.
  64. If the :prop_gbl:`FIND_LIBRARY_USE_LIB32_PATHS` global property is set
  65. all search paths will be tested as normal, with ``32/`` appended, and
  66. with all matches of ``lib/`` replaced with ``lib32/``. This property is
  67. automatically set for the platforms that are known to need it if at
  68. least one of the languages supported by the :command:`project` command
  69. is enabled.
  70. If the :prop_gbl:`FIND_LIBRARY_USE_LIBX32_PATHS` global property is set
  71. all search paths will be tested as normal, with ``x32/`` appended, and
  72. with all matches of ``lib/`` replaced with ``libx32/``. This property is
  73. automatically set for the platforms that are known to need it if at
  74. least one of the languages supported by the :command:`project` command
  75. is enabled.
  76. If the :prop_gbl:`FIND_LIBRARY_USE_LIB64_PATHS` global property is set
  77. all search paths will be tested as normal, with ``64/`` appended, and
  78. with all matches of ``lib/`` replaced with ``lib64/``. This property is
  79. automatically set for the platforms that are known to need it if at
  80. least one of the languages supported by the :command:`project` command
  81. is enabled.