I am trying to build a C++ project in Sublime Text 3 on Linux. Normally I just swap to the terminal and run make run and it runs. However, I'm trying to streamline the process by running directly in Sublime. However, pressing Ctrl+Shift+B brings up only two options: Make and Make clean. Both of which will do the command according to my Makefile for the project. However, there is no Make run, so I can't directly run the project by pressing Ctrl+B. I hope someone can provide some insight into this!
Here is my Makefile:
BINARY := build/project
SRCS := $(shell find . -iname "*.cpp")
OBJS := $(addprefix build/,$(SRCS:.cpp=.o))
NEEDED_LIBS :=
CXX := g++ -flto
LD := $(CXX) $(addprefix libs/,$(NEEDED_LIBS))
override CXXFLAGS += -std=c++11
override LDFLAGS += $(CXXFLAGS)
all:$(BINARY)
$(BINARY):$(OBJS) $(addprefix libs/,$(NEEDED_LIBS))
$(LD) $(LDFLAGS) -o $@ $^
build/%.o:%.cpp
$(CXX) -O2 -c $(CXXFLAGS) $< -o $@
run:$(BINARY)
@$(BINARY)
clean:
rm -rf build/*
The default build for this is
Makefile/Make.sublime-build, which looks like this:That is, by default it just runs
Make, but it also has a variant namedCleanthat will runmake cleanas well. In particular, this points out that the list of commands is static and doesn't rely on the actual content of the Makefile in question.What you can do is choose
Tools > Build System > New Build Systemfrom the menu, which will create a new tab and provide a default build system. Select all of that content, and then replace it with a copy of the above so you have a duplicate of the base build system. Then, you can add in additional variants as needed. For example:Once you're done, save the file in the location Sublime defaults to (your
Userpackage) with a custom name, likeCustom Makefile.sublime-buildor such (the location and the extension are the important parts).Once you've done that, you will see your build system appear in the menu under
Tools > Build Systemwith the name that you saved the file as. You can either select the build there to use it, or leave it set as automatic.When you use ctrl+shift+b next, the options from this build system will appear in the list (if the build is set to automatic, you'll see the default options as well).