CMP0114.rst 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. CMP0114
  2. -------
  3. .. versionadded:: 3.19
  4. :module:`ExternalProject` step targets fully adopt their steps.
  5. The :command:`ExternalProject_Add` ``STEP_TARGETS`` option, and the
  6. :command:`ExternalProject_Add_StepTargets` function, can be used to
  7. create build targets for individual steps of an external project.
  8. In CMake 3.18 and below, step targets have some limitations:
  9. * Step targets always depend on targets named by the
  10. :command:`ExternalProject_Add` ``DEPENDS`` option even though
  11. not all steps need them. In order to allow step targets to be created
  12. without those dependencies, the :command:`ExternalProject_Add`
  13. ``INDEPENDENT_STEP_TARGETS`` option or the
  14. :command:`ExternalProject_Add_StepTargets` ``NO_DEPENDS`` option may
  15. be used. However, adding such "independent" step targets makes sense
  16. only for specific steps such as ``download``, ``update``, and ``patch``
  17. because they do not need any of the external project's build dependencies.
  18. Furthermore, it does not make sense to create independent step targets
  19. for steps that depend on non-independent steps. Such rules are not
  20. enforced, and projects that do not follow them can generate build systems
  21. with confusing and generator-specific behavior.
  22. * Step targets hold copies of the custom commands implementing their
  23. steps that are separate from the copies in the primary target created
  24. by :command:`ExternalProject_Add`, and the primary target does not
  25. depend on the step targets. In parallel builds that drive the primary
  26. target and step targets concurrently, multiple copies of the steps'
  27. commands may run concurrently and race each other.
  28. Also, prior to policy :policy:`CMP0113`, the step targets generated
  29. by :ref:`Makefile Generators` also contain all the custom commands
  30. on which their step depends. This can lead to repeated execution of
  31. those steps even in serial builds.
  32. In CMake 3.19 and above, the :module:`ExternalProject` module prefers
  33. a revised design to address these problems:
  34. * Each step is classified as "independent" if it does not depend
  35. on other targets named by the :command:`ExternalProject_Add` ``DEPENDS``.
  36. The predefined steps are automatically classified by default:
  37. * The ``download``, ``update``, and ``patch`` steps are independent.
  38. * The ``configure``, ``build``, ``test``, and ``install`` steps are not.
  39. For custom steps, the :command:`ExternalProject_Add_Step` command provides
  40. an ``INDEPENDENT`` option to mark them as independent. It is an error to
  41. mark a step as independent if it depends on other steps that are not. Note
  42. that this use of the term "independent" refers only to independence from
  43. external targets and is orthogonal to a step's dependencies on other steps.
  44. * Step targets created by the :command:`ExternalProject_Add` ``STEP_TARGETS``
  45. option or the :command:`ExternalProject_Add_Step` function are now
  46. independent if and only if their steps are marked as independent.
  47. The :command:`ExternalProject_Add` ``INDEPENDENT_STEP_TARGETS`` option
  48. and :command:`ExternalProject_Add_StepTargets` ``NO_DEPENDS`` option
  49. are no longer allowed.
  50. * Step targets, when created, are fully responsible for holding the
  51. custom commands implementing their steps. The primary target created
  52. by :command:`ExternalProject_Add` depends on the step targets, and the
  53. step targets depend on each other. The target-level dependencies match
  54. the file-level dependencies used by the custom commands for each step.
  55. When the :command:`ExternalProject_Add` ``UPDATE_DISCONNECTED`` or
  56. ``TEST_EXCLUDE_FROM_MAIN`` option is used, or the
  57. :command:`ExternalProject_Add_Step` ``EXCLUDE_FROM_MAIN`` option is used
  58. for a custom step, some step targets may be created automatically.
  59. These are needed to hold the steps commonly depended upon by the primary
  60. target and the disconnected step targets.
  61. Policy ``CMP0114`` provides compatibility for projects that have not been
  62. updated to expect the new behavior. The ``OLD`` behavior for this policy
  63. is to use the above-documented behavior from 3.18 and below. The ``NEW``
  64. behavior for this policy is to use the above-documented behavior preferred
  65. by 3.19 and above.
  66. This policy was introduced in CMake version 3.19. CMake version
  67. |release| warns when the policy is not set and uses ``OLD`` behavior.
  68. Use the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW``
  69. explicitly.