From ff9209bd4e8c57659afe60b1a5875cfd7e21edff Mon Sep 17 00:00:00 2001 From: Quentin Quadrat Date: Fri, 10 May 2024 11:59:25 +0200 Subject: [PATCH] Use MyMakefile v2-alpha --- .gitignore | 4 +- .makefile | 2 +- Makefile | 93 ++++++---------------------- Makefile.common | 5 ++ README.md | 2 +- VERSION.txt | 1 - demo/Makefile | 74 ++++++---------------- demo/VERSION.txt | 1 - demo/{ => src}/Debug.cpp | 0 demo/{ => src}/Demo.cpp | 0 demo/{ => src}/Display/DataPath.cpp | 4 +- demo/{ => src}/Display/DataPath.hpp | 0 demo/{ => src}/Display/DearImGui.cpp | 0 demo/{ => src}/Display/DearImGui.hpp | 0 demo/{ => src}/Display/Draw.cpp | 0 demo/{ => src}/Display/IGame.hpp | 0 demo/{ => src}/Display/SDLHelper.cpp | 0 demo/{ => src}/Display/SDLHelper.hpp | 0 demo/{ => src}/Display/Window.cpp | 0 demo/{ => src}/Display/Window.hpp | 0 demo/{ => src}/Listeners.cpp | 0 demo/{ => src}/main.cpp | 20 +++--- demo/{ => src}/main.hpp | 0 external/download-external-libs.sh | 38 +++--------- tests/Makefile | 53 ++++++++-------- 25 files changed, 93 insertions(+), 204 deletions(-) create mode 100644 Makefile.common delete mode 100644 VERSION.txt delete mode 100644 demo/VERSION.txt rename demo/{ => src}/Debug.cpp (100%) rename demo/{ => src}/Demo.cpp (100%) rename demo/{ => src}/Display/DataPath.cpp (99%) rename demo/{ => src}/Display/DataPath.hpp (100%) rename demo/{ => src}/Display/DearImGui.cpp (100%) rename demo/{ => src}/Display/DearImGui.hpp (100%) rename demo/{ => src}/Display/Draw.cpp (100%) rename demo/{ => src}/Display/IGame.hpp (100%) rename demo/{ => src}/Display/SDLHelper.cpp (100%) rename demo/{ => src}/Display/SDLHelper.hpp (100%) rename demo/{ => src}/Display/Window.cpp (100%) rename demo/{ => src}/Display/Window.hpp (100%) rename demo/{ => src}/Listeners.cpp (100%) rename demo/{ => src}/main.cpp (91%) rename demo/{ => src}/main.hpp (100%) diff --git a/.gitignore b/.gitignore index 44e47ce..4091119 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,8 @@ # Project specific *~ -build +build* cov-int src/*.tar.bz2 -src/build -tests/build external/.downloaded external/imgui external/imgui_sdl diff --git a/.makefile b/.makefile index e763ff6..d9a4013 160000 --- a/.makefile +++ b/.makefile @@ -1 +1 @@ -Subproject commit e763ff67918c56b479a7eb240ff04dcdee899539 +Subproject commit d9a4013b29d7c48206f78be5e7edcafb1bc462b1 diff --git a/Makefile b/Makefile index 071e2ed..173b1b1 100644 --- a/Makefile +++ b/Makefile @@ -1,94 +1,41 @@ - -################################################### -# Project definition -# -PROJECT = OpenGlassBox -TARGET = $(PROJECT) -DESCRIPTION = An Open Source Implementation of the SimCity 2013 Simulation Engine GlassBox -STANDARD = --std=c++14 -BUILD_TYPE = release - ################################################### # Location of the project directory and Makefiles # P := . M := $(P)/.makefile -include $(M)/Makefile.header - -################################################### -# Inform Makefile where to find header files -# -INCLUDES += -I$(P)/include -I$(P) ################################################### -# Inform Makefile where to find *.cpp and *.o files +# Project definition # -VPATH += $(P)/src $(P)/src/Core +include $(P)/Makefile.common +TARGET_NAME := $(PROJECT_NAME) +TARGET_DESCRIPTION := An open source implementation of the SimCity 2013 simulation engine GlassBox +include $(M)/project/Makefile ################################################### -# Project defines +# Compile shared and static libraries # -DEFINES += -DVIRTUAL= -DDESIRED_GRID_SIZE=30u +LIB_FILES := $(call rwildcard,src,*.cpp) +INCLUDES := $(P)/include +VPATH := $(P)/src +DEFINES := -DVIRTUAL= -DDESIRED_GRID_SIZE=30u ################################################### -# Make the list of compiled files for the library +# Generic Makefile rules # -LIB_OBJS += Simulation.o Map.o City.o Unit.o Path.o Agent.o Resource.o Resources.o -LIB_OBJS += ScriptParser.o MapCoordinatesInsideRadius.o MapRandomCoordinates.o -LIB_OBJS += Rule.o RuleCommand.o RuleValue.o Dijkstra.o +include $(M)/rules/Makefile ################################################### -# Compile the project as static and shared libraries. +# Extra rules # -.PHONY: all -all: $(STATIC_LIB_TARGET) $(SHARED_LIB_TARGET) $(PKG_FILE) demo +all:: demo -################################################### -# Compile the demo as standalone application. -# .PHONY: demo -demo: | $(STATIC_LIB_TARGET) $(SHARED_LIB_TARGET) - @$(call print-from,"Compiling scenarios",$(PROJECT),demo) - $(MAKE) -C demo all - -################################################### -# Install project. You need to be root. -# -ifeq ($(ARCHI),Linux) -.PHONY: install -install: $(STATIC_LIB_TARGET) $(SHARED_LIB_TARGET) $(PKG_FILE) demo - @$(call INSTALL_BINARY) - @$(call INSTALL_DOCUMENTATION) - @$(call INSTALL_PROJECT_LIBRARIES) - @$(call INSTALL_PROJECT_HEADERS) -endif - -################################################### -# Compile and launch unit tests and generate the code coverage html report. -# -.PHONY: unit-tests -unit-tests: - @$(call print-simple,"Compiling unit tests") - @$(MAKE) -C tests coverage - -################################################### -# Compile and launch unit tests and generate the code coverage html report. -# -.PHONY: check -check: unit-tests - -################################################### -# Clean the whole project. -# -.PHONY: veryclean -veryclean: clean - @rm -fr cov-int $(PROJECT).tgz *.log foo 2> /dev/null - @(cd tests && $(MAKE) -s clean) - @$(call print-simple,"Cleaning","$(PWD)/doc/html") - @rm -fr $(THIRDPART)/*/ doc/html 2> /dev/null - @$(MAKE) -C demo clean +demo: + $(Q)$(MAKE) --no-print-directory --directory=demo all -################################################### -# Sharable informations between all Makefiles +clean:: + $(Q)$(MAKE) --no-print-directory --directory=demo clean -include $(M)/Makefile.footer +install:: + $(Q)$(MAKE) --no-print-directory --directory=demo install diff --git a/Makefile.common b/Makefile.common new file mode 100644 index 0000000..cb377ba --- /dev/null +++ b/Makefile.common @@ -0,0 +1,5 @@ +PROJECT_NAME := OpenGlassBox +PROJECT_VERSION := 0.2.0 +COMPILATION_MODE := release +CXX_STANDARD := --std=c++14 +PROJECT_DATA := demo/data diff --git a/README.md b/README.md index 95c4609..35bc44d 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Where `-j8` is to adapt to match the number of CPU cores. - Run the OpenGlassBox demo: ```sh -./demo/build/OpenGlassBox +./demo/build-release/Demo/Demo ``` - (Optional) Unit test with code coverage: diff --git a/VERSION.txt b/VERSION.txt deleted file mode 100644 index 0ea3a94..0000000 --- a/VERSION.txt +++ /dev/null @@ -1 +0,0 @@ -0.2.0 diff --git a/demo/Makefile b/demo/Makefile index e7ce534..de0da81 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -1,72 +1,38 @@ - -################################################### -# Project definition -# -PROJECT = OpenGlassBox -TARGET = $(PROJECT) -DESCRIPTION = An Open Source Implementation of the SimCity 2013 Simulation Engine GlassBox -STANDARD = --std=c++14 -BUILD_TYPE = debug - ################################################### # Location of the project directory and Makefiles # P := .. M := $(P)/.makefile -include $(M)/Makefile.header - -################################################### -# Inform Makefile where to find header files -# -INCLUDES += -I. -I$(P)/include -I$(P) - -################################################### -# Inform Makefile where to find *.cpp and *.o files -# -VPATH += $(P) Display ################################################### -# Project defines -# -DEFINES += -DVIRTUAL= -DDESIRED_GRID_SIZE=30u -DEFINES += -DDATADIR=\"$(DATADIR):$(abspath data)/:data/\" - -################################################### -# Set Libraries. For knowing which libraries -# is needed please read the external/README.md file. +# Project definition # -PKG_LIBS = sdl2 SDL2_image +include $(P)/Makefile.common +TARGET_NAME := $(PROJECT_NAME)-demo +TARGET_DESCRIPTION := A demo using $(PROJECT_NAME) +include $(M)/project/Makefile ################################################### -# Compile against the OpenGlassBox shared library +# Compile the standalone application # -THIRDPART_LIBS += $(abspath $(P)/$(BUILD)/libopenglassbox.a) +SRC_FILES := $(call rwildcard,src,*.cpp) +INCLUDES := $(P)/include $(P)/demo/src $(P) +VPATH := $(P)/demo +DEFINES := -DVIRTUAL= -DDESIRED_GRID_SIZE=30u +INTERNAL_LIBS := $(call internal-lib,$(PROJECT_NAME)) +PKG_LIBS := sdl2 SDL2_image ################################################### -# MacOS X +# Create MacOS X bundle application. # -ifeq ($(ARCHI),Darwin) -BUILD_MACOS_APP_BUNDLE = 1 -APPLE_IDENTIFIER = lecrapouille -MACOS_BUNDLE_ICON = data/$(PROJECT).icns -LINKER_FLAGS += -framework CoreFoundation +ifeq ($(OS),Darwin) + BUILD_MACOS_APP_BUNDLE = 1 + APPLE_IDENTIFIER := lecrapouille + MACOS_BUNDLE_ICON := data/$(PROJECT_NAME).icns + LINKER_FLAGS := -framework CoreFoundation endif ################################################### -# Compile the demo as standalone application. -# -OBJS += DearImGui.o SDLHelper.o Window.o DataPath.o -OBJS += Debug.o Draw.o Listeners.o Demo.o main.o - -################################################### -# Compile the demo as standalone application. +# Generic Makefile rules # -all: $(TARGET) - @cp $(BUILD)/$(TARGET) ../$(BUILD) -ifeq ($(ARCHI),Darwin) - @cp -r $(BUILD)/$(TARGET)$(EXT) ../$(BUILD) -endif - -################################################### -# Sharable informations between all Makefiles -include $(M)/Makefile.footer +include $(M)/rules/Makefile \ No newline at end of file diff --git a/demo/VERSION.txt b/demo/VERSION.txt deleted file mode 100644 index 0ea3a94..0000000 --- a/demo/VERSION.txt +++ /dev/null @@ -1 +0,0 @@ -0.2.0 diff --git a/demo/Debug.cpp b/demo/src/Debug.cpp similarity index 100% rename from demo/Debug.cpp rename to demo/src/Debug.cpp diff --git a/demo/Demo.cpp b/demo/src/Demo.cpp similarity index 100% rename from demo/Demo.cpp rename to demo/src/Demo.cpp diff --git a/demo/Display/DataPath.cpp b/demo/src/Display/DataPath.cpp similarity index 99% rename from demo/Display/DataPath.cpp rename to demo/src/Display/DataPath.cpp index 84bd88d..f632e30 100644 --- a/demo/Display/DataPath.cpp +++ b/demo/src/Display/DataPath.cpp @@ -217,15 +217,13 @@ std::string DataPath::toString() const { std::string string_path; - string_path += "."; - string_path += m_delimiter; - for (auto const& it: m_search_paths) { string_path += it; string_path.pop_back(); // Remove the '/' char string_path += m_delimiter; } + string_path.pop_back(); return string_path; } diff --git a/demo/Display/DataPath.hpp b/demo/src/Display/DataPath.hpp similarity index 100% rename from demo/Display/DataPath.hpp rename to demo/src/Display/DataPath.hpp diff --git a/demo/Display/DearImGui.cpp b/demo/src/Display/DearImGui.cpp similarity index 100% rename from demo/Display/DearImGui.cpp rename to demo/src/Display/DearImGui.cpp diff --git a/demo/Display/DearImGui.hpp b/demo/src/Display/DearImGui.hpp similarity index 100% rename from demo/Display/DearImGui.hpp rename to demo/src/Display/DearImGui.hpp diff --git a/demo/Display/Draw.cpp b/demo/src/Display/Draw.cpp similarity index 100% rename from demo/Display/Draw.cpp rename to demo/src/Display/Draw.cpp diff --git a/demo/Display/IGame.hpp b/demo/src/Display/IGame.hpp similarity index 100% rename from demo/Display/IGame.hpp rename to demo/src/Display/IGame.hpp diff --git a/demo/Display/SDLHelper.cpp b/demo/src/Display/SDLHelper.cpp similarity index 100% rename from demo/Display/SDLHelper.cpp rename to demo/src/Display/SDLHelper.cpp diff --git a/demo/Display/SDLHelper.hpp b/demo/src/Display/SDLHelper.hpp similarity index 100% rename from demo/Display/SDLHelper.hpp rename to demo/src/Display/SDLHelper.hpp diff --git a/demo/Display/Window.cpp b/demo/src/Display/Window.cpp similarity index 100% rename from demo/Display/Window.cpp rename to demo/src/Display/Window.cpp diff --git a/demo/Display/Window.hpp b/demo/src/Display/Window.hpp similarity index 100% rename from demo/Display/Window.hpp rename to demo/src/Display/Window.hpp diff --git a/demo/Listeners.cpp b/demo/src/Listeners.cpp similarity index 100% rename from demo/Listeners.cpp rename to demo/src/Listeners.cpp diff --git a/demo/main.cpp b/demo/src/main.cpp similarity index 91% rename from demo/main.cpp rename to demo/src/main.cpp index 2cc959b..a590e1e 100644 --- a/demo/main.cpp +++ b/demo/src/main.cpp @@ -11,21 +11,19 @@ #include "OpenGlassBox/Config.hpp" //------------------------------------------------------------------------------ -# ifndef DATADIR -# define GET_DATA_PATH project::info::data_path -# endif -# if defined(__APPLE__) -# define GET_DATA_PATH DATADIR":" + osx_get_resources_dir("") -# elif defined(__EMSCRIPTEN__) -# define GET_DATA_PATH "data/" -# else -# define GET_DATA_PATH DATADIR -# endif +#undef GET_DATA_PATH +#if defined(__APPLE__) +# define GET_DATA_PATH osx_get_resources_dir("") +#else +# define GET_DATA_PATH project::info::data_path +#endif //------------------------------------------------------------------------------ GlassBox::GlassBox() : m_path(GET_DATA_PATH), m_simulation(12u, 12u) -{} +{ + std::cout << "Search paths: " << m_path.toString() << std::endl; +} //------------------------------------------------------------------------------ void GlassBox::onRelease(SDL_Renderer&) diff --git a/demo/main.hpp b/demo/src/main.hpp similarity index 100% rename from demo/main.hpp rename to demo/src/main.hpp diff --git a/external/download-external-libs.sh b/external/download-external-libs.sh index adf1f9e..2193e45 100755 --- a/external/download-external-libs.sh +++ b/external/download-external-libs.sh @@ -1,37 +1,19 @@ #!/bin/bash -e +############################################################################### +### This script is called by (cd .. && make download-external-libs). It will +### git clone thirdparts needed for this project but does not compile them. +### It replaces git submodules that I dislike. +############################################################################### -### This script will git clone some libraries that OpenGlassBox needs and -### compile them. To avoid pollution, they are not installed into your -### environement. Therefore OpenGlassBox Makefiles have to know where to -### find their files (includes and static/shared libraries). +source $1 -### $1 is given by ../Makefile and refers to the current architecture. -if [ "$1" == "" ]; then - echo "Expected one argument. Select the architecture: Linux, Darwin or Windows" - exit 1 -fi -ARCHI="$1" -TARGET="$2" - -### Delete all previous directories to be sure to have and compile -### fresh code source. -rm -fr imgui_sdl imgui 2> /dev/null - -function print-clone -{ - echo -e "\033[35m*** Cloning:\033[00m \033[36m$TARGET\033[00m <= \033[33m$1\033[00m" -} - -### Library for creating GUI in OpenGL +### Bloat-free Graphical User interface for C++ with minimal dependencies ### License: MIT -print-clone imgui -git clone https://github.com/ocornut/imgui.git > /dev/null 2> /dev/null -(cd imgui && git reset --hard f9b873662baac2388a4ca78c967e53eb5d83d2a1) +cloning ocornut/imgui -b docking +(cd imgui && git fetch --unshallow && git reset --hard f9b873662baac2388a4ca78c967e53eb5d83d2a1) ### ImGuiSDL: SDL2 based renderer for Dear ImGui ### License: MIT -### FIXME: No longer needed since now integrated directly inside imgui -print-clone imgui_sdl -git clone https://github.com/Tyyppi77/imgui_sdl.git --depth=1 > /dev/null 2> /dev/null +cloning Tyyppi77/imgui_sdl cp imgui_sdl/imgui_sdl.cpp imgui/imgui_sdl.cpp cp imgui_sdl/imgui_sdl.h imgui/imgui_sdl.h diff --git a/tests/Makefile b/tests/Makefile index 009cabc..dc74c52 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,35 +1,32 @@ -PROJECT = OpenGlassBox -TARGET = $(PROJECT)-UnitTest -DESCRIPTION = Unit tests for $(PROJECT) -BUILD_TYPE = debug -STANDARD = --std=c++14 -USE_COVERAGE = 1 - +################################################### +# Location of the project directory and Makefiles +# P := .. M := $(P)/.makefile -include $(M)/Makefile.header - -VPATH += $(P) $(P)/src -INCLUDES += -I$(P) -I$(P)/include -OBJS += Simulation.o Map.o City.o Unit.o Path.o Agent.o Resource.o Resources.o Rule.o -OBJS += MapCoordinatesInsideRadius.o MapRandomCoordinates.o RuleCommand.o RuleValue.o -OBJS += ScriptParser.o Dijkstra.o -OBJS += TestsResource.o TestsResources.o TestsUnit.o TestsPath.o TestsMap.o TestsCity.o -OBJS += TestsAgent.o TestsCoordInsideRadius.o TestsValue.o TestsCommand.o TestsScriptParser.o -OBJS += TestsSimulation.o -OBJS += main.o +################################################### +# Project definition +# +include $(P)/Makefile.common +TARGET_NAME := $(PROJECT_NAME)-tests +TARGET_DESCRIPTION := Unit tests for $(PROJECT_NAME) +COMPILATION_MODE := test +include $(M)/project/Makefile +################################################### +# Compile the unit tests +# +SRC_FILES := $(call rwildcard,$(P)/src,*.cpp) \ + $(call rwildcard,$(P)/tests,*.cpp) +INCLUDES := $(P)/include +VPATH := $(P)/src DEFINES += -DVIRTUAL=virtual -DDESIRED_GRID_SIZE=2u -DEFINES += -Wno-unused-function -Wno-undef -Wno-keyword-macro -Wno-float-equal -Wno-gnu-zero-variadic-macro-arguments +USER_CXX_FLAGS += -Wno-unused-function -Wno-undef \ + -Wno-keyword-macro -Wno-float-equal \ + -Wno-gnu-zero-variadic-macro-arguments PKG_LIBS += gtest gmock -all: $(TARGET) - -.PHONY: unit-tests -.PHONY: check -unit-tests check: $(TARGET) - @$(call print-to,"Running","$(TARGET)","$(RAPPORT)","") - $(SANITIZER) ./$(BUILD)/$(TARGET) $(TU_OPTIONS) || (cat $(TARGET).log; return 1) - -include $(M)/Makefile.footer +################################################### +# Generic Makefile rules +# +include $(M)/rules/Makefile \ No newline at end of file