CMP0199.rst 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. CMP0199
  2. -------
  3. .. versionadded:: 4.2
  4. :genex:`$<CONFIG:cfgs>` only matches the configuration of the consumed target.
  5. Historically, when a :genex:`$<CONFIG:cfgs>` generator expression appeared in
  6. the properties of an imported target, it would match (that is, evaluate to
  7. ``1``) if any of the ``cfgs`` matched *any* of the following:
  8. 1. The selected configuration of the imported target being consumed.
  9. 2. The configuration of the consuming target.
  10. 3. *Any* of the configurations in the :prop_tgt:`MAP_IMPORTED_CONFIG_<CONFIG>`
  11. of the imported target being consumed
  12. (where ``<CONFIG>`` is the configuration of the consuming target),
  13. *whether or not such configurations are valid for the imported target*.
  14. This could result in expressions which are intended to be mutually exclusive
  15. being concurrently evaluated. This would be especially problematic if the
  16. value of a compile definition is intended to be determined by the
  17. configuration, as this lack of exclusivity could result in redefinition.
  18. CMake 4.2 and above prefer to consider *only* the configuration of the imported
  19. target being consumed; that is, (1) in the above list.
  20. This policy provides compatibility with projects that rely on the historical
  21. behavior. The ``OLD`` behavior for this policy is to retain the historic
  22. behavior as described above. The ``NEW`` behavior is to consider only the
  23. configuration of the imported target being consumed.
  24. .. note::
  25. This policy only applies to generator expressions being evaluated as part of
  26. the usage requirements of imported targets which are not imported from |CPS|
  27. packages.
  28. For non-imported targets, both the historic and ongoing behavior is to
  29. consider only the configuration of the consuming target. (The selected
  30. configuration of a non-imported target is always the active build
  31. configuration, which is necessarily the same as the consuming target's
  32. configuration.)
  33. For targets imported from |CPS| packages, the ``NEW`` behavior is used,
  34. regardless of the policy setting.
  35. .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 4.2
  36. .. |WARNS_OR_DOES_NOT_WARN| replace:: warns
  37. .. include:: include/STANDARD_ADVICE.rst
  38. .. include:: include/DEPRECATED.rst
  39. Examples
  40. ^^^^^^^^
  41. Consider the following imported libraries:
  42. .. code-block:: cmake
  43. add_library(test1 INTERFACE IMPORTED)
  44. set_target_properties(test1 PROPERTIES
  45. IMPORTED_CONFIGURATIONS "DEBUG"
  46. INTERFACE_COMPILE_DEFINITIONS
  47. "$<$<CONFIG:debug>:DEBUG>;$<$<CONFIG:release>:RELEASE>"
  48. )
  49. add_library(test2 INTERFACE IMPORTED)
  50. set_target_properties(test2 PROPERTIES
  51. IMPORTED_CONFIGURATIONS "TEST"
  52. INTERFACE_COMPILE_DEFINITIONS
  53. "$<$<CONFIG:debug>:DEBUG>;$<$<CONFIG:example>:EXAMPLE>;$<$<CONFIG:test>:TEST>"
  54. MAP_IMPORTED_CONFIG_RELEASE "DEBUG;EXAMPLE;TEST"
  55. )
  56. Assume that the consuming project is built in the ``Release`` configuration.
  57. Under the ``OLD`` policy, a consumer of ``test1`` would see both ``DEBUG``
  58. and ``RELEASE`` defined; ``$<CONFIG:debug>`` evaluates to ``1`` because the
  59. selected configuration of ``test1`` is ``DEBUG``, and ``$<CONFIG:release>``
  60. evaluates to ``1`` because the consumer's configuration is ``Release``
  61. (keeping in mind that configuration matching is case-insensitive). Likewise,
  62. a consumer of ``test2`` would see all of ``DEBUG``, ``RELEASE`` and ``TEST``
  63. defined; ``$<CONFIG:debug>``, ``$<CONFIG:example>`` and ``$<CONFIG:test>`` all
  64. evaluate to ``1`` because all of these configurations appear in
  65. ``MAP_IMPORTED_CONFIG_RELEASE``.
  66. Under the ``NEW`` policy, when ``test1`` is consumed, only ``$<CONFIG:debug>``
  67. will evaluate to ``1``. Similarly, when ``test2`` is consumed, only
  68. ``$<CONFIG:test>`` will evaluate to ``1``. Both of these correspond to the
  69. configuration of the consumed library that is actually selected by CMake.
  70. .. |CPS| replace:: Common Package Specification