本文档翻译自:https://docs.conan.io/en/latest/reference/commands/development/build.html

    1. $ conan build [-h] [-b] [-bf BUILD_FOLDER] [-c] [-i] [-t]
    2. [-if INSTALL_FOLDER] [-pf PACKAGE_FOLDER]
    3. [-sf SOURCE_FOLDER]
    4. path

    调用您本地的conanfile.py的”build()”方法。
    配方将建立在–build-folder指定的本地目录中,并从–source-folder中读取源。 如果使用的是诸如CMake()之类的构建帮助器,则–package-folder将被配置为安装步骤的目标文件夹。

    1. positional arguments:
    2. path Path to a folder containing a conanfile.py or to a
    3. recipe file e.g., my_folder/conanfile.py
    4. optional arguments:
    5. -h, --help show this help message and exit
    6. -b, --build Execute the build step (variable should_build=True).
    7. When specified, configure/install/test won't run
    8. unless --configure/--install/--test specified
    9. -bf BUILD_FOLDER, --build-folder BUILD_FOLDER
    10. Directory for the build process. Defaulted to the
    11. current directory. A relative path to the current
    12. directory can also be specified
    13. -c, --configure Execute the configuration step (variable
    14. should_configure=True). When specified,
    15. build/install/test won't run unless
    16. --build/--install/--test specified
    17. -i, --install Execute the install step (variable
    18. should_install=True). When specified,
    19. configure/build/test won't run unless
    20. --configure/--build/--test specified
    21. -t, --test Execute the test step (variable should_test=True).
    22. When specified, configure/build/install won't run
    23. unless --configure/--build/--install specified
    24. -if INSTALL_FOLDER, --install-folder INSTALL_FOLDER
    25. Directory containing the conaninfo.txt and
    26. conanbuildinfo.txt files (from previous 'conan
    27. install'). Defaulted to --build-folder
    28. -pf PACKAGE_FOLDER, --package-folder PACKAGE_FOLDER
    29. Directory to install the package (when the build
    30. system or build() method does it). Defaulted to the
    31. '{build_folder}/package' folder. A relative path can
    32. be specified, relative to the current folder. Also an
    33. absolute path is allowed.
    34. -sf SOURCE_FOLDER, --source-folder SOURCE_FOLDER
    35. Directory containing the sources. Defaulted to the
    36. conanfile's directory. A relative path to the current
    37. directory can also be specified

    build()方法可能使用来自指定配置文件的设置,选项和环境变量,以及来自conanfile要求中已声明的deps_XXX_info对象的依赖项信息。 运行conan install命令时,所有这些信息分别自动保存在conaninfo.txt和conanbuildinfo.txt文件中。 这些文件必须位于指定的—build-folder或—install-folder(如果指定)中。
    —configure,-build,-install参数控制build()的哪些部分实际执行。 它们具有相关的conanfile布尔变量should_configure,should_build,should_install,默认情况下为True,但是如果在命令行中使用其中一些自变量,则这些变量将更改。 CMake和Meson以及AutotoolsBuildEnvironment帮助程序已经使用了这些变量。
    示例:在本地目录中构建conan软件包(对于体系结构x86)。

    conanfile.py

    1. from conans import ConanFile, CMake, tools
    2. class LibConan(ConanFile):
    3. ...
    4. def source(self):
    5. self.run("git clone https://github.com/conan-io/hello.git")
    6. def build(self):
    7. cmake = CMake(self)
    8. cmake.configure(source_folder="hello")
    9. cmake.build()

    首先,我们将调用conan source来在src目录中获取源代码,然后使用conan install来安装需求并生成信息文件,最后通过conan build来构建软件包:

    1. $ conan source . --source-folder src
    2. $ conan install . --install-folder build_x86 -s arch=x86
    3. $ conan build . --build-folder build_x86 --source-folder src

    或者,如果我们想在另一个文件夹中创建conaninfo.txt和conanbuildinfo.txt文件:

    1. $ conan source . --source-folder src
    2. $ conan install . --install-folder install_x86 -s arch=x86
    3. $ conan build . --build-folder build_x86 --install-folder install_x86 --source-folder src

    但是,我们建议在同一–build-folder中生成conaninfo.txt和conanbuildinfo.txt,否则,您将需要在构建系统中指定其他文件夹以包括文件生成器文件。 例如,conanbuildinfo.cmake
    示例:控制构建阶段
    您可以使用—configure/-build/-install/-test参数来控制构建阶段。 这是使用CMake构建助手的示例:

    1. $ conan build . --configure # only run cmake.configure(). Other methods will do nothing
    2. $ conan build . --build # only run cmake.build(). Other methods will do nothing
    3. $ conan build . --install # only run cmake.install(). Other methods will do nothing
    4. $ conan build . --test # only run cmake.test(). Other methods will do nothing
    5. # They can be combined
    6. $ conan build . -c -b # run cmake.configure() + cmake.build(), but not cmake.install() nor cmake.test

    如果未指定任何内容,则将调用所有方法。

    :::info See alse
    阅读更多有关should_configure,should_build,should_install,should_test的信息。 :::