From 06c81c5d578075d5425671255ffd3c38cc1e2879 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Thu, 19 Sep 2024 16:32:58 +0200 Subject: [PATCH] Setup project structure for unified Makefile --- main.cpp => src/main.cpp | 0 src/precomp.hpp | 127 +++++++++++++++++++++++++++++++++++++++ src/version.cpp | 19 ++++++ src/version.hpp | 8 +++ tests/Makefile | 1 + tests/postmake.make | 6 ++ tests/premake.make | 5 ++ tests/src/main.cpp | 8 +++ tests/src/precomp.hpp | 1 + 9 files changed, 175 insertions(+) rename main.cpp => src/main.cpp (100%) create mode 100644 src/precomp.hpp create mode 100644 src/version.cpp create mode 100644 src/version.hpp create mode 120000 tests/Makefile create mode 100644 tests/postmake.make create mode 100644 tests/premake.make create mode 100644 tests/src/main.cpp create mode 120000 tests/src/precomp.hpp diff --git a/main.cpp b/src/main.cpp similarity index 100% rename from main.cpp rename to src/main.cpp diff --git a/src/precomp.hpp b/src/precomp.hpp new file mode 100644 index 0000000..8fbefe0 --- /dev/null +++ b/src/precomp.hpp @@ -0,0 +1,127 @@ +// C++98 (first official C++ standard) +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if (__cplusplus >= 201103L) // C++11 +#include +#include +#include +#include +#include +#include // deprecated in C++17, removed in C++26 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // C++11 + +#if (__cplusplus >= 201402L) // C++14 +#include +#endif // C++14 + +#if (__cplusplus >= 201703L) // C++17 +#include +#include +#include +#include +#include +#include +#include +#include +#endif // C++17 + +#if (__cplusplus >= 202002L) // C++20 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // C++20 + +#if (__cplusplus >= 202302L) // C++23 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // C++23 + +#if (__cplusplus > 202302L) // C++26 +#include +#include +#include +#include +#include +#include +#endif // C++26 diff --git a/src/version.cpp b/src/version.cpp new file mode 100644 index 0000000..0df3638 --- /dev/null +++ b/src/version.cpp @@ -0,0 +1,19 @@ +#include "version.hpp" +#include "version.inc" +#include "commit.inc" +#include + +std::string {PROJECT}_version() { + std::ostringstream oss; + oss << "{PROJECT} version " << version; +#ifdef DEBUG + oss << " DEBUG"; +#endif + oss << '\n'; + if (commit[0] != '\0') { + oss << "build " << commit << ", "; + } + oss << __DATE__ << ", " << __TIME__ << '\n'; + oss << "(c) Bob Polis, all rights reserved"; + return oss.str(); +} diff --git a/src/version.hpp b/src/version.hpp new file mode 100644 index 0000000..e808f25 --- /dev/null +++ b/src/version.hpp @@ -0,0 +1,8 @@ +#ifndef VERSION_H_ +#define VERSION_H_ + +#include + +std::string {PROJECT}_version(); + +#endif // VERSION_H_ diff --git a/tests/Makefile b/tests/Makefile new file mode 120000 index 0000000..d0b0e8e --- /dev/null +++ b/tests/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/tests/postmake.make b/tests/postmake.make new file mode 100644 index 0000000..39e713a --- /dev/null +++ b/tests/postmake.make @@ -0,0 +1,6 @@ +$(BUILDDIR)/%.o: ../src/%.cpp +ifeq ($(PRECOMPILE), 1) + $(CXX) $(CXXFLAGS) -o $@ -include precomp.hpp -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $< +else + $(CXX) $(CXXFLAGS) -o $@ -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $< +endif diff --git a/tests/premake.make b/tests/premake.make new file mode 100644 index 0000000..d5cfa47 --- /dev/null +++ b/tests/premake.make @@ -0,0 +1,5 @@ +include ../premake.make +LDLIBS += -lboost_unit_test_framework +CXXFLAGS += -I../src +SRCS := $(notdir $(filter-out ../src/main.cpp,$(wildcard ../src/*.cpp))) +PRODUCT := tool 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); +} diff --git a/tests/src/precomp.hpp b/tests/src/precomp.hpp new file mode 120000 index 0000000..821bca7 --- /dev/null +++ b/tests/src/precomp.hpp @@ -0,0 +1 @@ +../../src/precomp.hpp \ No newline at end of file