qmake SUBDIRS Project Automatic Dependencies

Here’s what I searched for, before figuring out how to get SUBDIRSdependencies working using qmake:

“qmake export compiler flags”
“qmake export defines”
“qmake export includepath”
“qmake build dependent projects”
“qt creator automatically build dependent libraries”

Problem 1: Detecting Dependency Changes

Qt Creator has some weird behaviors. As in, it doesn’t properly do dependent library builds all of the time, particularly when you’re using a SUBDIRS project template. I noticed that I would always have to right-click a project and “Run qmake” before running “Build X Project”, which was annoying. And I noticed that libraries wouldn’t automatically build and link to their consuming executables. It didn’t make sense, as I had used the “Add Library” option to add configuration blocks, like the following, to the executable project files that needed them:

win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../SomeLibrary/release/ -lSomeLibrary
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../SomeLibrary/debug/ -lSomeLibrary
else:unix: LIBS += -L$$OUT_PWD/../SomeLibrary/ -lSomeLibraryINCLUDEPATH += $$PWD/../SomeLibrary/source
DEPENDPATH += $$PWD/../SomeLibrary/sourcewin32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../SomeLibrary/release/SomeLibrary.lib
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../SomeLibrary/debug/SomeLibrary.lib
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../SomeLibrary/libSomeLibrary.a

Once that block was in place, I figured all would be good. However, all that Qt Creator would do is tell me was thatlibSomeLibrary.a wasn’t available, if I’d run a Clean on all of the projects, rather than just building and linking it for me. As in, makewould know the library file was missing (via the TARGET_PREDEPSsetting), but it would be too stupid to just build that target. And it wasn’t clear that any changes to SomeLibrary were being built and linked into the consuming executable, since SomeLibrary wasn’t getting autobuilt as a dependency. It seemed like old SomeLibrarycode was getting linked instead, and only the executable’s changed code was getting recompiled before the link. This was a dependency nightmare in the making.

On all of these particular points, the qmake manual does not clarify that SUBDIRS projects are essentially a completely different beast, and require different rules to set up.

Not so useful.

The way to properly define dependencies in a SUBDIRS project is to use a master Project file that looks something like:

cache()TEMPLATE = subdirsSUBDIRS += \ConsoleTest \        # an "app" projectSomeLibrary \        # a  "lib" projectSomeExternalLibrary  # a  "lib" project# ConsoleTest.subdir is implicitly set to "ConsoleTest".SomeLibrary.subdir         = SomeLibrary
SomeExternalLibrary.subdir = external/SomeExternalLibrary# Here's where you build up the hierarchical relationship between components.SomeLibrary.depends = SomeExternalLibrary
ConsoleTest.depends = SomeLibrary

This is all you need to do. The next time the project file is parsed and qmake is run to generate the platform-specific Makefiles, it will generate the dependencies properly. No more weird builds and dependency problems. As much as I appreciate Qt’s awesome software, this is something they really need to clarify how to get working in their manual.

Problem 2: Exporting DEFINES and INCLUDEPATH

In addition to the above, the method to set up the various projects to export the qmake DEFINES and INCLUDEPATH flags used to build them was not clear from the documentation.

What you want in a hierarchical project configuration, ideally, is that the whole project rebuilds if any of the library sources, includes, included folders, or compiler DEFINES changes. You want any library consumers to use the exact same settings used to build the libraries, and you want this to happen if the setting changes in a single, authoritative place (preferably the library build configuration). The only reference I could find to “library dependencies” in the qmake manual is not clear as to its mechanism for propagating this information, particularly theINCLUDEPATH and DEFINES settings.

After reading a handful of other references (1), (2), I finally figured out how to do this. It turns out that qmake has a lot of power to it, but that power is buried in bad documentation. (Why does no one invest in documentation? It’s an excellent opportunity to generate goodwill.)

The trick is twofold:

For each library project, you need to split the declaration ofDEFINES and INCLUDEPATH into a Defines.pri file at the same level as the .pro Project file, for example:

/SomeLibrary
/SomeLibrary/SomeLibrary.pro
/SomeLibrary/Defines.pri

In Defines.pri, add the DEFINES and INCLUDEPATH settings:

DEFINES += SOME_COMPILER_SETTINGmessage(Including $$_FILE_ from $$IN_PWD)
INCLUDEPATH += $$IN_PWD/source

In SomeLibrary.pro, add

include(Defines.pri)

In any other project, include the DEFINES and INCLUDEPATH settings using a similar include:

include(/SomeLibrary/Defines.pri)

You should then see something like "Including /SomeLibrary/Defines.pri from /SomeLibrary" show up in the General Messages window in Qt Creator, when the project files are reparsed, meaning that the dependent project pulled in these settings properly. In this way, any changes made to the Defines.priwill get propagated to the consuming projects.

So that’s it. Good luck.

Update

After some experimentation, you still need to “Add Library” the static library configuration blocks to the .pro project file of any consuming executables, for some reason when I tried moving these configuration blocks from the executable .pro files to the library .pri files, qmake started getting stuck in an infinite loop.

Omitting these configuration blocks will also cause the executables not to link. I don’t think I’m going to investigate this more closely, since solving the includeable DEFINES/INCLUDEPATH problem took care of a bigger build consistency issue. (But maybe I’ll come back to it.)

Thank you for browsing my blog

Original from https://vilimpoc.org/blog/2014/02/21/qmake-subdirs-project-automatic-dependencies/

转载于:https://blog.51cto.com/844133395/1795590

QMake Automatic Dependencies相关推荐

  1. RPM打包探索(rpm-max翻译整理)

    1. %global 和 %define 的区别? 这是内置宏,%define用来定义宏,%global用来定义一个全局可见的宏(在整个spec文件中可见) 2. %{!?macro-name} 和 ...

  2. EAR工程在jboss(wildfly)里的结构以及class loading关系

    EAR , WAR ,JAR EAR , WAR ,JAR 实际上都可以看成是文件夹,只是里面的组成规则不一样而已 WAR 工程结构 - META-INF- WEB-INF- classes- lib ...

  3. C++Qt中qmake的详解

    1.首先,感性的认识是,qmake可以利用源文件(包括头文件h,实现文件cpp,qt的ui文件等等)生成各种不同类型的工程,工程需要的Makefile文件,可执行的与不可执行的,这取决于所用的模板(包 ...

  4. qmake手册(Qt5.9.3)

    qmake手册 qmake手册 概观 描述一个项目 建立一个项目 使用第三方库 预编译头文件 入门 从简单的开始 使应用程序可调试 添加平台特定的源文件 如果文件不存在停止qmake 检查多个条件 创 ...

  5. Missing dependencies in the kernel

    Le Farfadet Spatial n00b 注册时间: 2011-01-03 帖子: 70 发表于: Sat Jul 16, 2011 12:02 pm    发表主题: [Solved] Mi ...

  6. 验证环境中的program为什么必须是automatic

    最近在项目中,发现验证环境中的顶层的program(一般将program作为验证环境的入口),都是automatic的. 其实Program默认是static的,那么为什么需要把验证环境做成autom ...

  7. qmake 简易教程

    qmake 简易教程 qmake是Qt开发中默认的构建工具. posted on 2018-05-27 00:09 JichengTang 阅读(...) 评论(...) 编辑 收藏 转载于:http ...

  8. 棋盘格检测--Automatic camera and range sensor calibration using a single shot

    Automatic camera and range sensor calibration using a single shot Robotics and Automation (ICRA), IE ...

  9. 图像拼接--Automatic Panoramic Image Stitching using Invariant Features

    Automatic Panoramic Image Stitching using Invariant Features <International Journal of Computer V ...

最新文章

  1. java 图片灰度化
  2. IC/FPGA笔试/面试题分析(八)近期IC/FPGA笔试面试讨论群题目汇总解析
  3. 解决ssh远程连接错误问题
  4. leetcode 111. 二叉树的最小深度
  5. live555源代码简介
  6. 信息学奥赛一本通 2071:【例2.14】平均分
  7. 每天一道剑指offer-链表中第k个节点
  8. C语言线程实例(生产者和消费者),Java多线程:生产者与消费者(1)
  9. sql mysql 删除数据库_如何清除SQL数据库中的数据?
  10. linux手动rpm升级glibc,升级glibc库到glibc-2.14.1
  11. 搭建git服务器 web项目,git服务器搭建web项目
  12. 短视频剪辑的九大技巧分享
  13. JGROUPS JGRP000029问题
  14. 正则匹配大于等于号与indexof结合
  15. 幽灵蛛(pholcus)(三)--goquery学习资料
  16. 奇迹般地修复损坏的Windows、苹果双系统
  17. ios云信不能全屏_网易云信-新增自定义消息(iOS版)
  18. python蓝桥杯省赛冲刺篇——3真题:答疑、鲁卡斯队列、金币、最大化股票交易的利润、谈判、排座椅
  19. “苹果”在中国的血汗工厂
  20. Smmu硬件寄存器—V2

热门文章

  1. java const string_深入研究Java String
  2. pandas 根据列名索引多列数据_Pandas 数据聚合与分组运算[groupby+apply]速查笔记
  3. 远控免杀专题3---msf自免杀
  4. uva 1331——Minimax Triangulation
  5. redis源码剖析(十四)—— dump.rdb文件分析工具
  6. 事务隔离级别动图演示
  7. 数据分割-并查集+set
  8. 【Linux】Ubuntu 18下安装Vim自动补全插件YouCompleteMe(可高速下载安装)
  9. java操作word文档,深度解析,值得收藏
  10. 大牛手把手教你!2021大厂Java面试经历