c++ - How to use qmake file with google test and shared library -


i started makefile generate dependencies of c++ files. c++ project using google test. later, started qt project uses qmake , links shared library old makefile builds. needless say, old makefile complicated now.

i make qmake file can following:

  • build shared library list sources
  • build google test (optionally, accept separate makefile this)
  • build qt executable different list of sources linking first shared library
  • all builds should have debug , release versions output different directories

can point me in right direction making *.pro file that? i'm not clear on how things multiple targets in qmake.

here current makefile using (clearly mess):

gtest_dir = /home/matt/lib/gtest-1.5.0 gmock_dir = /home/matt/lib/gmock-1.5.0 src_dir = /home/matt/documents/myproject  qtinc := -i/usr/share/qt4/mkspecs/linux-g++ -i/usr/include/qt4/qtcore \     -i/usr/include/qt4/qtgui -i/usr/include/qt4  test_srcs = test/testrunner.cpp test/celltest.cpp test/puzzletest.cpp \     test/singlecandidatemethodtest.cpp test/exclusionmethodtest.cpp \     test/blockintersectionmethodtest.cpp test/coveringsetmethodtest.cpp \     test/simplevalidatortest.cpp test/puzzlemarkertest.cpp \     test/playervalidatortest.cpp test/solverhelpertest.cpp \     test/guesscommandtest.cpp test/markcommandtest.cpp \     test/unmarkcommandtest.cpp test/methodsolvertest.cpp \     test/simplepuzzleimportertest.cpp test/solvedpuzzleimportertest.cpp \     test/addhintmarkscommandtest.cpp test/cellcontrollertest.cpp \     test/puzzlecontrollertest.cpp qt_srcs =  lib_srcs = puzzle.cpp cell.cpp singlecandidatemethod.cpp exclusionmethod.cpp \     blockintersectionmethod.cpp coveringsetmethod.cpp simplevalidator.cpp \     puzzlemarker.cpp playervalidator.cpp solverhelper.cpp guesscommand.cpp \     markcommand.cpp unmarkcommand.cpp methodsolver.cpp \     simplepuzzleimporter.cpp solvedpuzzleimporter.cpp gamemanager.cpp \     cellcontroller.cpp addhintmarkscommand.cpp gamecontroller.cpp \     puzzlecontroller.cpp  depdir = .deps df = $(depdir)/$(@f)  # preprocessor cppflags += -i$(gtest_dir)/include -i$(gmock_dir)/include -i$(src_dir) $(qtinc)  # c++ compiler cxxflags = -wall -std=c++0x # qt defines qtdef = -d_reentrant -dqt_no_debug -dqt_gui_lib -dqt_core_lib -dqt_shared # stuff link qt qtflags = -l/usr/lib -lqtcore -lqtgui -lpthread  # gtest headers, don't need change gtest_headers = $(gtest_dir)/include/gtest/*.h \                 $(gtest_dir)/include/gtest/internal/*.h # gmock stuff, don't need change gmock_headers = $(gmock_dir)/include/gmock/*.h \                 $(gmock_dir)/include/gmock/internal/*.h \                 $(gtest_headers)  makedepend = $(cxx) $(cppflags) -mm -o $(df).d $< makedepend_test = $(cxx) $(cppflags) -mm -o $(df).d -mt $(basename $<).o $< makedepend_qt = $(cxx) $(cppflags) -mm -o $(df).d -mt $(basename $<).o $<  srcs := main.cpp $(lib_srcs) objs := $(srcs:%.cpp=%.o) lib_objs := $(lib_srcs:%.cpp=%.o) qt_objs := $(qt_srcs:%.cpp=%.o) test_objs := $(test_srcs:%.cpp=%.o)  # targets: debug : cxxflags += -g -o0 # removed warning because sucks: -wconversion (int size_t!) debug_warn : cxxflags += -pedantic -wextra  debug_warn : debug debug : release : cxxflags += -o2 release :  lib : cxxflags += -fpic lib : libsudokulib.so  libsudokulib.so : $(lib_objs)     $(cxx) $(cppflags) $(cxxflags) -shared -o libsudokulib.so $(lib_objs)  : sudoku run_tests  sudoku : $(objs) $(qt_objs)     $(cxx) $(cppflags) $(qtdef) $(cxxflags) $(qtflags) $^ -o $@  run_tests : $(lib_objs) $(test_objs) gtest.a gmock.a     $(cxx) $(cppflags) $(cxxflags) -lpthread $^ -o $@  # dependency stuff .d_target:     mkdir -p $(depdir)     touch $@  .precious: .d_target  # gtest building stuff don't touch me gtest_srcs_ = $(gtest_dir)/src/*.cc $(gtest_dir)/src/*.h $(gtest_headers) gmock_srcs_ = $(gmock_dir)/src/*.cc $(gmock_headers)  gtest-all.o : $(gtest_srcs_)     $(cxx) $(cppflags) -i$(gtest_dir) -i$(gmock_dir) $(cxxflags) -c \            $(gtest_dir)/src/gtest-all.cc  gmock-all.o : $(gmock_srcs_)     $(cxx) $(cppflags) -i$(gtest_dir) -i$(gmock_dir) $(cxxflags) \             -c $(gmock_dir)/src/gmock-all.cc  gmock_main.o : $(gmock_srcs_)     $(cxx) $(cppflags) -i$(gtest_dir) -i$(gmock_dir) $(cxxflags) \             -c $(gmock_dir)/src/gmock_main.cc  gmock.a : gmock-all.o gtest-all.o     $(ar) $(arflags) $@ $^  gtest_main.o : $(gtest_srcs_)     $(cxx) $(cppflags) -i$(gtest_dir) $(cxxflags) -c \            $(gtest_dir)/src/gtest_main.cc  gtest.a : gtest-all.o     $(ar) $(arflags) $@ $^  gtest_main.a : gtest-all.o gtest_main.o     $(ar) $(arflags) $@ $^  # qt stuff %qt.o : %qt.o .d_target     $(makedepend_qt);     @cp $(df).d $(df).p; #   sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ #       -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).p;      @rm -f $(df).d     $(cxx) $(cppflags) $(qtdef) $(cxxflags) -o $@ -c $<  # tests %test.o : %test.cpp .d_target $(gmock_headers)     $(makedepend_test);     @cp $(df).d $(df).p; #   sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ #       -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).p;      @rm -f $(df).d     $(cxx) $(cppflags) $(cxxflags) -o $@ -c $<  # objects sources %.o : %.cpp .d_target     $(makedepend);     @cp $(df).d $(df).p; \ #   sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ #       -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).p;      @rm -f $(df).d     $(cxx) $(cppflags) $(cxxflags) -o $@ -c $<  -include $(qt_srcs:%.cpp=$(depdir)/%.o.p) -include $(test_srcs:test/%.cpp=$(depdir)/%.o.p) -include $(srcs:%.cpp=$(depdir)/%.o.p)  clean:     $(rm) $(objs) $(test_objs) $(qt_objs) \         gtest.a gtest_main.a gtest-all.o gtest_main.o \         .d_target sudoku run_tests     rm -rf $(depdir) 

and here project.pro file qmake (which relies on first makefile instead of building library itself)

template = app target = qtsudoku dependpath += . includepath += . ../myproject config += qt warn_on debug qmake_cxxflags += -std=c++0x libs += -l/home/matt/documents/myproject -lsudokulib  # input headers += qtpuzzlemodel.h qtpuzzleview.h qtgameapplication.h qtdirector.h \     qtmainwindow.h qtfactory.h sources += main.cpp qtpuzzlemodel.cpp qtgameapplication.cpp qtdirector.cpp \     qtmainwindow.cpp qtfactory.cpp 

in general, way subdirs qmake template. make qmake file each of items want build (shared library, google test, , executable), make subdirs template in order. think subdirs template provide debug/release flags each underlying make file.

for shared library, qmake library template should fine.

i don't know google test, assume generate qmake file if desired, or continue makefile.

for linking two, make qmake file has main.cpp, specifies others libraries, , builds executable.

you can use destdir, moc_dir, objects_dir, , ui_dir change generated files go.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -