我有一个项目,链接到一些共享库。
假设项目A取决于项目B和C.
理想情况下,我想在我的项目文件中强加以下依赖项:
>重建项目A,如果自上次构建项目A以来B或C已重建
>使用相关配置的输出(即如果在调试模式下构建项目A,则使用项目B和C的lib的调试版本)
有人知道我可以明确地表示这种依赖项在我的项目文件吗?
经过相当多的挫折qmake,我发现我认为是你的问题的答案。如果没有,那么我学会了如何使用qmake,直到我找到更好的东西,因为这仍然有点丑。我设置了一个demo项目,这是我的目录结构(文件有扩展名,文件夹不):
原文链接:https://www.f2er.com/javaschema/282701.htmlMyProj MyProj.pro myproj-core myproj-core.pro globals.h MyProjCore.h MyProjCore.cpp myproj-app myproj-app.pro main.cpp
我们从MyProj.pro开始作为subdirs项目,这是做你要求的关键。基本上,而不是依赖于其他项目来指定调试/版本和各种其他垃圾,你只需将其设置在一个qmake文件。它不让你做你所需要的,但它是我可以想出的最好的解决方案。这里是内容:
TEMPLATE = subdirs # Needed to ensure that things are built right,which you have to do yourself :( CONFIG += ordered # All the projects in your application are sub-projects of your solution SUBDIRS = myproj-core \ myproj-app # Use .depends to specify that a project depends on another. myproj-app.depends = myproj-core
myproj-core.pro是你典型的共享对象库:
QT -= gui TARGET = myproj-core TEMPLATE = lib DEFINES += MYPROJCORE_LIBRARY SOURCES += MyProjCore.cpp HEADERS += MyProjCore.h \ globals.h
myproj-app.pro是消费者应用程序,其中小的重建需要的技巧是:
QT -= gui TARGET = myproj-app CONFIG += console CONFIG -= app_bundle TEMPLATE = app # Specify that we're lookin in myproj-core. Realistically,this should be put # in some configuration file INCLUDEPATH += ../myproj-core # Link to the library generated by the project. Could use variables or # something here to make it more bulletproof LIBS += ../myproj-core/libmyproj-core.so # Specify that we depend on the library (which,logically would be implicit from # the fact that we are linking to it) PRE_TARGETDEPS += ../myproj-core/libmyproj-core.so SOURCES += main.cpp
编辑:我做了一个专门为我构建依赖项的文件,我将它存储在我的每个项目(在上面指定的目录结构中的MyProj的子项)的兄弟文件夹中称为dependencies.pri:
# On windows,a shared object is a .dll win32: SONAME=dll else: SONAME=so # This function sets up the dependencies for libraries that are built with # this project. Specify the libraries you need to depend on in the variable # DEPENDENCY_LIBRARIES and this will add for(dep,DEPENDENCY_LIBRARIES) { #message($$TARGET depends on $$dep ($${DESTDIR}/$${dep}.$${SONAME})) LIBS += $${DESTDIR}/lib$${dep}.$${SONAME} PRE_TARGETDEPS += $${DESTDIR}/lib$${dep}.$${SONAME} }
DEPENDENCY_LIBRARIES = myproj-core include(../config/dependencies.pri)