Last active
October 7, 2024 18:16
-
-
Save mishurov/8134532 to your computer and use it in GitHub Desktop.
Makefile to build QT projects (Linux) without qmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC=g++ | |
MOC=moc-qt4 | |
CFLAGS=-Wall | |
SOURCES=hello.cc hello_cls.cc | |
MOC_HEADERS=hello_cls.h | |
EXECUTABLE=hello | |
INCDIRS=-I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore | |
LIBS=-lQtCore -lQtGui | |
# Change postfixes | |
MOC_SOURCES=$(MOC_HEADERS:.h=.moc.cc) | |
OBJECTS=$(SOURCES:.cc=.o) $(MOC_SOURCES:.cc=.o) | |
all: $(EXECUTABLE) | |
@echo Done! | |
$(EXECUTABLE): $(OBJECTS) | |
$(CC) $^ $(LIBS) -o $@ | |
# Generate object files, rule to change postfix | |
%.o: %.cc | |
$(CC) $(CFLAGS) $(INCDIRS) -c $< -o $@ | |
# Generate cc from h via Qt's Meta Object Compiler, rule to change postfix | |
%.moc.cc: %.h | |
$(MOC) $(INCDIRS) $< -o $@ | |
.PHONY: tags clean | |
clean: | |
rm *.o | |
# Generate ctags file for all included files (autocomplete and jump to source) | |
tags: | |
gcc -M $(INCDIRS) $(SOURCES) | \ | |
sed -e 's/[\\ ]/\n/g' | \ | |
sed -e '/^$$/d' -e '/\.o:[ \t]*$$/d' | \ | |
ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q |
This variant is pretty much useless to anyone doing anything modern, but if you're using Qt2 or Osiris (which is my modernized-ish fork of Qt2.3.2), here's a modified version that should work with Qt2 and Osiris. If using Qt2, change $(OSIRISDIR)
to $(QTDIR)
. You'll still need to manually run uic
before running make if you're using .ui files.
CC=g++
MOC=moc
CFLAGS=-Wall
SOURCES=main.cpp wizard.cpp
MOC_HEADERS=wizard.h
EXECUTABLE=wizard
INCDIRS=-I$(OSIRISDIR)/include
LIBS=-lqt -L$(OSIRISDIR)/lib
# Change postfixes
MOC_SOURCES=$(MOC_HEADERS:.h=.moc.cc)
OBJECTS=$(SOURCES:.cc=.o) $(MOC_SOURCES:.cc=.o)
all: $(EXECUTABLE)
@echo Done!
$(EXECUTABLE): $(OBJECTS)
$(CC) $^ $(INCDIRS) $(LIBS) -o $@
# Generate object files, rule to change postfix
%.o: %.cc
$(CC) $(CFLAGS) $(INCDIRS) -c $< -o $@
# Generate cc from h via Qt's Meta Object Compiler, rule to change postfix
%.moc.cc: %.h
$(MOC) $< -o $@
.PHONY: tags clean
clean:
rm *.o
# Generate ctags file for all included files (autocomplete and jump to source)
tags:
gcc -M $(INCDIRS) $(SOURCES) | \
sed -e 's/[\\ ]/\n/g' | \
sed -e '/^$$/d' -e '/\.o:[ \t]*$$/d' | \
ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q
@habaneropep2019 it is as old as mammoth shite. I'm working on time series rendered on GPU and QML.
@mishurov is there any chance I could get your permission to include your makefile with my Qt fork, under GPLv2 or BSD?
Why even ask that. Sure, of course. I'm not a lawyer. Everything I share, it is for public use.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was very helpful for me #@mroavi. Thank you 👍