]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - package/pkg-cmake.mk
pkg-cmake: reduce output when being silent
[coffee/buildroot.git] / package / pkg-cmake.mk
1 ################################################################################
2 # CMake package infrastructure
3 #
4 # This file implements an infrastructure that eases development of
5 # package .mk files for CMake packages. It should be used for all
6 # packages that use CMake as their build system.
7 #
8 # See the Buildroot documentation for details on the usage of this
9 # infrastructure
10 #
11 # In terms of implementation, this CMake infrastructure requires
12 # the .mk file to only specify metadata information about the
13 # package: name, version, download URL, etc.
14 #
15 # We still allow the package .mk file to override what the different
16 # steps are doing, if needed. For example, if <PKG>_BUILD_CMDS is
17 # already defined, it is used as the list of commands to perform to
18 # build the package, instead of the default CMake behaviour. The
19 # package can also define some post operation hooks.
20 #
21 ################################################################################
22
23 # Set compiler variables.
24 ifeq ($(BR2_CCACHE),y)
25 CMAKE_HOST_C_COMPILER = $(HOST_DIR)/usr/bin/ccache
26 CMAKE_HOST_CXX_COMPILER = $(HOST_DIR)/usr/bin/ccache
27 CMAKE_HOST_C_COMPILER_ARG1 = $(HOSTCC_NOCCACHE)
28 CMAKE_HOST_CXX_COMPILER_ARG1 = $(HOSTCXX_NOCCACHE)
29 else
30 CMAKE_HOST_C_COMPILER = $(HOSTCC)
31 CMAKE_HOST_CXX_COMPILER = $(HOSTCXX)
32 endif
33
34 ifneq ($(QUIET),)
35 CMAKE_QUIET = -DCMAKE_RULE_MESSAGES=OFF -DCMAKE_INSTALL_MESSAGE=NEVER
36 endif
37
38 ################################################################################
39 # inner-cmake-package -- defines how the configuration, compilation and
40 # installation of a CMake package should be done, implements a few hooks to
41 # tune the build process and calls the generic package infrastructure to
42 # generate the necessary make targets
43 #
44 #  argument 1 is the lowercase package name
45 #  argument 2 is the uppercase package name, including a HOST_ prefix
46 #             for host packages
47 #  argument 3 is the uppercase package name, without the HOST_ prefix
48 #             for host packages
49 #  argument 4 is the type (target or host)
50 ################################################################################
51
52 define inner-cmake-package
53
54 $(2)_CONF_ENV                   ?=
55 $(2)_CONF_OPTS                  ?=
56 $(2)_MAKE                       ?= $$(MAKE)
57 $(2)_MAKE_ENV                   ?=
58 $(2)_MAKE_OPTS                  ?=
59 $(2)_INSTALL_OPTS               ?= install
60 $(2)_INSTALL_STAGING_OPTS       ?= DESTDIR=$$(STAGING_DIR) install
61 $(2)_INSTALL_TARGET_OPTS                ?= DESTDIR=$$(TARGET_DIR) install
62
63 $(2)_SRCDIR                     = $$($(2)_DIR)/$$($(2)_SUBDIR)
64 $(2)_BUILDDIR                   = $$($(2)_SRCDIR)
65
66 #
67 # Configure step. Only define it if not already defined by the package
68 # .mk file. And take care of the differences between host and target
69 # packages.
70 #
71 ifndef $(2)_CONFIGURE_CMDS
72 ifeq ($(4),target)
73
74 # Configure package for target
75 define $(2)_CONFIGURE_CMDS
76         (cd $$($$(PKG)_BUILDDIR) && \
77         rm -f CMakeCache.txt && \
78         PATH=$$(BR_PATH) \
79         $$($$(PKG)_CONF_ENV) $$(HOST_DIR)/usr/bin/cmake $$($$(PKG)_SRCDIR) \
80                 -DCMAKE_TOOLCHAIN_FILE="$$(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake" \
81                 -DCMAKE_BUILD_TYPE=$$(if $$(BR2_ENABLE_DEBUG),Debug,Release) \
82                 -DCMAKE_INSTALL_PREFIX="/usr" \
83                 -DCMAKE_COLOR_MAKEFILE=OFF \
84                 -DBUILD_DOC=OFF \
85                 -DBUILD_DOCS=OFF \
86                 -DBUILD_EXAMPLE=OFF \
87                 -DBUILD_EXAMPLES=OFF \
88                 -DBUILD_TEST=OFF \
89                 -DBUILD_TESTS=OFF \
90                 -DBUILD_TESTING=OFF \
91                 -DBUILD_SHARED_LIBS=$$(if $$(BR2_STATIC_LIBS),OFF,ON) \
92                 -DUSE_CCACHE=$$(if $$(BR2_CCACHE),ON,OFF) \
93                 $$(CMAKE_QUIET) \
94                 $$($$(PKG)_CONF_OPTS) \
95         )
96 endef
97 else
98
99 # Configure package for host
100 define $(2)_CONFIGURE_CMDS
101         (cd $$($$(PKG)_BUILDDIR) && \
102         rm -f CMakeCache.txt && \
103         PATH=$$(BR_PATH) \
104         $$(HOST_DIR)/usr/bin/cmake $$($$(PKG)_SRCDIR) \
105                 -DCMAKE_INSTALL_SO_NO_EXE=0 \
106                 -DCMAKE_FIND_ROOT_PATH="$$(HOST_DIR)" \
107                 -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM="BOTH" \
108                 -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY="BOTH" \
109                 -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE="BOTH" \
110                 -DCMAKE_INSTALL_PREFIX="$$(HOST_DIR)/usr" \
111                 -DCMAKE_C_FLAGS="$$(HOST_CFLAGS)" \
112                 -DCMAKE_CXX_FLAGS="$$(HOST_CXXFLAGS)" \
113                 -DCMAKE_EXE_LINKER_FLAGS="$$(HOST_LDFLAGS)" \
114                 -DCMAKE_ASM_COMPILER="$$(HOSTAS)" \
115                 -DCMAKE_C_COMPILER="$$(CMAKE_HOST_C_COMPILER)" \
116                 -DCMAKE_CXX_COMPILER="$$(CMAKE_HOST_CXX_COMPILER)" \
117                 $(if $$(CMAKE_HOST_C_COMPILER_ARG1),\
118                         -DCMAKE_C_COMPILER_ARG1="$$(CMAKE_HOST_C_COMPILER_ARG1)" \
119                         -DCMAKE_CXX_COMPILER_ARG1="$$(CMAKE_HOST_CXX_COMPILER_ARG1)" \
120                 ) \
121                 -DCMAKE_COLOR_MAKEFILE=OFF \
122                 -DBUILD_DOC=OFF \
123                 -DBUILD_DOCS=OFF \
124                 -DBUILD_EXAMPLE=OFF \
125                 -DBUILD_EXAMPLES=OFF \
126                 -DBUILD_TEST=OFF \
127                 -DBUILD_TESTS=OFF \
128                 -DBUILD_TESTING=OFF \
129                 $$(CMAKE_QUIET) \
130                 $$($$(PKG)_CONF_OPTS) \
131         )
132 endef
133 endif
134 endif
135
136 # This must be repeated from inner-generic-package, otherwise we only get
137 # host-cmake in _DEPENDENCIES because of the following line
138 ifeq ($(4),host)
139 $(2)_DEPENDENCIES ?= $$(filter-out host-toolchain $(1),$$(patsubst host-host-%,host-%,$$(addprefix host-,$$($(3)_DEPENDENCIES))))
140 endif
141
142 $(2)_DEPENDENCIES += host-cmake
143
144 #
145 # Build step. Only define it if not already defined by the package .mk
146 # file.
147 #
148 ifndef $(2)_BUILD_CMDS
149 ifeq ($(4),target)
150 define $(2)_BUILD_CMDS
151         $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_BUILDDIR)
152 endef
153 else
154 define $(2)_BUILD_CMDS
155         $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_BUILDDIR)
156 endef
157 endif
158 endif
159
160 #
161 # Host installation step. Only define it if not already defined by the
162 # package .mk file.
163 #
164 ifndef $(2)_INSTALL_CMDS
165 define $(2)_INSTALL_CMDS
166         $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) $$($$(PKG)_INSTALL_OPTS) -C $$($$(PKG)_BUILDDIR)
167 endef
168 endif
169
170 #
171 # Staging installation step. Only define it if not already defined by
172 # the package .mk file.
173 #
174 ifndef $(2)_INSTALL_STAGING_CMDS
175 define $(2)_INSTALL_STAGING_CMDS
176         $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) $$($$(PKG)_INSTALL_STAGING_OPTS) -C $$($$(PKG)_BUILDDIR)
177 endef
178 endif
179
180 #
181 # Target installation step. Only define it if not already defined by
182 # the package .mk file.
183 #
184 ifndef $(2)_INSTALL_TARGET_CMDS
185 define $(2)_INSTALL_TARGET_CMDS
186         $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) $$($$(PKG)_INSTALL_TARGET_OPTS) -C $$($$(PKG)_BUILDDIR)
187 endef
188 endif
189
190 # Call the generic package infrastructure to generate the necessary
191 # make targets
192 $(call inner-generic-package,$(1),$(2),$(3),$(4))
193
194 endef
195
196 ################################################################################
197 # cmake-package -- the target generator macro for CMake packages
198 ################################################################################
199
200 cmake-package = $(call inner-cmake-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
201 host-cmake-package = $(call inner-cmake-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
202
203 ################################################################################
204 # Generation of the CMake toolchain file
205 ################################################################################
206
207 # CMAKE_SYSTEM_PROCESSOR should match uname -m
208 ifeq ($(BR2_ARM_CPU_ARMV4),y)
209 CMAKE_SYSTEM_PROCESSOR_ARM_VARIANT = armv4
210 else ifeq ($(BR2_ARM_CPU_ARMV5),y)
211 CMAKE_SYSTEM_PROCESSOR_ARM_VARIANT = armv5
212 else ifeq ($(BR2_ARM_CPU_ARMV6),y)
213 CMAKE_SYSTEM_PROCESSOR_ARM_VARIANT = armv6
214 else ifeq ($(BR2_ARM_CPU_ARMV7A),y)
215 CMAKE_SYSTEM_PROCESSOR_ARM_VARIANT = armv7
216 endif
217
218 ifeq ($(BR2_arm),y)
219 CMAKE_SYSTEM_PROCESSOR = $(CMAKE_SYSTEM_PROCESSOR_ARM_VARIANT)l
220 else ifeq ($(BR2_armeb),y)
221 CMAKE_SYSTEM_PROCESSOR = $(CMAKE_SYSTEM_PROCESSORARM_VARIANT)b
222 else
223 CMAKE_SYSTEM_PROCESSOR = $(BR2_ARCH)
224 endif
225
226 # In order to allow the toolchain to be relocated, we calculate the HOST_DIR
227 # based on the toolchainfile.cmake file's location: $(HOST_DIR)/usr/share/buildroot
228 # In all the other variables, HOST_DIR will be replaced by RELOCATED_HOST_DIR,
229 # so we have to strip "$(HOST_DIR)/" from the paths that contain it.
230 $(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake:
231         @mkdir -p $(@D)
232         sed \
233                 -e 's:@@STAGING_SUBDIR@@:$(call qstrip,$(STAGING_SUBDIR)):' \
234                 -e 's:@@TARGET_CFLAGS@@:$(call qstrip,$(TARGET_CFLAGS)):' \
235                 -e 's:@@TARGET_CXXFLAGS@@:$(call qstrip,$(TARGET_CXXFLAGS)):' \
236                 -e 's:@@TARGET_LDFLAGS@@:$(call qstrip,$(TARGET_LDFLAGS)):' \
237                 -e 's:@@TARGET_CC_NOCCACHE@@:$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_CC_NOCCACHE))):' \
238                 -e 's:@@TARGET_CXX_NOCCACHE@@:$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_CXX_NOCCACHE))):' \
239                 -e 's:@@CMAKE_SYSTEM_PROCESSOR@@:$(call qstrip,$(CMAKE_SYSTEM_PROCESSOR)):' \
240                 $(TOPDIR)/support/misc/toolchainfile.cmake.in \
241                 > $@