Hello, :-)
I'm a "tup first timer”. I decided to give it a try, after I got fed up with cmake taking more time than gcc in many daily tasks.
I stumbled into some problems right away, while trying it on a rather simple project (see the attached archive, source files have been zeroed). The structure is this:
"config_module" is the main (top) directory containing everything. As the name suggests, this is to be ported to C++20 modules in the near future.
Within this directory is a file called "test_config.cpp”, which is a unit test. This is to build the only executable called "test_config", preferably in three possible ways (debug, release and static).
Then there is the directory "src”. In this directory we have the actual config module. This is to be compiled into objects only:
config.hpp
config.cpp
platform_folders.hpp
platform_folders.cpp
I would like to have three build configurations, which are the same for the directories containing the "test_config", as well as the "src" directory:
debug.config: CONFIG_BUILD_TYPE=debug
release.config: CONFIG_BUILD_TYPE=release
static.config: CONFIG_BUILD_TYPE=static
Then I have my universal build rules in a file ("Tuprules.tup") in the "src" directory, which is to be included where it's needed:
# Tuprules.tup in config_module/src
ifeq (@(BUILD_TYPE),debug)
# debug build:
CPPFLAGS += -march=native
CPPFLAGS += -ggdb3
CPPFLAGS += -D_GLIBCXX_DEBUG
else
ifeq (@(BUILD_TYPE),release)
CPPFLAGS += -march=native
CPPFLAGS += -O2
LDFLAGS += --as-needed -flto
else
ifeq (@(BUILD_TYPE),static)
CPPFLAGS += -static -Os
LDFLAGS += --as-needed -flto
else
error "Build type not set or wrong!"
endif
endif
endif
I did put a "Tupfile" in the "src" directory, which contained this:
# Tupfile in config_module/src
CPPFLAGS += -std=c++17
CPPFLAGS += -Wall
LDFLAGS += -lstdc++fs
include_rules
: foreach *.cpp |> g++ $(CPPFLAGS) -c %f -o %o |> %B.o
This works well when I call "init" in the "src" directory!
In the top directory (for building the unit test executable) I have this in a Tupfile:
# Tupfile in config_module
PROG_NAME = test_config
MY_CONFIG_FOLDER = $(TUP_CWD)/debug_config_folder
CPPFLAGS += -std=c++17
CPPFLAGS += -Wall
CPPFLAGS += -Isrc
include_rules
: foreach *.cpp |> g++ $(CPPFLAGS) -D$(MY_CONFIG_FOLDER) -c %f -o %o |> %B.o
# doesn't work : *.o |> gcc %f -o %o -Wl,$(LDFLAGS) |> $(PROG_NAME)
: *.o |> gcc %f -o %o -Wl,$(LDFLAGS) |> test_config
When I remove the ".tup" from the "src" directory and instead "init" the top directory, neither work.
To be clear: When running "tup build-debug" in the "src" directory, I want it to compile "config.cpp" and "platform_folders.cpp" into ".o" files within the "build-debug" directory under the "src" directory.
When running "tup build-debug" in the top directory, it should compile "test_config.cpp" into "test_config.o" and then link it to "test_config", both into the top-level "build-debug" directory.
In case the dependencies from the sub-module/project (in "src") aren't compiled, it should do that first.
I won't even go into my attempts to put a "make clean" function in there. Read-only file access - that was funny... ;-)
Thank you very much for any help!