Skip to content

Commit

Permalink
Refactored the project skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
david.chappelle committed Oct 1, 2013
1 parent 8ffac25 commit b30594b
Show file tree
Hide file tree
Showing 34 changed files with 118 additions and 177 deletions.
Empty file modified Makefile
100644 → 100755
Empty file.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
cpp-project-framework
=====================
+ cpp-project-framework

This is a project skeleton that can be used to quickly get up and running with a c++ based project without having to fight through all of the initial gnu make overhead.

+ Unit Testing

cxxtest is integrated with this project. To install cxxtest in your development
environment you first need to download the cxxtest tarball which you can find at
the following site:

http://sourceforge.net/projects/cxxtest/files/cxxtest/

Extract the tarball and install:

$ gunzip cxxtest-<version>.tar.gz
$ tar xf cxxtest-<version>.tar
$ cd cxxtest-<version>/python
$ python setup.py install

You should now be able to build your projects unit tests:

$ make test

This is a project skeleton that can be used to quickly get up and running with a c++ based project without having to fight through all of the initial gnu make overhead.
2 changes: 1 addition & 1 deletion bin/Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TOP_DIRECTORY=..
SUB_DIRECTORIES=client server
SUB_DIRECTORIES=skeleton

-include $(TOP_DIRECTORY)/mk/subdirectory.mk

8 changes: 0 additions & 8 deletions bin/client/client.cpp

This file was deleted.

12 changes: 0 additions & 12 deletions bin/server/Makefile

This file was deleted.

8 changes: 0 additions & 8 deletions bin/server/server.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions bin/client/Makefile → bin/skeleton/Makefile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ TOP_DIRECTORY=../..

CXX_LDFLAGS+= \
-lstdc++ \
-lclient \
-lskeleton \

EXECUTABLE=client
EXECUTABLE=skeleton

SOURCES=$(EXECUTABLE).cpp

Expand Down
10 changes: 10 additions & 0 deletions bin/skeleton/skeleton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdio.h>
#include <stdlib.h>

#include "skeleton/Skeleton.hpp"

int main(int argc, char** argv)
{
printf("argc=%d argv=%p\n", argc, argv);
return 0;
}
8 changes: 0 additions & 8 deletions include/client/client.hpp

This file was deleted.

8 changes: 0 additions & 8 deletions include/server/server.hpp

This file was deleted.

9 changes: 9 additions & 0 deletions include/skeleton/Skeleton.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef SKELETON_HPP
#define SKELETON_HPP

namespace skeleton
{

} // namespace skeleton

#endif
45 changes: 24 additions & 21 deletions mk/build.mk
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ ifeq ($(TOP_DIRECTORY),)
$(error <build.mk> TOP_DIRECTORY must be defined)
endif

ifeq ($(BUILD_CLEANUP_FILES),)
$(error <build.mk> BUILD_CLEANUP_FILES must be defined)
endif

ifeq ($(BUILD_OUTPUT_DIRECTORY),)
$(error <build.mk> BUILD_OUTPUT_DIRECTORY must be defined)
endif
Expand All @@ -14,6 +10,11 @@ ifeq ($(BUILD_LIBRARY_DIRECTORY),)
$(error <build.mk> BUILD_LIBRARY_DIRECTORY must be defined)
endif

ifneq ($(BUILD_OUTPUT_FILES),)
CLEANUP_BUILD_OUTPUT_FILES=1
endif
CLEANUP_BUILD_OUTPUT_FILES?=0

BUILD_DIRECTORIES=$(BUILD_OUTPUT_DIRECTORY) $(BUILD_LIBRARY_DIRECTORY)
BUILD_VERBOSE?=1

Expand All @@ -26,45 +27,47 @@ define create_build_directories
+@directories='$(BUILD_DIRECTORIES)'; \
for directory in $$directories; do \
if [ ! -d $$directory ]; then \
if test ! "$(BUILD_VERBOSE)" -eq 1; then \
if test $(BUILD_VERBOSE) -eq 1; then \
echo "Creating directory $$directory"; \
fi; \
$(MKDIR) -p $$directory; \
fi; \
done;
endef

# Currently we do not remove build directories. If we
# do find the need to it this should be called from
# clean below.
define remove_build_directories
+@directories='$(BUILD_DIRECTORIES)'; \
for directory in $$directories; do \
if [ -d $$directory ]; then \
if test ! "$(BUILD_VERBOSE)" -eq 1; then \
echo "Removing directory $$directory"; \
fi; \
$(RM) -fr $$directory; \
define cleanup_build_output
if [ -d $(BUILD_OUTPUT_DIRECTORY) ]; then \
if test $(BUILD_VERBOSE) -eq 1; then \
echo "Removing build output directory: $(BUILD_OUTPUT_DIRECTORY)"; \
fi; \
done;
$(RM) -fr $(BUILD_OUTPUT_DIRECTORY); \
fi; \
if test $(CLEANUP_BUILD_OUTPUT_FILES) -eq 1; then \
if test $(BUILD_VERBOSE) -eq 1; then \
echo "Removing build output files: $(BUILD_OUTPUT_FILES)"; \
fi; \
$(RM) -f $(BUILD_OUTPUT_FILES); \
fi;
endef

define compile_cxx_file
@cmd="$(CXX) $(CXX_FLAGS) -MMD -MP -c $< -o $@" ; \
if test ! "$(BUILD_VERBOSE)" -eq 1; then \
echo "Compiling $(BUILD_OUTPUT_DIRECTORY)/$<"; \
if test $(BUILD_VERBOSE) -eq 1; then \
echo "Compiling $<"; \
else \
echo "$$cmd"; \
fi; \
$$cmd
endef

build-directories:
$(create_build_directories)
@$(create_build_directories)

clean:
@rm -f $(BUILD_CLEANUP_FILES)
@$(cleanup_build_output)


$(BUILD_OUTPUT_DIRECTORY)/%.o: %.cpp
@$(compile_cxx_file)

.PHONY: clean
4 changes: 0 additions & 4 deletions mk/configuration.mk
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ BUILD_VERBOSE?=1
BUILD_OUTPUT_DIRECTORY?=output
BUILD_LIBRARY_DIRECTORY?=$(TOP_DIRECTORY)/lib
BUILD_INCLUDE_DIRECTORY?=$(TOP_DIRECTORY)/include

THIRDPARTY_LIBRARY_DIRECTORY?=$(TOP_DIRECTORY)/thirdparty/lib
THIRDPARTY_INCLUDE_DIRECTORY?=$(TOP_DIRECTORY)/thirdparty/include

2 changes: 1 addition & 1 deletion mk/executable.mk
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ endif
OBJECTS=$(addprefix $(BUILD_OUTPUT_DIRECTORY)/,$(addsuffix .o,$(basename $(SOURCES))))
DEPENDENCIES=$(addprefix $(BUILD_OUTPUT_DIRECTORY)/,$(addsuffix .d,$(basename $(SOURCES))))
EXECUTABLE_TARGETS=$(addprefix $(BUILD_OUTPUT_DIRECTORY)/, $(EXECUTABLES))
BUILD_CLEANUP_FILES=$(OBJECTS) $(DEPENDENCIES) $(EXECUTABLE_TARGETS)
BUILD_OUTPUT_FILES=$(OBJECTS) $(DEPENDENCIES) $(EXECUTABLE_TARGETS)

define compile_executable_target
@cmd="$(CXX) $(CXX_FLAGS) $@.o -o $@ $(CXX_LDFLAGS)" ; \
Expand Down
6 changes: 2 additions & 4 deletions mk/flags.mk
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ ifeq ($(TOP_DIRECTORY),)
endif

INCLUDE_DIRECTORIES+= \
-I$(BUILD_INCLUDE_DIRECTORY) \
-I$(THIRDPARTY_INCLUDE_DIRECTORY) \
-I$(BUILD_INCLUDE_DIRECTORY)

LIBRARY_DIRECTORIES+= \
-L$(BUILD_LIBRARY_DIRECTORY) \
-L$(THIRDPARTY_LIBRARY_DIRECTORY) \
-L$(BUILD_LIBRARY_DIRECTORY)

CXX_WARNINGS= \
-Wall \
Expand Down
2 changes: 1 addition & 1 deletion mk/library.mk
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ OBJECTS=$(addprefix $(BUILD_OUTPUT_DIRECTORY)/,$(addsuffix .o,$(basename $(SOURC
DEPENDENCIES=$(addprefix $(BUILD_OUTPUT_DIRECTORY)/,$(addsuffix .d,$(basename $(SOURCES))))
LIBRARY_DIRECTORY=$(TOP_DIRECTORY)/lib
LIBRARY_TARGET=$(LIBRARY_DIRECTORY)/lib$(LIBRARY).a
BUILD_CLEANUP_FILES=$(OBJECTS) $(DEPENDENCIES) $(LIBRARY_TARGET)
BUILD_OUTPUT_FILES=$(OBJECTS) $(DEPENDENCIES) $(LIBRARY_TARGET)

all: build-directories $(OBJECTS) $(LIBRARY_TARGET)

Expand Down
Empty file modified mk/subdirectory.mk
100644 → 100755
Empty file.
Empty file modified mk/target.mk
100644 → 100755
Empty file.
25 changes: 10 additions & 15 deletions mk/test.mk
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@ ifeq ($(TEST_SOURCES),)
$(error <test.mk> TEST_SOURCES must be defined)
endif

ifeq ($(TEST_EXECUTABLES),)
$(error <test.mk> TEST_EXECUTABLES must be defined)
endif
-include $(TOP_DIRECTORY)/mk/tools.mk
-include $(TOP_DIRECTORY)/mk/configuration.mk
-include $(TOP_DIRECTORY)/mk/build.mk

SOURCES=$(TEST_SOURCES)
EXECUTABLES=$(TEST_EXECUTABLES)
all:

-include $(TOP_DIRECTORY)/mk/executable.mk
test: build-directories $(BUILD_OUTPUT_DIRECTORY)/runner
$(BUILD_OUTPUT_DIRECTORY)/runner

define run_tests
+@tests='$(TEST_EXECUTABLES)'; \
for test in $$tests; do \
echo "Running test => $$test"; \
$(BUILD_OUTPUT_DIRECTORY)/$$test; \
done;
endef
$(BUILD_OUTPUT_DIRECTORY)/runner: $(BUILD_OUTPUT_DIRECTORY)/runner.cpp
$(CXX) $(CXX_FLAGS) -o $@ $< $(CXX_LDFLAGS)

test: all
$(run_tests)
$(BUILD_OUTPUT_DIRECTORY)/runner.cpp: $(TEST_SOURCES)
$(CXXTESTGEN) -o $@ --error-printer $^

2 changes: 2 additions & 0 deletions mk/tools.mk
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ INSTALL=?install
CP?=cp
MV?=mv
RM?=rm
RMDIR?=rmdir
MKDIR?=mkdir
DATE?=date
BISON?=bison
Expand All @@ -29,3 +30,4 @@ RANLIB=ranlib
SIZE=size
STRIP=strip
MAKE?=make
CXXTESTGEN=cxxtestgen
2 changes: 1 addition & 1 deletion src/Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TOP_DIRECTORY=..
SUB_DIRECTORIES=client server
SUB_DIRECTORIES=skeleton

-include $(TOP_DIRECTORY)/mk/subdirectory.mk

6 changes: 0 additions & 6 deletions src/client/client.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions src/client/test/Makefile

This file was deleted.

6 changes: 0 additions & 6 deletions src/client/test/t_test1.cpp

This file was deleted.

6 changes: 0 additions & 6 deletions src/client/test/t_test2.cpp

This file was deleted.

8 changes: 0 additions & 8 deletions src/server/Makefile

This file was deleted.

6 changes: 0 additions & 6 deletions src/server/server.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions src/server/test/Makefile

This file was deleted.

6 changes: 0 additions & 6 deletions src/server/test/t_test1.cpp

This file was deleted.

6 changes: 0 additions & 6 deletions src/server/test/t_test2.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions src/client/Makefile → src/skeleton/Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TOP_DIRECTORY=../..
SUB_DIRECTORIES=test
LIBRARY=client
SOURCES=client.cpp
LIBRARY=skeleton
SOURCES=Skeleton.cpp

-include $(TOP_DIRECTORY)/mk/library.mk
-include $(TOP_DIRECTORY)/mk/subdirectory.mk
Expand Down
Loading

0 comments on commit b30594b

Please sign in to comment.