CheckLinkerFlag.cmake 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. CheckLinkerFlag
  5. ---------------
  6. .. versionadded:: 3.18
  7. Check whether the compiler supports a given link flag.
  8. .. command:: check_linker_flag
  9. .. code-block:: cmake
  10. check_linker_flag(<lang> <flag> <var>)
  11. Check that the link ``<flag>`` is accepted by the ``<lang>`` compiler without
  12. a diagnostic. Stores the result in an internal cache entry named ``<var>``.
  13. This command temporarily sets the ``CMAKE_REQUIRED_LINK_OPTIONS`` variable
  14. and calls the :command:`check_source_compiles` command from the
  15. :module:`CheckSourceCompiles` module. See that module's documentation
  16. for a listing of variables that can otherwise modify the build.
  17. The underlying implementation relies on the :prop_tgt:`LINK_OPTIONS` property
  18. to check the specified flag. The ``LINKER:`` prefix, as described in the
  19. :command:`target_link_options` command, can be used as well.
  20. A positive result from this check indicates only that the compiler did not
  21. issue a diagnostic message when given the link flag. Whether the flag has any
  22. effect or even a specific one is beyond the scope of this module.
  23. .. note::
  24. Since the :command:`try_compile` command forwards flags from variables
  25. like :variable:`CMAKE_<LANG>_FLAGS`, unknown flags in such variables may
  26. cause a false negative for this check.
  27. #]=======================================================================]
  28. include_guard(GLOBAL)
  29. include(Internal/CheckLinkerFlag)
  30. function(CHECK_LINKER_FLAG _lang _flag _var)
  31. cmake_check_linker_flag(${_lang} "${_flag}" ${_var})
  32. endfunction()