OPTIMIZE_DEPENDENCIES.rst 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. OPTIMIZE_DEPENDENCIES
  2. ---------------------
  3. .. versionadded:: 3.19
  4. Activates dependency optimization of static and object libraries.
  5. When this property is set to true, some dependencies for a static or object
  6. library may be removed at generation time if they are not necessary to build
  7. the library, since static and object libraries don't actually link against
  8. anything.
  9. If a static or object library has dependency optimization enabled, it first
  10. discards all dependencies. Then, it looks through all of the direct and
  11. indirect dependencies that it initially had, and adds them back if they meet
  12. any of the following criteria:
  13. * The dependency was added to the library by :command:`add_dependencies`.
  14. * The dependency was added to the library through a source file in the library
  15. generated by a custom command that uses the dependency.
  16. * The dependency has any ``PRE_BUILD``, ``PRE_LINK``, or ``POST_BUILD`` custom
  17. commands associated with it.
  18. * The dependency contains any source files that were generated by a custom
  19. command.
  20. * The dependency contains any languages which produce side effects that are
  21. relevant to the library. Currently, all languages except C, C++, Objective-C,
  22. Objective-C++, assembly, and CUDA are assumed to produce side effects.
  23. However, side effects from one language are assumed not to be relevant to
  24. another (for example, a Fortran library is assumed to not have any side
  25. effects that are relevant for a Swift library.)
  26. As an example, assume you have a static Fortran library which depends on a
  27. static C library, which in turn depends on a static Fortran library. The
  28. top-level Fortran library has optimization enabled, but the middle C library
  29. does not. If you build the top Fortran library, the bottom Fortran library will
  30. also build, but not the middle C library, since the C library does not have any
  31. side effects that are relevant for the Fortran library. However, if you build
  32. the middle C library, the bottom Fortran library will also build, even though
  33. it does not have any side effects that are relevant to the C library, since the
  34. C library does not have optimization enabled.
  35. This property is initialized by the value of the
  36. :variable:`CMAKE_OPTIMIZE_DEPENDENCIES` variable when the target is created.