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
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
32 # argument 3 is the uppercase package name, without the HOST_ prefix
34 # argument 4 is the type (target or host)
35 ################################################################################
37 define inner-cmake-package
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
56 ifndef $(2)_CONFIGURE_CMDS
59 # Configure package for target
60 define $(2)_CONFIGURE_CMDS
61 (cd
$$($$(PKG
)_BUILDDIR
) && \
62 rm -f CMakeCache.txt
&& \
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 \
70 -DBUILD_SHARED_LIBS
=$$(if
$$(BR2_PREFER_STATIC_LIB
),OFF
,ON
) \
71 -DUSE_CCACHE
=$$(if
$$(BR2_CCACHE
),ON
,OFF
) \
72 $$($$(PKG
)_CONF_OPT
) \
77 # Configure package for host
78 define $(2)_CONFIGURE_CMDS
79 (cd
$$($$(PKG
)_BUILDDIR
) && \
80 rm -f CMakeCache.txt
&& \
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)" \
93 $$($$(PKG
)_CONF_OPT
) \
99 # This must be repeated from inner-generic-package, otherwise we only get
100 # host-cmake in _DEPENDENCIES because of the following line
102 $(2)_DEPENDENCIES ?
= $$(filter-out host-toolchain
$(1),$$(patsubst host-host-
%,host-
%,$$(addprefix host-
,$$($(3)_DEPENDENCIES
))))
105 $(2)_DEPENDENCIES
+= host-cmake
108 # Build step. Only define it if not already defined by the package .mk
111 ifndef $(2)_BUILD_CMDS
113 define $(2)_BUILD_CMDS
114 $$(TARGET_MAKE_ENV
) $$($$(PKG
)_MAKE_ENV
) $$($$(PKG
)_MAKE
) $$($$(PKG
)_MAKE_OPTS
) -C
$$($$(PKG
)_BUILDDIR
)
117 define $(2)_BUILD_CMDS
118 $$(HOST_MAKE_ENV
) $$($$(PKG
)_MAKE_ENV
) $$($$(PKG
)_MAKE
) $$($$(PKG
)_MAKE_OPTS
) -C
$$($$(PKG
)_BUILDDIR
)
124 # Host installation step. Only define it if not already defined by the
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
)
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
)
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
)
153 # Call the generic package infrastructure to generate the necessary
155 $(call inner-generic-package
,$(1),$(2),$(3),$(4))
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
:
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 \