Adapted Makefile to allow for release/debug compiling and used new Makefile for test suite.

This commit is contained in:
Jerome 2021-12-18 15:59:08 +01:00
parent 82b5773b73
commit d344e6cf17
8 changed files with 77 additions and 52 deletions

View file

@ -22,7 +22,7 @@ OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
DEPS = $(OBJECTS:.o=.d)
# flags #
COMPILE_FLAGS = -std=c++17 -Wall -Wextra -g # -O3 -funsafe-math-optimizations
COMPILE_FLAGS = -std=c++17 -Wall -Wextra # -O3 -funsafe-math-optimizations
INCLUDES = -I include/ -I /usr/local/include
# Space-separated pkg-config libraries used by this project
LIBS =
@ -31,10 +31,15 @@ LIBS =
default_target: release
.PHONY: release
release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS)
release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) -O3 # -funsafe-math-optimizations
release: dirs
@$(MAKE) all
.PHONY: debug
debug: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) -g
debug: dirs
@$(MAKE) all
.PHONY: dirs
dirs:
@echo "Creating directories"

View file

@ -1,6 +0,0 @@
#ifndef DEF_test_c_lib
#define DEF_test_c_lib
#endif

View file

@ -1,14 +1,14 @@
#include <iostream>
#include "utils.hpp"
#include "TestClass.hpp"
#include <utils.hpp>
#include <TestClass.hpp>
using std::cout;
using std::endl;
int main()
{
return 0;
}

View file

@ -1 +0,0 @@
#include "test_c_lib.h"

View file

@ -1,49 +1,76 @@
# Declaration of variables
C = gcc
COMMON_FLAGS = -Wall -MMD -fprofile-arcs -ftest-coverage
C_FLAGS = $(COMMON_FLAGS)
CC = g++
CC_FLAGS = $(COMMON_FLAGS) -std=c++17 -O0
LD_FLAGS = -lgcov
INCLUDES =
CXX ?= g++
# File names
EXEC = run
CSOURCES = $(wildcard *.c)
COBJECTS = $(CSOURCES:.c=.o)
SOURCES = $(wildcard *.cpp)
OBJECTS = $(SOURCES:.cpp=.o)
# path #
SRC_PATH = src
BUILD_PATH = build
BIN_PATH = $(BUILD_PATH)/bin
# Main target
$(EXEC): $(COBJECTS) $(OBJECTS)
$(CC) $(COBJECTS) $(OBJECTS) -o $(EXEC) $(LD_FLAGS)
# executable #
BIN_NAME = CppQuickStart_test
# To obtain object files
%.o: %.cpp
$(CC) $(INCLUDES) $(CC_FLAGS) -o $@ -c $<
# extensions #
SRC_EXT = cpp
# To obtain object files
%.o: %.c
$(C) $(INCLUDES) $(C_FLAGS) -o $@ -c $<
# code lists #
# Find all source files in the source directory, sorted by
# most recently modified
SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-)
# Set the object file names, with the source directory stripped
# from the path, and the build path prepended in its place
OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
# Set the dependency files that will be used to add header dependencies
DEPS = $(OBJECTS:.o=.d)
-include $(SOURCES:%.cpp=%.d)
-include $(CSOURCES:%.c=%.d)
# flags #
COMPILE_FLAGS = -std=c++17 -Wall -Wextra -O0 -MMD -fprofile-arcs -ftest-coverage -g -lgcov
INCLUDES = -I include/ -I ../include/ -I /usr/local/include
# Space-separated pkg-config libraries used by this project
LIBS =
# To generate the documentation
.PHONY: default_target
default_target: debug
.PHONY: debug
debug: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS)
debug: dirs
@$(MAKE) all
.PHONY: dirs
dirs:
@echo "Creating directories"
@mkdir -p $(dir $(OBJECTS))
@mkdir -p $(BIN_PATH)
.PHONY: clean
clean:
@echo "Deleting $(BIN_NAME) symlink"
@$(RM) $(BIN_NAME)
@echo "Deleting directories"
@$(RM) -r $(BUILD_PATH)
@$(RM) -r $(BIN_PATH)
# checks the executable and symlinks to the output
.PHONY: all
all: $(BIN_PATH)/$(BIN_NAME)
@echo "Making symlink: $(BIN_NAME) -> $<"
@$(RM) $(BIN_NAME)
@ln -s $(BIN_PATH)/$(BIN_NAME) $(BIN_NAME)
.PHONY: doc
doc:
doxygen Doxyfile
# To generate human-readable coverage data
cov:
gcov *.gcda
# Creation of the executable
$(BIN_PATH)/$(BIN_NAME): $(OBJECTS)
@echo "Linking: $@"
$(CXX) $(OBJECTS) -o $@ ${LIBS}
# To remove all the files generated by gcov
cleancov:
rm -f *.gcov *.gcda
# Add dependency files, if they exist
-include $(DEPS)
# To remove generated files
clean: cleancov
rm -f $(COBJECTS) $(OBJECTS) $(SOURCES:%.cpp=%.d) $(CSOURCES:%.c=%.d) *.gcno
cleaner: clean
rm -f $(EXEC)
# Source file rules
# After the first compilation they will be joined with the rules from the
# dependency files to provide header dependencies
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
@echo "Compiling: $< -> $@"
$(CXX) $(CXXFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@

View file

@ -1,8 +1,8 @@
#include <catch2/catch.hpp>
#include <iostream>
#include "../utils.hpp"
#include "utils_test.hpp"
#include <utils.hpp>
#include <utils_test.hpp>
#define print(x) PRINT_VAR(x);
#define printvec(x) PRINT_VEC(x);