cjson: bump to version 1.4.3
[buildroot-gz.git] / package / pkg-cmake.mk
blob0897430f7088ab65d232c84d29f0a64d2ce988ab
1 ################################################################################
2 # CMake package infrastructure
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.
8 # See the Buildroot documentation for details on the usage of this
9 # infrastructure
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.
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.
21 ################################################################################
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
34 ifneq ($(QUIET),)
35 CMAKE_QUIET = -DCMAKE_RULE_MESSAGES=OFF -DCMAKE_INSTALL_MESSAGE=NEVER
36 endif
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
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 ################################################################################
52 define inner-cmake-package
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/fast
61 $(2)_INSTALL_TARGET_OPTS ?= DESTDIR=$$(TARGET_DIR) install/fast
63 $(2)_SRCDIR = $$($(2)_DIR)/$$($(2)_SUBDIR)
65 $(3)_SUPPORTS_IN_SOURCE_BUILD ?= YES
68 ifeq ($$($(3)_SUPPORTS_IN_SOURCE_BUILD),YES)
69 $(2)_BUILDDIR = $$($(2)_SRCDIR)
70 else
71 $(2)_BUILDDIR = $$($(2)_SRCDIR)/buildroot-build
72 endif
75 # Configure step. Only define it if not already defined by the package
76 # .mk file. And take care of the differences between host and target
77 # packages.
79 ifndef $(2)_CONFIGURE_CMDS
80 ifeq ($(4),target)
82 # Configure package for target
83 define $(2)_CONFIGURE_CMDS
84 (mkdir -p $$($$(PKG)_BUILDDIR) && \
85 cd $$($$(PKG)_BUILDDIR) && \
86 rm -f CMakeCache.txt && \
87 PATH=$$(BR_PATH) \
88 $$($$(PKG)_CONF_ENV) $$(BR2_CMAKE) $$($$(PKG)_SRCDIR) \
89 -DCMAKE_TOOLCHAIN_FILE="$$(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake" \
90 -DCMAKE_INSTALL_PREFIX="/usr" \
91 -DCMAKE_COLOR_MAKEFILE=OFF \
92 -DBUILD_DOC=OFF \
93 -DBUILD_DOCS=OFF \
94 -DBUILD_EXAMPLE=OFF \
95 -DBUILD_EXAMPLES=OFF \
96 -DBUILD_TEST=OFF \
97 -DBUILD_TESTS=OFF \
98 -DBUILD_TESTING=OFF \
99 -DBUILD_SHARED_LIBS=$$(if $$(BR2_STATIC_LIBS),OFF,ON) \
100 $$(CMAKE_QUIET) \
101 $$($$(PKG)_CONF_OPTS) \
103 endef
104 else
106 # Configure package for host
107 define $(2)_CONFIGURE_CMDS
108 (mkdir -p $$($$(PKG)_BUILDDIR) && \
109 cd $$($$(PKG)_BUILDDIR) && \
110 rm -f CMakeCache.txt && \
111 PATH=$$(BR_PATH) \
112 $$($$(PKG)_CONF_ENV) $$(BR2_CMAKE) $$($$(PKG)_SRCDIR) \
113 -DCMAKE_INSTALL_SO_NO_EXE=0 \
114 -DCMAKE_FIND_ROOT_PATH="$$(HOST_DIR)" \
115 -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM="BOTH" \
116 -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY="BOTH" \
117 -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE="BOTH" \
118 -DCMAKE_INSTALL_PREFIX="$$(HOST_DIR)/usr" \
119 -DCMAKE_C_FLAGS="$$(HOST_CFLAGS)" \
120 -DCMAKE_CXX_FLAGS="$$(HOST_CXXFLAGS)" \
121 -DCMAKE_EXE_LINKER_FLAGS="$$(HOST_LDFLAGS)" \
122 -DCMAKE_ASM_COMPILER="$$(HOSTAS)" \
123 -DCMAKE_C_COMPILER="$$(CMAKE_HOST_C_COMPILER)" \
124 -DCMAKE_CXX_COMPILER="$$(CMAKE_HOST_CXX_COMPILER)" \
125 $(if $$(CMAKE_HOST_C_COMPILER_ARG1),\
126 -DCMAKE_C_COMPILER_ARG1="$$(CMAKE_HOST_C_COMPILER_ARG1)" \
127 -DCMAKE_CXX_COMPILER_ARG1="$$(CMAKE_HOST_CXX_COMPILER_ARG1)" \
129 -DCMAKE_COLOR_MAKEFILE=OFF \
130 -DBUILD_DOC=OFF \
131 -DBUILD_DOCS=OFF \
132 -DBUILD_EXAMPLE=OFF \
133 -DBUILD_EXAMPLES=OFF \
134 -DBUILD_TEST=OFF \
135 -DBUILD_TESTS=OFF \
136 -DBUILD_TESTING=OFF \
137 $$(CMAKE_QUIET) \
138 $$($$(PKG)_CONF_OPTS) \
140 endef
141 endif
142 endif
144 # Since some CMake modules (even upstream ones) use pgk_check_modules
145 # primitives to find {C,LD}FLAGS, add it to the dependency list.
146 $(2)_DEPENDENCIES += host-pkgconf
148 $(2)_DEPENDENCIES += $(BR2_CMAKE_HOST_DEPENDENCY)
151 # Build step. Only define it if not already defined by the package .mk
152 # file.
154 ifndef $(2)_BUILD_CMDS
155 ifeq ($(4),target)
156 define $(2)_BUILD_CMDS
157 $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_BUILDDIR)
158 endef
159 else
160 define $(2)_BUILD_CMDS
161 $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_BUILDDIR)
162 endef
163 endif
164 endif
167 # Host installation step. Only define it if not already defined by the
168 # package .mk file.
170 ifndef $(2)_INSTALL_CMDS
171 define $(2)_INSTALL_CMDS
172 $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) $$($$(PKG)_INSTALL_OPTS) -C $$($$(PKG)_BUILDDIR)
173 endef
174 endif
177 # Staging installation step. Only define it if not already defined by
178 # the package .mk file.
180 ifndef $(2)_INSTALL_STAGING_CMDS
181 define $(2)_INSTALL_STAGING_CMDS
182 $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) $$($$(PKG)_INSTALL_STAGING_OPTS) -C $$($$(PKG)_BUILDDIR)
183 endef
184 endif
187 # Target installation step. Only define it if not already defined by
188 # the package .mk file.
190 ifndef $(2)_INSTALL_TARGET_CMDS
191 define $(2)_INSTALL_TARGET_CMDS
192 $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) $$($$(PKG)_INSTALL_TARGET_OPTS) -C $$($$(PKG)_BUILDDIR)
193 endef
194 endif
196 # Call the generic package infrastructure to generate the necessary
197 # make targets
198 $(call inner-generic-package,$(1),$(2),$(3),$(4))
200 endef
202 ################################################################################
203 # cmake-package -- the target generator macro for CMake packages
204 ################################################################################
206 cmake-package = $(call inner-cmake-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
207 host-cmake-package = $(call inner-cmake-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
209 ################################################################################
210 # Generation of the CMake toolchain file
211 ################################################################################
213 # CMAKE_SYSTEM_PROCESSOR should match uname -m
214 ifeq ($(BR2_ARM_CPU_ARMV4),y)
215 CMAKE_SYSTEM_PROCESSOR_ARM_VARIANT = armv4
216 else ifeq ($(BR2_ARM_CPU_ARMV5),y)
217 CMAKE_SYSTEM_PROCESSOR_ARM_VARIANT = armv5
218 else ifeq ($(BR2_ARM_CPU_ARMV6),y)
219 CMAKE_SYSTEM_PROCESSOR_ARM_VARIANT = armv6
220 else ifeq ($(BR2_ARM_CPU_ARMV7A),y)
221 CMAKE_SYSTEM_PROCESSOR_ARM_VARIANT = armv7
222 endif
224 ifeq ($(BR2_arm),y)
225 CMAKE_SYSTEM_PROCESSOR = $(CMAKE_SYSTEM_PROCESSOR_ARM_VARIANT)l
226 else ifeq ($(BR2_armeb),y)
227 CMAKE_SYSTEM_PROCESSOR = $(CMAKE_SYSTEM_PROCESSOR_ARM_VARIANT)b
228 else ifeq ($(call qstrip,$(BR2_ARCH)),powerpc64)
229 CMAKE_SYSTEM_PROCESSOR = ppc64
230 else ifeq ($(call qstrip,$(BR2_ARCH)),powerpc64le)
231 CMAKE_SYSTEM_PROCESSOR = ppc64le
232 else
233 CMAKE_SYSTEM_PROCESSOR = $(BR2_ARCH)
234 endif
236 # In order to allow the toolchain to be relocated, we calculate the HOST_DIR
237 # based on the toolchainfile.cmake file's location: $(HOST_DIR)/usr/share/buildroot
238 # In all the other variables, HOST_DIR will be replaced by RELOCATED_HOST_DIR,
239 # so we have to strip "$(HOST_DIR)/" from the paths that contain it.
240 $(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake:
241 @mkdir -p $(@D)
242 sed \
243 -e 's#@@STAGING_SUBDIR@@#$(call qstrip,$(STAGING_SUBDIR))#' \
244 -e 's#@@TARGET_CFLAGS@@#$(call qstrip,$(TARGET_CFLAGS))#' \
245 -e 's#@@TARGET_CXXFLAGS@@#$(call qstrip,$(TARGET_CXXFLAGS))#' \
246 -e 's#@@TARGET_FCFLAGS@@#$(call qstrip,$(TARGET_FCFLAGS))#' \
247 -e 's#@@TARGET_LDFLAGS@@#$(call qstrip,$(TARGET_LDFLAGS))#' \
248 -e 's#@@TARGET_CC@@#$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_CC)))#' \
249 -e 's#@@TARGET_CXX@@#$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_CXX)))#' \
250 -e 's#@@TARGET_FC@@#$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_FC)))#' \
251 -e 's#@@CMAKE_SYSTEM_PROCESSOR@@#$(call qstrip,$(CMAKE_SYSTEM_PROCESSOR))#' \
252 -e 's#@@TOOLCHAIN_HAS_FORTRAN@@#$(if $(BR2_TOOLCHAIN_HAS_FORTRAN),1,0)#' \
253 -e 's#@@CMAKE_BUILD_TYPE@@#$(if $(BR2_ENABLE_DEBUG),Debug,Release)#' \
254 $(TOPDIR)/support/misc/toolchainfile.cmake.in \
255 > $@
257 $(HOST_DIR)/usr/share/buildroot/Platform/Buildroot.cmake:
258 $(Q)$(INSTALL) -D -m 0644 support/misc/Buildroot.cmake $(@)