From b30594b5d5631304578b2a6b302acaca778dd91f Mon Sep 17 00:00:00 2001 From: "david.chappelle" Date: Mon, 30 Sep 2013 21:00:19 -0400 Subject: [PATCH] Refactored the project skeleton --- Makefile | 0 README.md | 25 ++++++++++++++--- bin/Makefile | 2 +- bin/client/client.cpp | 8 ------ bin/server/Makefile | 12 --------- bin/server/server.cpp | 8 ------ bin/{client => skeleton}/Makefile | 4 +-- bin/skeleton/skeleton.cpp | 10 +++++++ include/client/client.hpp | 8 ------ include/server/server.hpp | 8 ------ include/skeleton/Skeleton.hpp | 9 +++++++ mk/build.mk | 45 ++++++++++++++++--------------- mk/configuration.mk | 4 --- mk/executable.mk | 2 +- mk/flags.mk | 6 ++--- mk/library.mk | 2 +- mk/subdirectory.mk | 0 mk/target.mk | 0 mk/test.mk | 25 +++++++---------- mk/tools.mk | 2 ++ src/Makefile | 2 +- src/client/client.cpp | 6 ----- src/client/test/Makefile | 17 ------------ src/client/test/t_test1.cpp | 6 ----- src/client/test/t_test2.cpp | 6 ----- src/server/Makefile | 8 ------ src/server/server.cpp | 6 ----- src/server/test/Makefile | 17 ------------ src/server/test/t_test1.cpp | 6 ----- src/server/test/t_test2.cpp | 6 ----- src/{client => skeleton}/Makefile | 4 +-- src/skeleton/Skeleton.cpp | 6 +++++ src/skeleton/test/Makefile | 9 +++++++ src/skeleton/test/t-Skeleton.hxx | 16 +++++++++++ 34 files changed, 118 insertions(+), 177 deletions(-) mode change 100644 => 100755 Makefile mode change 100644 => 100755 bin/Makefile delete mode 100644 bin/client/client.cpp delete mode 100644 bin/server/Makefile delete mode 100644 bin/server/server.cpp rename bin/{client => skeleton}/Makefile (78%) mode change 100644 => 100755 create mode 100644 bin/skeleton/skeleton.cpp delete mode 100644 include/client/client.hpp delete mode 100644 include/server/server.hpp create mode 100644 include/skeleton/Skeleton.hpp mode change 100644 => 100755 mk/build.mk mode change 100644 => 100755 mk/configuration.mk mode change 100644 => 100755 mk/executable.mk mode change 100644 => 100755 mk/flags.mk mode change 100644 => 100755 mk/library.mk mode change 100644 => 100755 mk/subdirectory.mk mode change 100644 => 100755 mk/target.mk mode change 100644 => 100755 mk/test.mk mode change 100644 => 100755 mk/tools.mk mode change 100644 => 100755 src/Makefile delete mode 100644 src/client/client.cpp delete mode 100644 src/client/test/Makefile delete mode 100644 src/client/test/t_test1.cpp delete mode 100644 src/client/test/t_test2.cpp delete mode 100644 src/server/Makefile delete mode 100644 src/server/server.cpp delete mode 100644 src/server/test/Makefile delete mode 100644 src/server/test/t_test1.cpp delete mode 100644 src/server/test/t_test2.cpp rename src/{client => skeleton}/Makefile (77%) mode change 100644 => 100755 create mode 100644 src/skeleton/Skeleton.cpp create mode 100755 src/skeleton/test/Makefile create mode 100644 src/skeleton/test/t-Skeleton.hxx diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 diff --git a/README.md b/README.md index 7682977..67f135b 100644 --- a/README.md +++ b/README.md @@ -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-.tar.gz + $ tar xf cxxtest-.tar + $ cd cxxtest-/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. \ No newline at end of file diff --git a/bin/Makefile b/bin/Makefile old mode 100644 new mode 100755 index 98c16c4..bd1f54f --- a/bin/Makefile +++ b/bin/Makefile @@ -1,5 +1,5 @@ TOP_DIRECTORY=.. -SUB_DIRECTORIES=client server +SUB_DIRECTORIES=skeleton -include $(TOP_DIRECTORY)/mk/subdirectory.mk diff --git a/bin/client/client.cpp b/bin/client/client.cpp deleted file mode 100644 index 31a7f9e..0000000 --- a/bin/client/client.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include - -#include "client/client.hpp" - -int main(int argc, char** argv) -{ - return 0; -} diff --git a/bin/server/Makefile b/bin/server/Makefile deleted file mode 100644 index 1d89d3b..0000000 --- a/bin/server/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -TOP_DIRECTORY=../.. - -CXX_LDFLAGS+= \ - -lstdc++ \ - -lserver \ - -EXECUTABLE=server - -SOURCES=$(EXECUTABLE).cpp - --include $(TOP_DIRECTORY)/mk/executable.mk - diff --git a/bin/server/server.cpp b/bin/server/server.cpp deleted file mode 100644 index 1ffd07a..0000000 --- a/bin/server/server.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include - -#include "server/server.hpp" - -int main(int argc, char** argv) -{ - return 0; -} diff --git a/bin/client/Makefile b/bin/skeleton/Makefile old mode 100644 new mode 100755 similarity index 78% rename from bin/client/Makefile rename to bin/skeleton/Makefile index 7b780e0..5c740ea --- a/bin/client/Makefile +++ b/bin/skeleton/Makefile @@ -2,9 +2,9 @@ TOP_DIRECTORY=../.. CXX_LDFLAGS+= \ -lstdc++ \ - -lclient \ + -lskeleton \ -EXECUTABLE=client +EXECUTABLE=skeleton SOURCES=$(EXECUTABLE).cpp diff --git a/bin/skeleton/skeleton.cpp b/bin/skeleton/skeleton.cpp new file mode 100644 index 0000000..39e0e61 --- /dev/null +++ b/bin/skeleton/skeleton.cpp @@ -0,0 +1,10 @@ +#include +#include + +#include "skeleton/Skeleton.hpp" + +int main(int argc, char** argv) +{ + printf("argc=%d argv=%p\n", argc, argv); + return 0; +} diff --git a/include/client/client.hpp b/include/client/client.hpp deleted file mode 100644 index 104a84d..0000000 --- a/include/client/client.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef CLIENT_HPP -#define CLIENT_HPP - -namespace client { - -} // namespace client - -#endif diff --git a/include/server/server.hpp b/include/server/server.hpp deleted file mode 100644 index 13ceec4..0000000 --- a/include/server/server.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef SERVER_HPP -#define SERVER_HPP - -namespace server { - -} // namespace server - -#endif diff --git a/include/skeleton/Skeleton.hpp b/include/skeleton/Skeleton.hpp new file mode 100644 index 0000000..7489d50 --- /dev/null +++ b/include/skeleton/Skeleton.hpp @@ -0,0 +1,9 @@ +#ifndef SKELETON_HPP +#define SKELETON_HPP + +namespace skeleton +{ + +} // namespace skeleton + +#endif diff --git a/mk/build.mk b/mk/build.mk old mode 100644 new mode 100755 index e046d21..a740a1a --- a/mk/build.mk +++ b/mk/build.mk @@ -2,10 +2,6 @@ ifeq ($(TOP_DIRECTORY),) $(error TOP_DIRECTORY must be defined) endif -ifeq ($(BUILD_CLEANUP_FILES),) - $(error BUILD_CLEANUP_FILES must be defined) -endif - ifeq ($(BUILD_OUTPUT_DIRECTORY),) $(error BUILD_OUTPUT_DIRECTORY must be defined) endif @@ -14,6 +10,11 @@ ifeq ($(BUILD_LIBRARY_DIRECTORY),) $(error 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 @@ -26,7 +27,7 @@ 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; \ @@ -34,25 +35,25 @@ define create_build_directories 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; \ @@ -60,11 +61,13 @@ define compile_cxx_file 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 diff --git a/mk/configuration.mk b/mk/configuration.mk old mode 100644 new mode 100755 index c612c6c..f0a9f7f --- a/mk/configuration.mk +++ b/mk/configuration.mk @@ -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 - diff --git a/mk/executable.mk b/mk/executable.mk old mode 100644 new mode 100755 index 29d8781..31c1f72 --- a/mk/executable.mk +++ b/mk/executable.mk @@ -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)" ; \ diff --git a/mk/flags.mk b/mk/flags.mk old mode 100644 new mode 100755 index 249504c..ed154ac --- a/mk/flags.mk +++ b/mk/flags.mk @@ -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 \ diff --git a/mk/library.mk b/mk/library.mk old mode 100644 new mode 100755 index 1342bb0..4ea4338 --- a/mk/library.mk +++ b/mk/library.mk @@ -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) diff --git a/mk/subdirectory.mk b/mk/subdirectory.mk old mode 100644 new mode 100755 diff --git a/mk/target.mk b/mk/target.mk old mode 100644 new mode 100755 diff --git a/mk/test.mk b/mk/test.mk old mode 100644 new mode 100755 index 45ca3f7..a259905 --- a/mk/test.mk +++ b/mk/test.mk @@ -6,23 +6,18 @@ ifeq ($(TEST_SOURCES),) $(error TEST_SOURCES must be defined) endif -ifeq ($(TEST_EXECUTABLES),) - $(error 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 $^ diff --git a/mk/tools.mk b/mk/tools.mk old mode 100644 new mode 100755 index facecb5..8ff7614 --- a/mk/tools.mk +++ b/mk/tools.mk @@ -3,6 +3,7 @@ INSTALL=?install CP?=cp MV?=mv RM?=rm +RMDIR?=rmdir MKDIR?=mkdir DATE?=date BISON?=bison @@ -29,3 +30,4 @@ RANLIB=ranlib SIZE=size STRIP=strip MAKE?=make +CXXTESTGEN=cxxtestgen diff --git a/src/Makefile b/src/Makefile old mode 100644 new mode 100755 index 98c16c4..bd1f54f --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ TOP_DIRECTORY=.. -SUB_DIRECTORIES=client server +SUB_DIRECTORIES=skeleton -include $(TOP_DIRECTORY)/mk/subdirectory.mk diff --git a/src/client/client.cpp b/src/client/client.cpp deleted file mode 100644 index 7249823..0000000 --- a/src/client/client.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "client/client.hpp" - -namespace client { - -} // namespace client - diff --git a/src/client/test/Makefile b/src/client/test/Makefile deleted file mode 100644 index 7468115..0000000 --- a/src/client/test/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -TOP_DIRECTORY=../../.. - -CXX_LDFLAGS= \ - -TEST1=t_test1 -TEST2=t_test2 - -TEST_SOURCES= \ - $(TEST1).cpp \ - $(TEST2).cpp \ - -TEST_EXECUTABLES= \ - $(TEST1) \ - $(TEST2) \ - --include $(TOP_DIRECTORY)/mk/test.mk - diff --git a/src/client/test/t_test1.cpp b/src/client/test/t_test1.cpp deleted file mode 100644 index 2187a0f..0000000 --- a/src/client/test/t_test1.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - return 0; -} diff --git a/src/client/test/t_test2.cpp b/src/client/test/t_test2.cpp deleted file mode 100644 index 2187a0f..0000000 --- a/src/client/test/t_test2.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - return 0; -} diff --git a/src/server/Makefile b/src/server/Makefile deleted file mode 100644 index 8033b24..0000000 --- a/src/server/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -TOP_DIRECTORY=../.. -SUB_DIRECTORIES=test -LIBRARY=server -SOURCES=server.cpp - --include $(TOP_DIRECTORY)/mk/library.mk --include $(TOP_DIRECTORY)/mk/subdirectory.mk - diff --git a/src/server/server.cpp b/src/server/server.cpp deleted file mode 100644 index aa04ec2..0000000 --- a/src/server/server.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "server/server.hpp" - -namespace server { - -} // namespace server - diff --git a/src/server/test/Makefile b/src/server/test/Makefile deleted file mode 100644 index 7468115..0000000 --- a/src/server/test/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -TOP_DIRECTORY=../../.. - -CXX_LDFLAGS= \ - -TEST1=t_test1 -TEST2=t_test2 - -TEST_SOURCES= \ - $(TEST1).cpp \ - $(TEST2).cpp \ - -TEST_EXECUTABLES= \ - $(TEST1) \ - $(TEST2) \ - --include $(TOP_DIRECTORY)/mk/test.mk - diff --git a/src/server/test/t_test1.cpp b/src/server/test/t_test1.cpp deleted file mode 100644 index 2187a0f..0000000 --- a/src/server/test/t_test1.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - return 0; -} diff --git a/src/server/test/t_test2.cpp b/src/server/test/t_test2.cpp deleted file mode 100644 index 2187a0f..0000000 --- a/src/server/test/t_test2.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - return 0; -} diff --git a/src/client/Makefile b/src/skeleton/Makefile old mode 100644 new mode 100755 similarity index 77% rename from src/client/Makefile rename to src/skeleton/Makefile index 1f763f6..66665ef --- a/src/client/Makefile +++ b/src/skeleton/Makefile @@ -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 diff --git a/src/skeleton/Skeleton.cpp b/src/skeleton/Skeleton.cpp new file mode 100644 index 0000000..3976667 --- /dev/null +++ b/src/skeleton/Skeleton.cpp @@ -0,0 +1,6 @@ +#include "skeleton/Skeleton.hpp" + +namespace skeleton +{ + +} // namespace skeleton diff --git a/src/skeleton/test/Makefile b/src/skeleton/test/Makefile new file mode 100755 index 0000000..34e9882 --- /dev/null +++ b/src/skeleton/test/Makefile @@ -0,0 +1,9 @@ +TOP_DIRECTORY=../../.. + +CXX_LDFLAGS+= \ + -lskeleton \ + +TEST_SOURCES= t-Skeleton.hxx + +-include $(TOP_DIRECTORY)/mk/test.mk + diff --git a/src/skeleton/test/t-Skeleton.hxx b/src/skeleton/test/t-Skeleton.hxx new file mode 100644 index 0000000..9b6e447 --- /dev/null +++ b/src/skeleton/test/t-Skeleton.hxx @@ -0,0 +1,16 @@ +#include + + +#include "skeleton/Skeleton.hpp" + + +class MySkeletonTestSuite : public CxxTest::TestSuite +{ +public: + void test_skeleton(void) + { + TS_ASSERT_EQUALS(true, true); + } +}; + +