1################################################################################
2#
3# cmake
4#
5################################################################################
6
7# When updating the version, please also update BR2_HOST_CMAKE_AT_LEAST_X_Y
8CMAKE_VERSION_MAJOR = 3.28
9CMAKE_VERSION = $(CMAKE_VERSION_MAJOR).3
10CMAKE_SITE = https://cmake.org/files/v$(CMAKE_VERSION_MAJOR)
11CMAKE_LICENSE = BSD-3-Clause
12CMAKE_LICENSE_FILES = Copyright.txt
13CMAKE_CPE_ID_VALID = YES
14# Tool download MITM attack warning if using npm package to install cmake
15CMAKE_IGNORE_CVES = CVE-2016-10642
16
17# CMake is a particular package:
18# * CMake can be built using the generic infrastructure or the cmake one.
19#   Since Buildroot has no requirement regarding the host system cmake
20#   program presence, it uses the generic infrastructure to build the
21#   host-cmake package, then the (target-)cmake package can be built
22#   using the cmake infrastructure;
23# * CMake bundles its dependencies within its sources. This is the
24#   reason why the host-cmake package has no dependencies:, whereas
25#   the (target-)cmake package has a lot of dependencies, using only
26#   the system-wide libraries instead of rebuilding and statically
27#   linking with the ones bundled into the CMake sources.
28
29CMAKE_DEPENDENCIES = zlib jsoncpp libcurl libarchive expat bzip2 xz libuv rhash
30
31CMAKE_CONF_OPTS = \
32	-DKWSYS_LFS_WORKS=TRUE \
33	-DKWSYS_CHAR_IS_SIGNED=TRUE \
34	-DCMAKE_USE_SYSTEM_LIBRARIES=1 \
35	-DCTEST_USE_XMLRPC=OFF \
36	-DCMake_ENABLE_DEBUGGER=0 \
37	-DBUILD_CursesDialog=OFF
38
39# Get rid of -I* options from $(HOST_CPPFLAGS) to prevent that a
40# header available in $(HOST_DIR)/include is used instead of a
41# CMake internal header, e.g. lzma* headers of the xz package
42HOST_CMAKE_CFLAGS = $(shell echo $(HOST_CFLAGS) | sed -r "s%$(HOST_CPPFLAGS)%%")
43HOST_CMAKE_CXXFLAGS = $(shell echo $(HOST_CXXFLAGS) | sed -r "s%$(HOST_CPPFLAGS)%%")
44
45# We may be a ccache dependency, so we can't use ccache
46HOST_CMAKE_CONFIGURE_OPTS = \
47	$(HOST_CONFIGURE_OPTS) \
48	CC="$(HOSTCC_NOCCACHE)" \
49	GCC="$(HOSTCC_NOCCACHE)" \
50	CXX="$(HOSTCXX_NOCCACHE)"
51
52define HOST_CMAKE_CONFIGURE_CMDS
53	(cd $(@D); \
54		$(HOST_CMAKE_CONFIGURE_OPTS) \
55		CFLAGS="$(HOST_CMAKE_CFLAGS)" \
56		./bootstrap --prefix=$(HOST_DIR) \
57			--parallel=$(PARALLEL_JOBS) -- \
58			-DCMAKE_C_FLAGS="$(HOST_CMAKE_CFLAGS)" \
59			-DCMAKE_CXX_FLAGS="$(HOST_CMAKE_CXXFLAGS)" \
60			-DCMAKE_EXE_LINKER_FLAGS="$(HOST_LDFLAGS)" \
61			-DCMAKE_USE_OPENSSL:BOOL=OFF \
62			-DBUILD_CursesDialog=OFF \
63	)
64endef
65
66define HOST_CMAKE_BUILD_CMDS
67	$(HOST_MAKE_ENV) $(MAKE) -C $(@D)
68endef
69
70define HOST_CMAKE_INSTALL_CMDS
71	$(HOST_MAKE_ENV) $(MAKE) -C $(@D) install/fast
72endef
73
74define CMAKE_REMOVE_EXTRA_DATA
75	rm $(TARGET_DIR)/usr/bin/{cmake,cpack}
76	rm -fr $(TARGET_DIR)/usr/share/cmake-$(CMAKE_VERSION_MAJOR)/{completions,editors}
77	rm -fr $(TARGET_DIR)/usr/share/cmake-$(CMAKE_VERSION_MAJOR)/{Help,include}
78endef
79
80define CMAKE_INSTALL_CTEST_CFG_FILE
81	$(INSTALL) -m 0644 -D $(@D)/Modules/CMake.cmake \
82		$(TARGET_DIR)/usr/share/cmake-$(CMAKE_VERSION_MAJOR)/Modules/CMake.cmake.ctest
83endef
84
85CMAKE_POST_INSTALL_TARGET_HOOKS += CMAKE_REMOVE_EXTRA_DATA
86CMAKE_POST_INSTALL_TARGET_HOOKS += CMAKE_INSTALL_CTEST_CFG_FILE
87
88define CMAKE_INSTALL_TARGET_CMDS
89	(cd $(@D); \
90		$(HOST_MAKE_ENV) DESTDIR=$(TARGET_DIR) \
91		cmake -P cmake_install.cmake \
92	)
93endef
94
95$(eval $(cmake-package))
96$(eval $(host-generic-package))
97