CMP0125.rst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. CMP0125
  2. -------
  3. .. versionadded:: 3.21
  4. The :command:`find_file`, :command:`find_path`, :command:`find_library` and
  5. :command:`find_program` commands cache their result in the variable specified
  6. by their first argument. Prior to CMake 3.21, if a cache variable of that
  7. name already existed before the call but the cache variable had no type, any
  8. non-cache variable of the same name would be discarded and the cache variable
  9. was always used (see also :policy:`CMP0126` for a different but similar
  10. behavior). This contradicts the convention that a non-cache variable should
  11. take precedence over a cache variable of the same name. Such a situation can
  12. arise if a user sets a cache variable on the command line without specifying
  13. a type, such as ``cmake -DMYVAR=blah ...`` instead of
  14. ``cmake -DMYVAR:FILEPATH=blah``.
  15. Related to the above, if a cache variable of the specified name already exists
  16. and it *does* have a type, the various ``find_...()`` commands would return
  17. that value unchanged. In particular, if it contained a relative path, it
  18. would not be converted to an absolute path in this situation.
  19. When policy ``CMP0125`` is set to ``OLD`` or is unset, the behavior is as
  20. described above. When it is set to ``NEW``, the behavior is as follows:
  21. * If a non-cache variable of the specified name exists when the ``find_...()``
  22. command is called, its value will be used regardless of whether a cache
  23. variable of the same name already exists or not. A cache variable will not
  24. be created in this case if no such cache variable existed before.
  25. If a cache variable of the specified name did already exist, the cache will
  26. be updated to match the non-cache variable.
  27. * The various ``find...()`` commands will always provide an absolute path in
  28. the result variable, except where a relative path provided by a cache or
  29. non-cache variable cannot be resolved to an existing path.
  30. .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.21
  31. .. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
  32. .. include:: STANDARD_ADVICE.txt
  33. .. include:: DEPRECATED.txt