adding-packages-cmake.txt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // -*- mode:doc; -*-
  2. Infrastructure for CMake-based packages
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. [[cmake-package-tutorial]]
  5. +cmake-package+ tutorial
  6. ^^^^^^^^^^^^^^^^^^^^^^^^
  7. First, let's see how to write a +.mk+ file for a CMake-based package,
  8. with an example :
  9. ------------------------
  10. 01: #############################################################
  11. 02: #
  12. 03: # libfoo
  13. 04: #
  14. 05: #############################################################
  15. 06: LIBFOO_VERSION = 1.0
  16. 07: LIBFOO_SOURCE = libfoo-$(LIBFOO_VERSION).tar.gz
  17. 08: LIBFOO_SITE = http://www.foosoftware.org/download
  18. 09: LIBFOO_INSTALL_STAGING = YES
  19. 10: LIBFOO_INSTALL_TARGET = NO
  20. 11: LIBFOO_CONF_OPT = -DBUILD_DEMOS=ON
  21. 12: LIBFOO_DEPENDENCIES = libglib2 host-pkgconf
  22. 13:
  23. 14: $(eval $(cmake-package))
  24. ------------------------
  25. On line 6, we declare the version of the package.
  26. On line 7 and 8, we declare the name of the tarball and the location
  27. of the tarball on the Web. Buildroot will automatically download the
  28. tarball from this location.
  29. On line 9, we tell Buildroot to install the package to the staging
  30. directory. The staging directory, located in +output/staging/+
  31. is the directory where all the packages are installed, including their
  32. development files, etc. By default, packages are not installed to the
  33. staging directory, since usually, only libraries need to be installed in
  34. the staging directory: their development files are needed to compile
  35. other libraries or applications depending on them. Also by default, when
  36. staging installation is enabled, packages are installed in this location
  37. using the +make install+ command.
  38. On line 10, we tell Buildroot to not install the package to the
  39. target directory. This directory contains what will become the root
  40. filesystem running on the target. For purely static libraries, it is
  41. not necessary to install them in the target directory because they will
  42. not be used at runtime. By default, target installation is enabled; setting
  43. this variable to NO is almost never needed. Also by default, packages are
  44. installed in this location using the +make install+ command.
  45. On line 11, we tell Buildroot to pass custom options to CMake when it is
  46. configuring the package.
  47. On line 12, we declare our dependencies, so that they are built
  48. before the build process of our package starts.
  49. Finally, on line line 14, we invoke the +cmake-package+
  50. macro that generates all the Makefile rules that actually allows the
  51. package to be built.
  52. [[cmake-package-reference]]
  53. +cmake-package+ reference
  54. ^^^^^^^^^^^^^^^^^^^^^^^^^
  55. The main macro of the CMake package infrastructure is
  56. +cmake-package+. It is similar to the +generic-package+ macro. The ability to
  57. have target and host packages is also available, with the
  58. +host-cmake-package+ macro.
  59. Just like the generic infrastructure, the CMake infrastructure works
  60. by defining a number of variables before calling the +cmake-package+
  61. macro.
  62. First, all the package metadata information variables that exist in
  63. the generic infrastructure also exist in the CMake infrastructure:
  64. +LIBFOO_VERSION+, +LIBFOO_SOURCE+, +LIBFOO_PATCH+, +LIBFOO_SITE+,
  65. +LIBFOO_SUBDIR+, +LIBFOO_DEPENDENCIES+, +LIBFOO_INSTALL_STAGING+,
  66. +LIBFOO_INSTALL_TARGET+.
  67. A few additional variables, specific to the CMake infrastructure, can
  68. also be defined. Many of them are only useful in very specific cases,
  69. typical packages will therefore only use a few of them.
  70. * +LIBFOO_SUBDIR+ may contain the name of a subdirectory inside the
  71. package that contains the main CMakeLists.txt file. This is useful,
  72. if for example, the main CMakeLists.txt file is not at the root of
  73. the tree extracted by the tarball. If +HOST_LIBFOO_SUBDIR+ is not
  74. specified, it defaults to +LIBFOO_SUBDIR+.
  75. * +LIBFOO_CONF_ENV+, to specify additional environment variables to
  76. pass to CMake. By default, empty.
  77. * +LIBFOO_CONF_OPT+, to specify additional configure options to pass
  78. to CMake. By default, empty.
  79. * +LIBFOO_MAKE+, to specify an alternate +make+ command. This is
  80. typically useful when parallel make is enabled in the configuration
  81. (using +BR2_JLEVEL+) but that this feature should be disabled for
  82. the given package, for one reason or another. By default, set to
  83. +$(MAKE)+. If parallel building is not supported by the package,
  84. then it should be set to +LIBFOO_MAKE=$(MAKE1)+.
  85. * +LIBFOO_MAKE_ENV+, to specify additional environment variables to
  86. pass to make in the build step. These are passed before the +make+
  87. command. By default, empty.
  88. * +LIBFOO_MAKE_OPT+, to specify additional variables to pass to make
  89. in the build step. These are passed after the +make+ command. By
  90. default, empty.
  91. * +LIBFOO_INSTALL_STAGING_OPT+ contains the make options used to
  92. install the package to the staging directory. By default, the value
  93. is +DESTDIR=$(STAGING_DIR) install+, which is correct for most
  94. CMake packages. It is still possible to override it.
  95. * +LIBFOO_INSTALL_TARGET_OPT+ contains the make options used to
  96. install the package to the target directory. By default, the value
  97. is +DESTDIR=$(TARGET_DIR) install+. The default value is correct
  98. for most CMake packages, but it is still possible to override it if
  99. needed.
  100. * +LIBFOO_CLEAN_OPT+ contains the make options used to clean the
  101. package. By default, the value is +clean+.
  102. With the CMake infrastructure, all the steps required to build and
  103. install the packages are already defined, and they generally work well
  104. for most CMake-based packages. However, when required, it is still
  105. possible to customize what is done in any particular step:
  106. * By adding a post-operation hook (after extract, patch, configure,
  107. build or install). See the reference documentation of the generic
  108. infrastructure for details.
  109. * By overriding one of the steps. For example, even if the CMake
  110. infrastructure is used, if the package +.mk+ file defines its own
  111. +LIBFOO_CONFIGURE_CMDS+ variable, it will be used instead of the
  112. default CMake one. However, using this method should be restricted
  113. to very specific cases. Do not use it in the general case.