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