From af157dea67ec313fe0b9636565a8a7856cf9b957 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 12 Jul 2020 18:26:01 -0500 Subject: [PATCH] Preserve CMake options when `make` is invoked --- BSDmakefile | 12 +++++++----- GNUmakefile | 7 +++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/BSDmakefile b/BSDmakefile index 85f5ee162..1fcc30512 100644 --- a/BSDmakefile +++ b/BSDmakefile @@ -20,20 +20,22 @@ _GENERATOR!=which ninja 2>/dev/null >/dev/null && echo Ninja || echo "Unix Makef GENERATOR?=$(_GENERATOR) .if $(GENERATOR) == "Ninja" -BUILDFILE=build/build.ninja +BUILDFILE=build.ninja .else -BUILDFILE=build/Makefile +BUILDFILE=Makefile .endif PREFIX?=/usr/local +.PHONY: build/fish build/fish: build/$(BUILDFILE) $(CMAKE) --build build -build: +# Don't split the mkdir into its own rule because that would cause CMake to regenerate the build +# files after each build (because it adds the mdate of the build directory into the out-of-date +# calculation tree). GNUmake supports order-only dependencies, BSDmake does not seem to. +build/$(BUILDFILE): mkdir -p build - -build/$(BUILDFILE): build cd build; $(CMAKE) .. -G "$(GENERATOR)" -DCMAKE_INSTALL_PREFIX="$(PREFIX)" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .PHONY: install diff --git a/GNUmakefile b/GNUmakefile index 53a7b046b..628a23292 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -31,15 +31,18 @@ else all: .begin build/fish -PHONY: .begin +.PHONY: .begin .begin: @which $(CMAKE) > /dev/null 2> /dev/null || \ (echo 'Please install CMake and then re-run the `make` command!' 1>&2 && false) +.PHONY: build/fish build/fish: build/$(BUILDFILE) $(CMAKE) --build build -build/$(BUILDFILE): build +# Use build as an order-only dependency. This prevents the target from always being outdated +# after a make run, and more importantly, doesn't clobber manually specified CMake options. +build/$(BUILDFILE): | build cd build; $(CMAKE) .. -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -G "$(GENERATOR)" \ -DCMAKE_INSTALL_PREFIX="$(PREFIX)" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ -DCMAKE_BUILD_TYPE=RelWithDebInfo