CMP0125.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. This policy was introduced in CMake version 3.21. Use the
  31. :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
  32. Unlike many policies, CMake version |release| does *not* warn when the policy
  33. is not set and simply uses ``OLD`` behavior.
  34. .. include:: DEPRECATED.txt