c++ - 使用 (nobase_)pkginclude_HEADERS 在子目录中安装 header

标签 c++ autotools automake

我在安装头文件时使用 automake 处理子目录时遇到一点问题。

这是我的大致项目层次结构:

foo/
  foo-bin/
    Makefile.am
    ...
  foo-tests/
    Makefile.am
    ...
  foo-lib/
    Makefile.am
    include/
      foo/
        header1.h
        subdir/
          header2.h
    src/
      file1.cpp

没什么特别的,有一个包含 configure.ac 的根目录,以及共享库、主二进制文件和测试的 3 个子目录。

这里有趣的部分是foo-lib/。它包含二进制文件和测试链接到的库。

因为我希望能够从源代码树中生成配置文件,所以我决定在我的 Makefile.am 中使用 $top_srcdir 相对路径.

这是它的样子:

libfoo_la_SOURCES = \
  $(top_srcdir)/foo-lib/src/file1.cpp

pkginclude_HEADERS = \
  $(top_srcdir)/foo-lib/include/foo/header1.h \
  $(top_srcdir)/foo-lib/include/foo/subdir/header2.h

如果没有这些 $top_srcdir 相对路径,当我尝试使用 foo-bin 中的 foo-lib 时会遇到问题,或者当我尝试从源代码树中生成项目时。

现在的问题是:在安装这些 header 时,它们最终被压扁了! 也就是说,我最终得到:

$prefix/include/foo/header1.h
$prefix/include/foo/header2.h

当我期待的时候:

$prefix/include/foo/header1.h
$prefix/include/foo/subdir/header2.h

所以我假设这就是 nobase_ 应该实现的,但是因为我使用的路径不是相对于 Makefile.am,而是相对于 $ top_srcdir,我最终复制了整个 $top_srcdir 路径:

$prefix/include/foo-lib/include/foo/header1.h
$prefix/include/foo-lib/include/foo/subdir/header2.h

这显然不是预期的。

非常感谢对此的任何想法和建议:) 如果您需要访问真正的 Makefile.am 文件,而不是规范示例,该项目在这里:

https://github.com/NewbiZ/crashburn

最佳答案

这个:

pkginclude_HEADERS = \
$(top_srcdir)/foo-lib/include/foo/header1.h \
$(top_srcdir)/foo-lib/include/foo/subdir/header2.h

告诉安装将上面的 header 放在 $(pkgincludedir) 中,所以扁平化是您告诉它们的方式。

你可以做的是:

myincludesubdir=$(pkgincludedir)/subdir

pkginclude_HEADERS = $(top_srcdir)/foo-lib/include/foo/header1.h
myincludesub_HEADERS = $(top_srcdir)/foo-lib/include/foo/subdir/header2.h

这应该将 header1.h 安装到 $(pkgincludedir) 并将 header2.h 安装到 $(myincludesubdir) 又名 $(pkgincludedir)/subdir

在这种情况下我不会使用 nobase_。你使用它得到的结果对我来说并不出乎意料或错误。

关于c++ - 使用 (nobase_)pkginclude_HEADERS 在子目录中安装 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22533504/

相关文章:

c++ - 在 autoconf 中检查仅 header 库

c++ - 自动工具编译器

autotools - 如何在 make 时将 shell 脚本输出放入 Makefile.am 中?

c++ - 在源文件中内联

c++ - 在 C++ 成员函数中引用指针

c++ - 无法运行 Makefile.am,我该怎么办?

c - gengetopt 和 Automake

configuration - 如何禁用Automake文档?

c++ - Mysql 连接器 C++ 无缓冲结果集 C++

c++ - 我的自定义命名空间的链接器错误