find_library.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 a library file name and then considered with platform-specific
  46. prefixes (e.g. ``lib``) and suffixes (e.g. ``.so``). Therefore one
  47. may specify library file names such as ``libfoo.a`` directly.
  48. This can be used to locate static libraries on UNIX-like systems.
  49. If the library found is a framework, then ``<VAR>`` will be set to the full
  50. path to the framework ``<fullPath>/A.framework``. When a full path to a
  51. framework is used as a library, CMake will use a ``-framework A``, and a
  52. ``-F<fullPath>`` to link the framework to the target.
  53. .. versionadded:: 3.28
  54. The library found can now be a ``.xcframework`` folder.
  55. If the :variable:`CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX` variable is set all
  56. search paths will be tested as normal, with the suffix appended, and with
  57. all matches of ``lib/`` replaced with
  58. ``lib${CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX}/``. This variable overrides
  59. the :prop_gbl:`FIND_LIBRARY_USE_LIB32_PATHS`,
  60. :prop_gbl:`FIND_LIBRARY_USE_LIBX32_PATHS`,
  61. and :prop_gbl:`FIND_LIBRARY_USE_LIB64_PATHS` global properties.
  62. If the :prop_gbl:`FIND_LIBRARY_USE_LIB32_PATHS` global property is set
  63. all search paths will be tested as normal, with ``32/`` appended, and
  64. with all matches of ``lib/`` replaced with ``lib32/``. This property is
  65. automatically set for the platforms that are known to need it if at
  66. least one of the languages supported by the :command:`project` command
  67. is enabled.
  68. If the :prop_gbl:`FIND_LIBRARY_USE_LIBX32_PATHS` global property is set
  69. all search paths will be tested as normal, with ``x32/`` appended, and
  70. with all matches of ``lib/`` replaced with ``libx32/``. This property is
  71. automatically set for the platforms that are known to need it if at
  72. least one of the languages supported by the :command:`project` command
  73. is enabled.
  74. If the :prop_gbl:`FIND_LIBRARY_USE_LIB64_PATHS` global property is set
  75. all search paths will be tested as normal, with ``64/`` appended, and
  76. with all matches of ``lib/`` replaced with ``lib64/``. This property is
  77. automatically set for the platforms that are known to need it if at
  78. least one of the languages supported by the :command:`project` command
  79. is enabled.