AutotoolsDeps

AutotoolsDeps 是 Autotools 的依赖生成器。它将生成包含环境变量定义的 shell 脚本,autotools 构建系统可以理解这些脚本。

它可以在conanfile中通过名称使用

conanfile.py
class Pkg(ConanFile):
    generators = "AutotoolsDeps"
conanfile.txt
[generators]
AutotoolsDeps

它也可以在 conanfile 的 generate() 方法中完全实例化

from conan import ConanFile
from conan.tools.gnu import AutotoolsDeps

class App(ConanFile):
    settings = "os", "arch", "compiler", "build_type"

    def generate(self):
        tc = AutotoolsDeps(self)
        tc.generate()

生成的文件

它将生成文件 conanautotoolsdeps.shconanautotoolsdeps.bat

$ conan install conanfile.py # default is Release
$ source conanautotoolsdeps.sh
# or in Windows
$ conanautotoolsdeps.bat

这些启动器将定义聚合变量 CPPFLAGS, LIBS, LDFLAGS, CXXFLAGS, CFLAGS,这些变量汇总了所有依赖项信息,包括传递依赖项,并带有类似 -I<path>, -L<path> 等标志。

目前,只有 requires 信息会被生成,tool_requires 信息尚未由此生成器管理。

自定义

要修改计算出的值,您可以访问 .environment 属性,该属性返回一个 Environment 类。

from conan import ConanFile
from conan.tools.gnu import AutotoolsDeps

class App(ConanFile):
    settings = "os", "arch", "compiler", "build_type"

    def generate(self):
        tc = AutotoolsDeps(self)
        tc.environment.remove("CPPFLAGS", "undesired_value")
        tc.environment.append("CPPFLAGS", "var")
        tc.environment.define("OTHER", "cat")
        tc.environment.unset("LDFLAGS")
        tc.generate()

参考

class AutotoolsDeps(conanfile)
property environment
返回:

一个包含计算出的变量的 Environment 对象。如果您需要修改一些计算出的值,您可以访问 environment 对象。