Preserve CMake options when make is invoked

This commit is contained in:
Mahmoud Al-Qudsi 2020-07-12 18:26:01 -05:00
parent 9ee5075fc3
commit af157dea67
2 changed files with 12 additions and 7 deletions

View File

@ -20,20 +20,22 @@ _GENERATOR!=which ninja 2>/dev/null >/dev/null && echo Ninja || echo "Unix Makef
GENERATOR?=$(_GENERATOR) GENERATOR?=$(_GENERATOR)
.if $(GENERATOR) == "Ninja" .if $(GENERATOR) == "Ninja"
BUILDFILE=build/build.ninja BUILDFILE=build.ninja
.else .else
BUILDFILE=build/Makefile BUILDFILE=Makefile
.endif .endif
PREFIX?=/usr/local PREFIX?=/usr/local
.PHONY: build/fish
build/fish: build/$(BUILDFILE) build/fish: build/$(BUILDFILE)
$(CMAKE) --build build $(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 mkdir -p build
build/$(BUILDFILE): build
cd build; $(CMAKE) .. -G "$(GENERATOR)" -DCMAKE_INSTALL_PREFIX="$(PREFIX)" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 cd build; $(CMAKE) .. -G "$(GENERATOR)" -DCMAKE_INSTALL_PREFIX="$(PREFIX)" -DCMAKE_EXPORT_COMPILE_COMMANDS=1
.PHONY: install .PHONY: install

View File

@ -31,15 +31,18 @@ else
all: .begin build/fish all: .begin build/fish
PHONY: .begin .PHONY: .begin
.begin: .begin:
@which $(CMAKE) > /dev/null 2> /dev/null || \ @which $(CMAKE) > /dev/null 2> /dev/null || \
(echo 'Please install CMake and then re-run the `make` command!' 1>&2 && false) (echo 'Please install CMake and then re-run the `make` command!' 1>&2 && false)
.PHONY: build/fish
build/fish: build/$(BUILDFILE) build/fish: build/$(BUILDFILE)
$(CMAKE) --build build $(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)" \ cd build; $(CMAKE) .. -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -G "$(GENERATOR)" \
-DCMAKE_INSTALL_PREFIX="$(PREFIX)" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ -DCMAKE_INSTALL_PREFIX="$(PREFIX)" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_BUILD_TYPE=RelWithDebInfo