From 97258f53634d7237a2962aec3387f011047ce83b Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 6 Jun 2021 14:31:01 +0200 Subject: build: add ninja build tool and make it available for cmake ninja is faster at building cmake packages than make, and according to reports also more reliable at handling parallel builds This commit includes a patch that adds GNU make jobserver support, in order to allow more precise control over the number of parallel tasks Enable parallel build by default for packages using ninja Signed-off-by: Felix Fietkau Signed-off-by: Rosen Penev --- include/cmake.mk | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'include') diff --git a/include/cmake.mk b/include/cmake.mk index 96c4d7df34..8a1c4fc4d5 100644 --- a/include/cmake.mk +++ b/include/cmake.mk @@ -1,5 +1,11 @@ cmake_bool = $(patsubst %,-D%:BOOL=$(if $($(1)),ON,OFF),$(2)) +ifeq ($(PKG_USE_NINJA),1) + PKG_BUILD_PARALLEL ?= 1 +endif +ifeq ($(HOST_USE_NINJA),1) + HOST_BUILD_PARALLEL ?= 1 +endif PKG_INSTALL:=1 ifneq ($(findstring c,$(OPENWRT_VERBOSE)),) @@ -44,6 +50,34 @@ CMAKE_FIND_ROOT_PATH:=$(STAGING_DIR)/usr;$(TOOLCHAIN_DIR)$(if $(CONFIG_EXTERNAL_ CMAKE_HOST_FIND_ROOT_PATH:=$(STAGING_DIR)/host;$(STAGING_DIR_HOSTPKG);$(STAGING_DIR_HOST) CMAKE_SHARED_LDFLAGS:=-Wl,-Bsymbolic-functions +ifeq ($(HOST_USE_NINJA),1) + CMAKE_HOST_OPTIONS += -DCMAKE_GENERATOR="Ninja" + + define Host/Compile/Default + +$(NINJA) -C $(HOST_BUILD_DIR) $(1) + endef + + define Host/Install/Default + +DESTDIR="$(HOST_INSTALL_DIR)" $(NINJA) -C $(HOST_BUILD_DIR) install + endef + + define Host/Uninstall/Default + +DESTDIR="$(HOST_INSTALL_DIR)" $(NINJA) -C $(HOST_BUILD_DIR) uninstall + endef +endif + +ifeq ($(PKG_USE_NINJA),1) + CMAKE_OPTIONS += -DCMAKE_GENERATOR="Ninja" + + define Build/Compile/Default + +$(NINJA) -C $(CMAKE_BINARY_DIR) $(1) + endef + + define Build/Install/Default + +DESTDIR="$(PKG_INSTALL_DIR)" $(NINJA) -C $(CMAKE_BINARY_DIR) install + endef +endif + define Build/Configure/Default mkdir -p $(CMAKE_BINARY_DIR) (cd $(CMAKE_BINARY_DIR); \ -- cgit v1.2.3