如何为 Qt 项目的一个子目录调用 make install

发布于 2024-09-01 07:31:39 字数 801 浏览 1 评论 0原文

我正在开发自定义库,我希望用户可以通过添加:

CONFIG += mylib

到他们的专业文件来使用它。这可以通过将 mylib.prf 文件安装到 %QTDIR%/mkspec/features 来完成。我已经在 Qt Mobility 项目中查看了如何创建和安装此类文件,但有一件事我想做不同的事情。

如果我正确理解了 Qt Mobility 的 pro/pri 文件,那么在示例项目中,他们并没有真正使用 CONFIG +=mobility,而是添加 QtMobility 源来包含路径并与主库项目共享 *.obj 目录。对于我的库,我希望有尽可能独立的项目示例,即编译和安装 MyLib 后可以从任何地方编译的项目。

我有以下目录结构:

mylib
  |
  |- examples
  |- src
  |- tests
  \- mylib.pro

似乎实现上述目标的最简单方法是像这样创建 mylib.pro:

TEMPLATE = subdirs
SUBDIRS += src
SUBDIRS += examples
tests:SUBDIRS += tests

并在构建 src 后以某种方式强制调用“cd src && make install”。最好的方法是什么?

当然,欢迎在示例编译之前对自动库部署提出任何其他建议。

I'm working on custom library and I wish users could just use it by adding:

CONFIG += mylib

to their pro files. This can be done by installing mylib.prf file to %QTDIR%/mkspec/features. I've checked out in Qt Mobility project how to create and install such file, but there is one thing I'd like to do differently.

If I correctly understood the pro/pri files of Qt Mobility, inside the example projects they don't really use CONFIG += mobility, instead they add QtMobility sources to include path and share the *.obj directory with main library project. For my library I'd like to have examples that are as independent projects as possible, i.e. projects that can be compiled from anywhere once MyLib is compiled and installed.

I have following directory structure:

mylib
  |
  |- examples
  |- src
  |- tests
  \- mylib.pro

It seems that the easiest way to achieve what I described above is creating mylib.pro like this:

TEMPLATE = subdirs
SUBDIRS += src
SUBDIRS += examples
tests:SUBDIRS += tests

And somehow enforce invoking "cd src && make install" after building src. What is the best way to do this?

Of course any other suggestions for automatic library deployment before examples compilation are welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里寻她 2024-09-08 07:31:39

您可以创建另一个目标并将其添加到 SUBDIRS 变量中,如果您意识到普通的 .pro 文件也可以作为目标,那么这种方法会很好用。我建议这样的事情

TEMPLATE = subdirs
CONFIG += ordered

SUBDIRS += src
tests:SUBDIRS += tests
SUBDIRS += src/install.pro
SUBDIRS += examples

在这种情况下,我确保子目录目标将通过配置变量添加按顺序执行。我将测试编译移至安装之前,这对我来说很有意义——您需要在继续安装之前测试代码是否正常工作。重要的补充是源目录中 install.pro 文件的直接链接。 (如果您想保持 src 更干净,您也可以将其放在本地目录中。)其中,您应该有命令来安装您想要安装的组件。

在这种情况下,我发现将源和标头列表分隔在一个文件中通常会有所帮助,该文件可以包含在多个 .pro 文件中,如下所示:

src/sources.pri:

HEADERS += foo.h
SOURCES += foo.c

src/src.pro

include(sources.pri)
#...

src/install .pro

include(sources.pri)
#...

You could make another target and add it to the SUBDIRS variable, which works well if you realize that plain .pro files can also be a target. I would suggest something like this

TEMPLATE = subdirs
CONFIG += ordered

SUBDIRS += src
tests:SUBDIRS += tests
SUBDIRS += src/install.pro
SUBDIRS += examples

In this case, I made sure the subdir targets would be executed in order, via the config variable addition. I moved the tests compile to before the install, which makes sense to me -- you'd want to test that the code is working before going ahead and installing it. The important addition is the direct link to an install.pro file inside your source directory. (You could place this in the local directory also, if you want to keep src cleaner.) In that, you should have your commands to install the components you want installed.

In situations like this, I find it often helps to have the list of sources and headers separated out in a file that could be included in multiple .pro files, as such:

src/sources.pri:

HEADERS += foo.h
SOURCES += foo.c

src/src.pro

include(sources.pri)
#...

src/install.pro

include(sources.pri)
#...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文