From 2494f4c5eb3610560b35fb3b08653da6eec0e7c1 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Tue, 10 Nov 2020 22:07:12 +0100 Subject: [PATCH] adapted to new project hierarchy --- .gitignore | 1 + Makefile | 58 +++++++++++++++++++++++++++++----------------- premake.make | 1 + tests/Makefile | 51 ++++++++++++++++++++++++++++++++++++++++ tests/src/main.cpp | 8 +++++++ 5 files changed, 98 insertions(+), 21 deletions(-) create mode 100644 premake.make create mode 100644 tests/Makefile create mode 100644 tests/src/main.cpp diff --git a/.gitignore b/.gitignore index 821e960..3457b36 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ libscscreensaver.hpp +tests/tests diff --git a/Makefile b/Makefile index 8258260..9cc91d3 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +include premake.make + LIBNAME := $(shell basename $$(pwd)) MAJOR := 1 MINOR := 0.0 @@ -14,6 +16,7 @@ else REALNAME := $(SONAME).$(MINOR) endif +BUILDDIR := build/intermediates/ PREFIX ?= /usr/local BINDIR ?= $(PREFIX)/bin CONFIGDIR ?= $(PREFIX)/etc @@ -23,59 +26,72 @@ DATADIR ?= $(PREFIX)/share MANDIR ?= $(DATADIR)/man DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc -SRCS := $(wildcard *.cpp) -OBJS := $(subst .cpp,.o,$(SRCS)) -DEPS := $(subst .cpp,.d,$(SRCS)) -HDRS := $(filter-out $(LIBNAME).hpp,$(wildcard *.hpp)) +SRCS := $(notdir $(wildcard src/*.cpp)) +OBJS := $(SRCS:.cpp=.o) +DEPS := $(SRCS:.cpp=.d) +HDRS := $(wildcard src/*.hpp) CXX ?= g++ CXXFLAGS := $(CXXFLAGS) -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -fPIC ifeq ($(DEBUG),1) CXXFLAGS += -D DEBUG -O0 + CONFIG := debug else CXXFLAGS += -D NDEBUG -O3 + CONFIG := release endif +OUTDIR := build/$(CONFIG)/ -LDLIBS := -lcairo - -RM := /bin/rm -f +RM := /bin/rm -rf INSTALL := /usr/bin/install -c -.PHONY: all clean install +vpath %.cpp src +vpath %.d $(BUILDDIR) +vpath %.o $(BUILDDIR) -all: $(REALNAME) +.PHONY: all clean install prebuild test -$(REALNAME): $(OBJS) $(DEPS) +all: prebuild $(OUTDIR)$(REALNAME) + +prebuild: + @mkdir -p $(BUILDDIR) $(OUTDIR) + +$(OUTDIR)$(REALNAME): $(OBJS) $(DEPS) ifeq ($(UNAME_S),Darwin) - $(CXX) -dynamiclib -o $(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(OBJS) + $(CXX) -dynamiclib -o $(OUTDIR)$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS)) else - $(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(REALNAME) $(LDFLAGS) $(LDLIBS) $(OBJS) + $(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS)) endif %.o: %.cpp %.d Makefile $(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $< + @mv $@ $*.d $(BUILDDIR) --include *.d +-include $(BUILDDIR)*.d %.d: ; $(LIBNAME).hpp: $(HDRS) - @echo updating $(LIBNAME).hpp - @cp /dev/null $(LIBNAME).hpp + @echo updating build/$(LIBNAME).hpp + @cp /dev/null build/$(LIBNAME).hpp @for h in $(HDRS); \ do \ - cat $$h >> $(LIBNAME).hpp; \ + cat $$h >> build/$(LIBNAME).hpp; \ done -clean: - $(RM) $(OBJS) $(DEPS) $(REALNAME) $(LIBNAME).hpp +test: + $(MAKE) -C tests && tests/tests -install: $(REALNAME) $(LIBNAME).hpp +clean: + $(RM) build + $(MAKE) -C tests clean + +install: $(OUTDIR)$(REALNAME) $(LIBNAME).hpp $(INSTALL) -d $(LIBDIR) - $(INSTALL) -m 644 $(REALNAME) $(LIBDIR) + $(INSTALL) -m 644 $(OUTDIR)$(REALNAME) $(LIBDIR) $(INSTALL) -d $(INCLUDEDIR) - $(INSTALL) -m 644 $(LIBNAME).hpp $(INCLUDEDIR) + $(INSTALL) -m 644 build/$(LIBNAME).hpp $(INCLUDEDIR) ifeq ($(UNAME_S),Darwin) cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME) else diff --git a/premake.make b/premake.make new file mode 100644 index 0000000..44d7882 --- /dev/null +++ b/premake.make @@ -0,0 +1 @@ +LDLIBS := -lcairo diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..ae065a3 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,51 @@ +include ../premake.make +LDLIBS += -lboost_unit_test_framework + +BIN := $(shell basename $$(pwd)) + +SRCS := $(notdir $(wildcard src/*.cpp)) +SRCS += $(notdir $(filter-out ../src/main.cpp,$(wildcard ../src/*.cpp))) +OBJS := $(SRCS:.cpp=.o) +DEPS := $(SRCS:.cpp=.d) + +BUILDDIR := build/intermediates/ + +CXX ?= g++ +RM := /bin/rm -rf +INSTALL := /usr/bin/install -c + +CXXFLAGS := $(CXXFLAGS) -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -pthread -I../src +ifeq ($(DEBUG),1) + CXXFLAGS += -D DEBUG -O0 + CONFIG := debug +else + CXXFLAGS += -D NDEBUG -O3 + CONFIG := release +endif +OUTDIR := build/$(CONFIG)/ + +vpath %.cpp src ../src +vpath %.d $(BUILDDIR) +vpath %.o $(BUILDDIR) + +.PHONY: all clean prebuild + +all: prebuild $(OUTDIR)$(BIN) + +prebuild: + @mkdir -p $(BUILDDIR) $(OUTDIR) + +$(OUTDIR)$(BIN): $(OBJS) $(DEPS) + $(CXX) $(addprefix $(BUILDDIR),$(OBJS)) $(LDFLAGS) $(LDLIBS) -o $(OUTDIR)$(BIN) + @ln -sf $(OUTDIR)$(BIN) $(BIN) + +%.o: %.cpp %.d + $(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $< + @mv $@ $*.d $(BUILDDIR) + +-include $(BUILDDIR)*.d + +%.d: ; + +clean: + $(RM) build $(BIN) diff --git a/tests/src/main.cpp b/tests/src/main.cpp new file mode 100644 index 0000000..533ab2a --- /dev/null +++ b/tests/src/main.cpp @@ -0,0 +1,8 @@ +#define BOOST_TEST_MODULE My Test +#define BOOST_TEST_DYN_LINK +#include + +BOOST_AUTO_TEST_CASE(first_test) +{ + BOOST_TEST(1 == 1); +}