supraMan
supraMan

Reputation: 53

Makefile getting all object files in a directory

I currently have a C++ google test project that relies on another program to be built first. In my google test test project makefile I am trying to get all the object files in the project it is testing. So for example:

USER_OBJS = $(PROJECT_BEING_TESTED_PATH)/class1.o
USER_OBJS = $(PROJECT_BEING_TESTED_PATH)/class2.o
USER_OBJS = $(PROJECT_BEING_TESTED_PATH)/class3.o

However, whenever there is a class added or removed to the project that is being tested, then I have to manually change USER_OBJS in my makefile. With automated testing, this is becoming a hassle. Does anyone know how I can make USER_OBJS just get all the object files in the tested project? I have tried the following:

USER_OBJS := $(PROJECT_BEING_TESTED_PATH)/$(wildcard *.o)

Still does not work. Any ideas?

Upvotes: 1

Views: 7190

Answers (2)

Shammel Lee
Shammel Lee

Reputation: 4475

If you only want (class1.o, class2.o, class3.o), use…

USER_OBJS = $(wildcard $(PROJECT_BEING_TESTED_PATH)/class[1-3].o)

If you want all object files, use…

USER_OBJS = $(wildcard $(PROJECT_BEING_TESTED_PATH)/*.o)

Upvotes: 5

Laurent H.
Laurent H.

Reputation: 6526

The right way to use "wildcard" in your case should be:

USER_OBJS = $(wildcard $(PROJECT_BEING_TESTED_PATH)/*.o)

Upvotes: 4

Related Questions