공부/그외

CONAN C/C++ Package Manager

래울 2025. 3. 8. 03:28

 

그저 JFrog CONAN 강의 듣고 사용해보면서 끄적거리는 페이지


CONAN 사용이유

https://dooho-h.medium.com/reasons-why-i-use-conan-f9506958b115

 

CONAN Tutorial

https://academy.jfrog.com/path/conan

 

CONAN 메모

더보기

abstracting away build systems

normalizing inputs and outputs

Multi-Binary Packages and Shared Repositories

- build configuration(options, settings)에 따라서 유니크한 Package ID를 생성

- 같은 build configuration에 대해 Remote Server에서 Local Client로 가져옴

 

프로젝트에서 입력과 출력의 정규화

conanbuildinfo.cmake

conanbuildinfo.mak

 

개발자가 여러 프로젝트에 필요한 복잡한 빌드 시스템을 이해해서 사용하는 부담을 덜어줌

각 빌드 정보를 레시피로 캡처함, 이미 코난에는 다양한 C/C++ 프로젝트에 필요한 레시피가 존재해서 가져와 사용 가능

Conan은 C 및 C++ 프로젝트를 위한 일종의 범용 "프로젝트 API"를 제공하며, 이는 프로젝트 입력과 출력을 공통 요소로 추출함

Conan 생성기는 모든 프로젝트 종속성의 모든 정보가 포함된 .txt 파일을 생성하고, 코난은 알아서 해당 파일을 빌드 시스템이 이해할 수 있는 형식으로 변환해 줌

 

구조

Server(artifact storage): JFrog Artifactory, JFrog CONANCENTER

Developer(machine/CI): Client

 

Binary Management

 

pkg/0.1@user/channel

Package + Recipe -> Package 'binaries'

각각의 바이너리는 유니크한 Package ID를 가짐

 

 

패키지 생성

1. conanfile.py 템플릿 생성

conan new my_package/1.0@test/channel

 

conanfile.py(receipe)

- source

- build

- package

- package info

 

클래스 안에 속성과 메소드들이 정의됨, 상세(https://docs.conan.io/1/reference/conanfile.html)

from conans import ConanFile, CMake, tools


class MyPackageConan(ConanFile):
    name = "my_package"
    version = "1.0"
    license = "<Put the package license here>"
    author = "<Put your name here> <And your email here>"
    url = "<Package recipe repository url here, for issues about the package>"
    description = "<Description of MyPackage here>"
    topics = ("<Put some tag here>", "<here>", "<and here>")
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False], "fPIC": [True, False]}
    default_options = {"shared": False, "fPIC": True}
    generators = "cmake"

    def config_options(self):
        if self.settings.os == "Windows":
            del self.options.fPIC

    def source(self):
        self.run("git clone https://github.com/conan-io/hello.git")
        # This small hack might be useful to guarantee proper /MT /MD linkage
        # in MSVC if the packaged project doesn't have variables to set it
        # properly
        tools.replace_in_file("hello/CMakeLists.txt", "PROJECT(HelloWorld)",
                              '''PROJECT(HelloWorld)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()''')

    def build(self):
        cmake = CMake(self)
        cmake.configure(source_folder="hello")
        cmake.build()

        # Explicit way:
        # self.run('cmake %s/hello %s'
        #          % (self.source_folder, cmake.command_line))
        # self.run("cmake --build . %s" % cmake.build_config)

    def package(self):
        self.copy("*.h", dst="include", src="hello")
        self.copy("*hello.lib", dst="lib", keep_path=False)
        self.copy("*.dll", dst="bin", keep_path=False)
        self.copy("*.so", dst="lib", keep_path=False)
        self.copy("*.dylib", dst="lib", keep_path=False)
        self.copy("*.a", dst="lib", keep_path=False)

    def package_info(self):
        self.cpp_info.libs = ["hello"]

 

2. create package

conan create . user/testing

conan search

conan search my_package/1.0@user/testing

 

3. create package, 하나의 recipe에 두 개의 Package ID가 생성됨을 확인

conan create . user/testing -s build_type=Debug

$ conan search my_package/1.0@user/testing

 

 

 

 Build Configurations

Settings

- 다른 빌드 타입

- 다른 컴파일러 버전

- 다른 컴파일러

- 다른 아키텍처에 대한 크로스 빌드

 

Options

다른 옵션들, FP, shared, static 등등

 

Options Ex

만약 사용자 정의 옵션을 뭔가 추가하고 싶으면 비슷하게 추가하면 됨

options / default_options

$ conan create . user/testing -o hello:shared=True

 

conan pre-settings

코난에서 사전에 정의된 settings

~/.conan/settings.yml

 

추가.

$conan profile list

$conan profile show default

~/.conan/profiles

 

 

추후 필요한 것들 더 작성 예정...