C++ Compiling/Including all files . cpp from the subdirectories of the /src folder

Asked

Viewed 193 times

0

I use Visual Studio Code + Mingw.

My project is the https://github.com/KaueAlves/Grimorie-Tabuleiro

As some IDES link between classes automatically, when using VSCODE I came across the need to pass the compilation parameters.

How do I read all the files .cpp of all directories in /src and then generate the output .exe?

My markfile is currently like this, Focusing it works only on the levels I add to FOLDERS :

#LIBARIES := 
#INCLUDES :=
FOLDERS  := src/*.cpp src/*/*.cpp
FILES    := main.cpp
all:
    g++ -g  -std=c++17  -Wall   $(INCLUDES) $(FOLDERS)  $(FILES)    -o  main

1 answer

0

You can use wildcards for this. It would look something like this (not tested):

src = $(wildcard *.cpp) \
      $(wildcard src/*.cpp) \
      $(wildcard src/pecas/*.cpp)
obj = $(src:.cpp=.o)

CXXFLAGS= -O2 -std=c++17 -Wall

game: $(obj) 
    $(CXX) $(CXXFLAGS) -o $@ $^

.PHONY: clean
clean: 
    rm -f $(obj) game

Furthermore, I strongly recommend that you start using Cmake for your projects. The syntax is more intuitive than GNU Make.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.