本文档翻译自:https://docs.conan.io/en/latest/reference/commands/development/build.html
$ conan build [-h] [-b] [-bf BUILD_FOLDER] [-c] [-i] [-t]
[-if INSTALL_FOLDER] [-pf PACKAGE_FOLDER]
[-sf SOURCE_FOLDER]
path
调用您本地的conanfile.py的”build()”方法。
配方将建立在–build-folder指定的本地目录中,并从–source-folder中读取源。 如果使用的是诸如CMake()之类的构建帮助器,则–package-folder将被配置为安装步骤的目标文件夹。
positional arguments:
path Path to a folder containing a conanfile.py or to a
recipe file e.g., my_folder/conanfile.py
optional arguments:
-h, --help show this help message and exit
-b, --build Execute the build step (variable should_build=True).
When specified, configure/install/test won't run
unless --configure/--install/--test specified
-bf BUILD_FOLDER, --build-folder BUILD_FOLDER
Directory for the build process. Defaulted to the
current directory. A relative path to the current
directory can also be specified
-c, --configure Execute the configuration step (variable
should_configure=True). When specified,
build/install/test won't run unless
--build/--install/--test specified
-i, --install Execute the install step (variable
should_install=True). When specified,
configure/build/test won't run unless
--configure/--build/--test specified
-t, --test Execute the test step (variable should_test=True).
When specified, configure/build/install won't run
unless --configure/--build/--install specified
-if INSTALL_FOLDER, --install-folder INSTALL_FOLDER
Directory containing the conaninfo.txt and
conanbuildinfo.txt files (from previous 'conan
install'). Defaulted to --build-folder
-pf PACKAGE_FOLDER, --package-folder PACKAGE_FOLDER
Directory to install the package (when the build
system or build() method does it). Defaulted to the
'{build_folder}/package' folder. A relative path can
be specified, relative to the current folder. Also an
absolute path is allowed.
-sf SOURCE_FOLDER, --source-folder SOURCE_FOLDER
Directory containing the sources. Defaulted to the
conanfile's directory. A relative path to the current
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¶
from conans import ConanFile, CMake, tools
class LibConan(ConanFile):
...
def source(self):
self.run("git clone https://github.com/conan-io/hello.git")
def build(self):
cmake = CMake(self)
cmake.configure(source_folder="hello")
cmake.build()
首先,我们将调用conan source来在src目录中获取源代码,然后使用conan install来安装需求并生成信息文件,最后通过conan build来构建软件包:
$ conan source . --source-folder src
$ conan install . --install-folder build_x86 -s arch=x86
$ conan build . --build-folder build_x86 --source-folder src
或者,如果我们想在另一个文件夹中创建conaninfo.txt和conanbuildinfo.txt文件:
$ conan source . --source-folder src
$ conan install . --install-folder install_x86 -s arch=x86
$ 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构建助手的示例:
$ conan build . --configure # only run cmake.configure(). Other methods will do nothing
$ conan build . --build # only run cmake.build(). Other methods will do nothing
$ conan build . --install # only run cmake.install(). Other methods will do nothing
$ conan build . --test # only run cmake.test(). Other methods will do nothing
# They can be combined
$ 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的信息。
:::