#
# Makefile
#
# CMake-forwarding Makefile for POCO [generated by mkrelease]
#

.DEFAULT_GOAL := all

CMAKE_BUILD_DIR ?= cmake-build
CMAKE_BUILD_TYPE ?= RelWithDebInfo
CMAKE_GENERATOR ?= $(shell command -v ninja >/dev/null 2>&1 && echo "Ninja" || echo "Unix Makefiles")
CMAKE_OPTIONS ?=

.PHONY: all test install clean distclean help

help:
	@echo "POCO C++ Libraries - CMake Build"
	@echo ""
	@echo "Usage: make [target] [CMAKE_OPTIONS='-DENABLE_FOO=ON ...']"
	@echo ""
	@echo "Targets:"
	@echo "  all        - Configure and build (default)"
	@echo "  test       - Build and run tests"
	@echo "  install    - Install to CMAKE_INSTALL_PREFIX"
	@echo "  clean      - Remove build directory"

all:
	cmake -S. -B$(CMAKE_BUILD_DIR) -G"$(CMAKE_GENERATOR)" \
		-DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \
		$(CMAKE_OPTIONS)
	cmake --build $(CMAKE_BUILD_DIR) --parallel

test:
	cmake -S. -B$(CMAKE_BUILD_DIR) -G"$(CMAKE_GENERATOR)" \
		-DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \
		-DENABLE_TESTS=ON $(CMAKE_OPTIONS)
	cmake --build $(CMAKE_BUILD_DIR) --parallel
	cd $(CMAKE_BUILD_DIR) && ctest --output-on-failure

install: all
	cmake --install $(CMAKE_BUILD_DIR)

clean:
	rm -rf $(CMAKE_BUILD_DIR)

distclean: clean
