c++ conan 配置以来

 

1. conan 的建议

https://docs.conan.io/1/cheatsheet.html

版本控制、修订记录和依赖解析应该在整个公司保持一致。

所有开发者的配置需要保持同步,尤其是软件包id计算模式。在CI/CD系统中,应该始终使用lock文件,以保证构建的可重现性。

2. conan的配置

设置settings

https://docs.conan.io/1/reference/conanfile/attributes.html

class HelloConan(ConanFile):
    settings = {"os": ["Windows"],
        "compiler": {"Visual Studio": {"version": [11, 12]}},
        "arch": None}
settings = "os", "compiler", "build_type", "arch"
def configure(self):
    self.settings.compiler["Visual Studio"].remove("runtime")

选项options

https://docs.conan.io/en/latest/reference/conanfile/attributes.html#options

class MyPkg(ConanFile):

    options = {
        "shared": [True, False],
        "option1": ["value1", "value2"],
        "option2": "ANY",
    }

    def configure(self):
        if some_condition:
            self.options.shared = False

requires

class MyLibConan(ConanFile):
    requires = [("hello/0.1@user/testing"),
                ("say/0.2@dummy/stable", "override"),
                ("bye/2.1@coder/beta", "private")]
class HelloConan(ConanFile):
    requires = "pkg/[>1.0 <1.8]@user/stable"

package id

不用的mode有着不同的packge id构建方法 https://docs.conan.io/1/creating_packages/define_abi_compatibility.html

参考package格式

https://docs.conan.io/en/latest/versioning/revisions.html#how-it-works | Reference | Meaning | |——————————————-|—————————————————————| | lib/1.0@conan/stable | Latest RREV for lib/1.0@conan/stable | | lib/1.0@conan/stable#RREV | Specific RREV for lib/1.0@conan/stable | | lib/1.0@conan/stable#RREV:PACKAGE_ID | A binary package belonging to the specific RREV | | lib/1.0@conan/stable#RREV:PACKAGE_ID#PREV | A binary package revision PREV belonging to the specific RREV |

config

https://docs.conan.io/1/reference/config_files/conan.conf.html

[log]
run_to_output = True        # environment CONAN_LOG_RUN_TO_OUTPUT
run_to_file = False         # environment CONAN_LOG_RUN_TO_FILE
level = critical            # environment CONAN_LOGGING_LEVEL
# trace_file =              # environment CONAN_TRACE_FILE
print_run_commands = False  # environment CONAN_PRINT_RUN_COMMANDS

[general]
default_profile = default
compression_level = 9                 # environment CONAN_COMPRESSION_LEVEL
sysrequires_sudo = True               # environment CONAN_SYSREQUIRES_SUDO
request_timeout = 60                  # environment CONAN_REQUEST_TIMEOUT (seconds)
default_package_id_mode = semver_direct_mode # environment CONAN_DEFAULT_PACKAGE_ID_MODE
# parallel_download = 8               # experimental download binaries in parallel
# full_transitive_package_id = 0
# retry = 2                           # environment CONAN_RETRY
# retry_wait = 5                      # environment CONAN_RETRY_WAIT (seconds)
# sysrequires_mode = enabled          # environment CONAN_SYSREQUIRES_MODE (allowed modes enabled/verify/disabled)
# vs_installation_preference = Enterprise, Professional, Community, BuildTools # environment CONAN_VS_INSTALLATION_PREFERENCE
# verbose_traceback = False           # environment CONAN_VERBOSE_TRACEBACK
# error_on_override = False           # environment CONAN_ERROR_ON_OVERRIDE
# bash_path = ""                      # environment CONAN_BASH_PATH (only windows)
# read_only_cache = True              # environment CONAN_READ_ONLY_CACHE
# cache_no_locks = True               # environment CONAN_CACHE_NO_LOCKS
# user_home_short = your_path         # environment CONAN_USER_HOME_SHORT
# use_always_short_paths = False      # environment CONAN_USE_ALWAYS_SHORT_PATHS
# skip_vs_projects_upgrade = False    # environment CONAN_SKIP_VS_PROJECTS_UPGRADE
# non_interactive = False             # environment CONAN_NON_INTERACTIVE
# skip_broken_symlinks_check = False  # environment CONAN_SKIP_BROKEN_SYMLINKS_CHECK
# revisions_enabled = False           # environment CONAN_REVISIONS_ENABLED

# conan_make_program = make           # environment CONAN_MAKE_PROGRAM (overrides the make program used in AutoToolsBuildEnvironment.make)
# conan_cmake_program = cmake         # environment CONAN_CMAKE_PROGRAM (overrides the make program used in CMake.cmake_program)

# cmake_generator                     # environment CONAN_CMAKE_GENERATOR
# cmake_generator_platform            # environment CONAN_CMAKE_GENERATOR_PLATFORM
# http://www.vtk.org/Wiki/CMake_Cross_Compiling
# cmake_toolchain_file                # environment CONAN_CMAKE_TOOLCHAIN_FILE
# cmake_system_name                   # environment CONAN_CMAKE_SYSTEM_NAME
# cmake_system_version                # environment CONAN_CMAKE_SYSTEM_VERSION
# cmake_system_processor              # environment CONAN_CMAKE_SYSTEM_PROCESSOR
# cmake_find_root_path                # environment CONAN_CMAKE_FIND_ROOT_PATH
# cmake_find_root_path_mode_program   # environment CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM
# cmake_find_root_path_mode_library   # environment CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
# cmake_find_root_path_mode_include   # environment CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE

# msbuild_verbosity = minimal         # environment CONAN_MSBUILD_VERBOSITY

# cpu_count = 1             # environment CONAN_CPU_COUNT

# Change the default location for building test packages to a temporary folder
# which is deleted after the test.
# temp_test_folder = True             # environment CONAN_TEMP_TEST_FOLDER

# cacert_path                         # environment CONAN_CACERT_PATH
# scm_to_conandata                    # environment CONAN_SCM_TO_CONANDATA

# config_install_interval = 1h
# required_conan_version = >=1.26

# keep_python_files = False           # environment CONAN_KEEP_PYTHON_FILES

[storage]
# This is the default path, but you can write your own. It must be an absolute path or a
# path beginning with "~" (if the environment var CONAN_USER_HOME is specified, this directory, even
# with "~/", will be relative to the conan user home, not to the system user home)
path = ./data
# download_cache = /path/to/my/cache

[proxies]
# Empty (or missing) section will try to use system proxies.
# As documented in https://requests.readthedocs.io/en/master/user/advanced/#proxies - but see below
# for proxies to specific hosts
# http = http://user:pass@10.10.1.10:3128/
# http = http://10.10.1.10:3128
# https = http://10.10.1.10:1080
# To specify a proxy for a specific host or hosts, use multiple lines each specifying host = proxy-spec
# http =
#   hostname.to.be.proxied.com = http://user:pass@10.10.1.10:3128
# You can skip the proxy for the matching (fnmatch) urls (comma-separated)
# no_proxy_match = *center.conan.io*, https://myserver.*

[hooks]    # environment CONAN_HOOKS
attribute_checker

# Default settings now declared in the default profile

profile

https://docs.conan.io/1/reference/profiles.html

[settings]
setting=value

[options]
MyLib:shared=True

[env]
# [env] is deprecated! Use [buildenv] instead
env_var=value

[tool_requires]
tool1/0.1@user/channel
tool2/0.1@user/channel, tool3/0.1@user/channel
*: tool4/0.1@user/channel

3. conan分解流程

3.1 conan new

conan new hello/0.1@user/testing

3.2 conan source

conan source . --source-folder=tmp/source

3.3 conan install

conan install . --install-folder=tmp/build [--profile XXXX]

3.4 conan package

conan package . --source-folder=tmp/source --build-folder=tmp/build --package-folder=tmp/package

3.5 conan test

conan test test_package hello/1.1@user/channel

conan create

这个命令会执行以上所有命令 (除了conan test)

onan create . user/channel

conan upload 上传过程

添加remote

添加user

上传流程

4. 标准创建过程

conan_create

5. conanfile

可以对conanfile定制一定的模板,方便整体项目的使用

https://docs.conan.io/en/latest/extending/template_system/command_new.html

https://docs.conan.io/en/latest/reference/commands/creator/new.html

参考文档

https://ccup.github.io/conan-docs-zh/

https://docs.conan.io/1/cheatsheet.html

https://docs.conan.io/1/reference/conanfile/attributes.html