packages: rename FOO_INSTALL_HOST_OPT into FOO_INSTALL_HOST_OPTS
[buildroot-gz.git] / package / pkg-cmake.mk
blob1cd91ab1cac80380393b9d88448d15cd624e4c66
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 ################################################################################
24 # inner-cmake-package -- defines how the configuration, compilation and
25 # installation of a CMake package should be done, implements a few hooks to
26 # tune the build process and calls the generic package infrastructure to
27 # generate the necessary make targets
29 # argument 1 is the lowercase package name
30 # argument 2 is the uppercase package name, including a HOST_ prefix
31 # for host packages
32 # argument 3 is the uppercase package name, without the HOST_ prefix
33 # for host packages
34 # argument 4 is the type (target or host)
35 ################################################################################
37 define inner-cmake-package
39 $(2)_CONF_ENV ?=
40 $(2)_CONF_OPT ?=
41 $(2)_MAKE ?= $$(MAKE)
42 $(2)_MAKE_ENV ?=
43 $(2)_MAKE_OPTS ?=
44 $(2)_INSTALL_HOST_OPTS ?= install
45 $(2)_INSTALL_STAGING_OPTS ?= DESTDIR=$$(STAGING_DIR) install
46 $(2)_INSTALL_TARGET_OPTS ?= DESTDIR=$$(TARGET_DIR) install
48 $(2)_SRCDIR = $$($(2)_DIR)/$$($(2)_SUBDIR)
49 $(2)_BUILDDIR = $$($(2)_SRCDIR)
52 # Configure step. Only define it if not already defined by the package
53 # .mk file. And take care of the differences between host and target
54 # packages.
56 ifndef $(2)_CONFIGURE_CMDS
57 ifeq ($(4),target)
59 # Configure package for target
60 define $(2)_CONFIGURE_CMDS
61 (cd $$($$(PKG)_BUILDDIR) && \
62 rm -f CMakeCache.txt && \
63 PATH=$$(BR_PATH) \
64 $$($$(PKG)_CONF_ENV) $$(HOST_DIR)/usr/bin/cmake $$($$(PKG)_SRCDIR) \
65 -DCMAKE_TOOLCHAIN_FILE="$$(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake" \
66 -DCMAKE_BUILD_TYPE=$$(if $$(BR2_ENABLE_DEBUG),Debug,Release) \
67 -DCMAKE_INSTALL_PREFIX="/usr" \
68 -DCMAKE_COLOR_MAKEFILE=OFF \
69 -DBUILD_TESTING=OFF \
70 -DBUILD_SHARED_LIBS=$$(if $$(BR2_PREFER_STATIC_LIB),OFF,ON) \
71 -DUSE_CCACHE=$$(if $$(BR2_CCACHE),ON,OFF) \
72 $$($$(PKG)_CONF_OPT) \
74 endef
75 else
77 # Configure package for host
78 define $(2)_CONFIGURE_CMDS
79 (cd $$($$(PKG)_BUILDDIR) && \
80 rm -f CMakeCache.txt && \
81 PATH=$$(BR_PATH) \
82 $$(HOST_DIR)/usr/bin/cmake $$($$(PKG)_SRCDIR) \
83 -DCMAKE_INSTALL_SO_NO_EXE=0 \
84 -DCMAKE_FIND_ROOT_PATH="$$(HOST_DIR)" \
85 -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM="BOTH" \
86 -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY="BOTH" \
87 -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE="BOTH" \
88 -DCMAKE_INSTALL_PREFIX="$$(HOST_DIR)/usr" \
89 -DCMAKE_C_FLAGS="$$(HOST_CFLAGS)" \
90 -DCMAKE_CXX_FLAGS="$$(HOST_CXXFLAGS)" \
91 -DCMAKE_EXE_LINKER_FLAGS="$$(HOST_LDFLAGS)" \
92 -DBUILD_TESTING=OFF \
93 $$($$(PKG)_CONF_OPT) \
95 endef
96 endif
97 endif
99 # This must be repeated from inner-generic-package, otherwise we only get
100 # host-cmake in _DEPENDENCIES because of the following line
101 ifeq ($(4),host)
102 $(2)_DEPENDENCIES ?= $$(filter-out host-toolchain $(1),$$(patsubst host-host-%,host-%,$$(addprefix host-,$$($(3)_DEPENDENCIES))))
103 endif
105 $(2)_DEPENDENCIES += host-cmake
108 # Build step. Only define it if not already defined by the package .mk
109 # file.
111 ifndef $(2)_BUILD_CMDS
112 ifeq ($(4),target)
113 define $(2)_BUILD_CMDS
114 $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_BUILDDIR)
115 endef
116 else
117 define $(2)_BUILD_CMDS
118 $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_BUILDDIR)
119 endef
120 endif
121 endif
124 # Host installation step. Only define it if not already defined by the
125 # package .mk file.
127 ifndef $(2)_INSTALL_CMDS
128 define $(2)_INSTALL_CMDS
129 $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) $$($$(PKG)_INSTALL_HOST_OPTS) -C $$($$(PKG)_BUILDDIR)
130 endef
131 endif
134 # Staging installation step. Only define it if not already defined by
135 # the package .mk file.
137 ifndef $(2)_INSTALL_STAGING_CMDS
138 define $(2)_INSTALL_STAGING_CMDS
139 $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) $$($$(PKG)_INSTALL_STAGING_OPTS) -C $$($$(PKG)_BUILDDIR)
140 endef
141 endif
144 # Target installation step. Only define it if not already defined by
145 # the package .mk file.
147 ifndef $(2)_INSTALL_TARGET_CMDS
148 define $(2)_INSTALL_TARGET_CMDS
149 $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) $$($$(PKG)_INSTALL_TARGET_OPTS) -C $$($$(PKG)_BUILDDIR)
150 endef
151 endif
153 # Call the generic package infrastructure to generate the necessary
154 # make targets
155 $(call inner-generic-package,$(1),$(2),$(3),$(4))
157 endef
159 ################################################################################
160 # cmake-package -- the target generator macro for CMake packages
161 ################################################################################
163 cmake-package = $(call inner-cmake-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
164 host-cmake-package = $(call inner-cmake-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
166 ################################################################################
167 # Generation of the CMake toolchain file
168 ################################################################################
170 # In order to allow the toolchain to be relocated, we calculate the HOST_DIR
171 # based on the toolchainfile.cmake file's location: $(HOST_DIR)/usr/share/buildroot
172 # In all the other variables, HOST_DIR will be replaced by RELOCATED_HOST_DIR,
173 # so we have to strip "$(HOST_DIR)/" from the paths that contain it.
174 $(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake:
175 @mkdir -p $(@D)
176 sed \
177 -e 's:@@STAGING_SUBDIR@@:$(call qstrip,$(STAGING_SUBDIR)):' \
178 -e 's:@@TARGET_CFLAGS@@:$(call qstrip,$(TARGET_CFLAGS)):' \
179 -e 's:@@TARGET_CXXFLAGS@@:$(call qstrip,$(TARGET_CXXFLAGS)):' \
180 -e 's:@@TARGET_LDFLAGS@@:$(call qstrip,$(TARGET_LDFLAGS)):' \
181 -e 's:@@TARGET_CC_NOCCACHE@@:$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_CC_NOCCACHE))):' \
182 -e 's:@@TARGET_CXX_NOCCACHE@@:$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_CXX_NOCCACHE))):' \
183 $(TOPDIR)/support/misc/toolchainfile.cmake.in \
184 > $@