CMP0077.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. CMP0077
  2. -------
  3. .. versionadded:: 3.13
  4. :command:`option` honors normal variables.
  5. The :command:`option` command is typically used to create a cache entry
  6. to allow users to set the option. However, there are cases in which a
  7. normal (non-cached) variable of the same name as the option may be
  8. defined by the project prior to calling the :command:`option` command.
  9. For example, a project that embeds another project as a subdirectory
  10. may want to hard-code options of the subproject to build the way it needs.
  11. For historical reasons in CMake 3.12 and below the :command:`option`
  12. command *removes* a normal (non-cached) variable of the same name when:
  13. * a cache entry of the specified name does not exist at all, or
  14. * a cache entry of the specified name exists but has not been given
  15. a type (e.g. via ``-D<name>=ON`` on the command line).
  16. In both of these cases (typically on the first run in a new build tree),
  17. the :command:`option` command gives the cache entry type ``BOOL`` and
  18. removes any normal (non-cached) variable of the same name. In the
  19. remaining case that the cache entry of the specified name already
  20. exists and has a type (typically on later runs in a build tree), the
  21. :command:`option` command changes nothing and any normal variable of
  22. the same name remains set.
  23. In CMake 3.13 and above the :command:`option` command prefers to
  24. do nothing when a normal variable of the given name already exists.
  25. It does not create or update a cache entry or remove the normal variable.
  26. The new behavior is consistent between the first and later runs in a
  27. build tree. This policy provides compatibility with projects that have
  28. not been updated to expect the new behavior.
  29. When the :command:`option` command sees a normal variable of the given
  30. name:
  31. * The ``OLD`` behavior for this policy is to proceed even when a normal
  32. variable of the same name exists. If the cache entry does not already
  33. exist and have a type then it is created and/or given a type and the
  34. normal variable is removed.
  35. * The ``NEW`` behavior for this policy is to do nothing when a normal
  36. variable of the same name exists. The normal variable is not removed.
  37. The cache entry is not created or updated and is ignored if it exists.
  38. See :policy:`CMP0126` for a similar policy for the :command:`set(CACHE)`
  39. command, but note that there are some differences in ``NEW`` behavior
  40. between the two policies.
  41. This policy was introduced in CMake version 3.13. CMake version
  42. |release| warns when the policy is not set and uses ``OLD`` behavior.
  43. Use the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW``
  44. explicitly within a project. Use the :variable:`CMAKE_POLICY_DEFAULT_CMP0077
  45. <CMAKE_POLICY_DEFAULT_CMP\<NNNN\>>` variable to set the policy for
  46. a third-party project in a subdirectory without modifying it.
  47. .. include:: DEPRECATED.txt