Skip to content

Commit

Permalink
conan: migrate to conan 2
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed May 18, 2023
1 parent 73bac1a commit a0f8db0
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 100 deletions.
30 changes: 14 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ env:
MYCI_CONAN_REMOTE: https://gagis.hopto.org/conan
MYCI_CONAN_USER: cppfw
MYCI_CONAN_PASSWORD: ${{ secrets.MYCI_CONAN_PASSWORD }}
CONAN_V2_MODE: 1
CONAN_REVISIONS_ENABLED: 1
CONAN_SCM_TO_CONANDATA: 1
jobs:
##### linux #####
linux:
Expand Down Expand Up @@ -254,26 +251,25 @@ jobs:
keys-asc: https://gagis.hopto.org/repo/cppfw/pubkey.gpg
install: devscripts equivs myci prorab prorab-extra python3-pip cmake git clang-tidy
- name: install conan
run: pip3 --quiet install conan
- name: create default conan profile
run: |
pip3 install conan
conan profile new --detect default
conan profile update settings.compiler.libcxx=libstdc++11 default
conan profile detect --name default
sed -i -E "s/compiler.cppstd=.*$/compiler.cppstd=17/g" ~/.conan2/profiles/default
- name: git clone
uses: myci-actions/checkout@master
- name: set PACKAGE_VERSION
uses: myci-actions/export-env-var@master
with: {name: PACKAGE_VERSION, value: $(myci-deb-version.sh debian/changelog)}
if: startsWith(github.ref, 'refs/tags/')
- name: prepare conanfile
run: myci-apply-version.sh --version $PACKAGE_VERSION conan/conanfile.py.in
- name: build
run: |
conan remote add cppfw $MYCI_CONAN_REMOTE
conan create conan $MYCI_CONAN_USER/main --ignore-dirty
conan create conan --user $MYCI_CONAN_USER --channel main --version $PACKAGE_VERSION
- name: deploy conan package
run: |
conan user --remote cppfw --password $MYCI_CONAN_PASSWORD $MYCI_CONAN_USER
conan upload --remote cppfw --all $PACKAGE_NAME/$PACKAGE_VERSION@$MYCI_CONAN_USER/main
conan remote login --password $MYCI_CONAN_PASSWORD cppfw $MYCI_CONAN_USER
conan upload --check --remote cppfw $PACKAGE_NAME/$PACKAGE_VERSION@$MYCI_CONAN_USER/main
if: startsWith(github.ref, 'refs/tags/')
##### conan - macosx #####
conan-macosx:
Expand All @@ -295,6 +291,10 @@ jobs:
brew update
- name: install ci tools
run: brew install myci prorab prorab-extra conan make
- name: create default conan profile
run: |
conan profile detect --name default
sed -i -E "s/compiler.cppstd=.*$/compiler.cppstd=17/g" ~/.conan2/profiles/default
- name: set PATH
uses: myci-actions/export-env-var@master
with: {name: PATH, value: "/usr/local/opt/make/libexec/gnubin:$PATH"}
Expand All @@ -304,14 +304,12 @@ jobs:
uses: myci-actions/export-env-var@master
with: {name: PACKAGE_VERSION, value: $(myci-deb-version.sh debian/changelog)}
if: startsWith(github.ref, 'refs/tags/')
- name: prepare conanfile
run: myci-apply-version.sh --version $PACKAGE_VERSION conan/conanfile.py.in
- name: build
run: |
conan remote add cppfw $MYCI_CONAN_REMOTE
conan create conan $MYCI_CONAN_USER/main --ignore-dirty
conan create conan --user $MYCI_CONAN_USER --channel main --version $PACKAGE_VERSION
- name: deploy conan package
run: |
conan user --remote cppfw --password $MYCI_CONAN_PASSWORD $MYCI_CONAN_USER
conan upload --remote cppfw --all $PACKAGE_NAME/$PACKAGE_VERSION@$MYCI_CONAN_USER/main
conan remote login --password $MYCI_CONAN_PASSWORD cppfw $MYCI_CONAN_USER
conan upload --check --remote cppfw $PACKAGE_NAME/$PACKAGE_VERSION@$MYCI_CONAN_USER/main
if: startsWith(github.ref, 'refs/tags/')
78 changes: 78 additions & 0 deletions conan/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import os
from conan import ConanFile
from conan.tools.scm import Git
from conan.tools.files import load, update_conandata, copy
from conan.tools.layout import basic_layout

class AggConan(ConanFile):
name = "agg"
license = "MIT"
author = "Maxim Shemanarev <[email protected]>"
url = "http://github.com/cppfw/" + name
description = "Anti-grain geometry, vector graphics library in C++"
topics = ("C++", "cross-platform")
settings = "os", "compiler", "build_type", "arch"
package_type = "library"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
generators = "AutotoolsDeps" # this will set CXXFLAGS etc. env vars

def requirements(self):
# self.requires("utki/[>=1.1.202]@cppfw/main", transitive_headers=True)

def build_requirements(self):
# self.requires("tst/[>=0.3.29]@cppfw/main", visible=False)

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

# save commit and remote URL to conandata.yml for packaging
def export(self):
git = Git(self)
scm_url = git.get_remote_url()
# NOTE: Git.get_commit() doesn't work properly,
# it gets latest commit of the folder in which conanfile.py resides.
# So, we use "git rev-parse HEAD" instead as it gets the actual HEAD
# commit regardless of the current working directory within the repo.
scm_commit = git.run("rev-parse HEAD") # get current commit
update_conandata(self, {"sources": {"commit": scm_commit, "url": scm_url}})

def source(self):
git = Git(self)
sources = self.conan_data["sources"]
# shallow fetch commit
git.fetch_commit(url=sources["url"], commit=sources['commit'])
# shallow clone submodules
git.run("submodule update --init --remote --depth 1")

def build(self):
self.run("make lint=off")
self.run("make lint=off test")

def package(self):
src_dir = os.path.join(self.build_folder, "src")
src_rel_dir = os.path.join(self.build_folder, "src/out/rel")
dst_include_dir = os.path.join(self.package_folder, "include")
dst_lib_dir = os.path.join(self.package_folder, "lib")
dst_bin_dir = os.path.join(self.package_folder, "bin")

copy(conanfile=self, pattern="*.h", dst=dst_include_dir, src=src_dir, keep_path=True)
copy(conanfile=self, pattern="*.hpp", dst=dst_include_dir, src=src_dir, keep_path=True)

if self.options.shared:
copy(conanfile=self, pattern="*" + self.name + ".lib", dst=dst_lib_dir, src="", keep_path=False)
copy(conanfile=self, pattern="*.dll", dst=dst_bin_dir, src=src_rel_dir, keep_path=False)
copy(conanfile=self, pattern="*.so", dst=dst_lib_dir, src=src_rel_dir, keep_path=False)
copy(conanfile=self, pattern="*.so.*", dst=dst_lib_dir, src=src_rel_dir, keep_path=False)
copy(conanfile=self, pattern="*.dylib", dst=dst_lib_dir, src=src_rel_dir, keep_path=False)
else:
copy(conanfile=self, pattern="*" + self.name + ".lib", dst=dst_lib_dir, src="", keep_path=False)
copy(conanfile=self, pattern="*.a", dst=dst_lib_dir, src=src_rel_dir, keep_path=False)

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

def package_id(self):
# change package id only when minor or major version changes, i.e. when ABI breaks
self.info.requires.minor_mode()
53 changes: 0 additions & 53 deletions conan/conanfile.py.in

This file was deleted.

17 changes: 4 additions & 13 deletions conan/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

# set(CMAKE_VERBOSE_MAKEFILE on)

add_executable(example example.cpp)
target_link_libraries(example ${CONAN_LIBS})
find_package(agg CONFIG REQUIRED)

# CTest is a testing tool that can be used to test your project.
# enable_testing()
# add_test(NAME example
# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
# COMMAND example)
add_executable(example example.cpp)
target_link_libraries(example agg::agg)
33 changes: 15 additions & 18 deletions conan/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import os

from conans import ConanFile, CMake, tools
from conan import ConanFile, tools
from conan.tools.cmake import CMake, cmake_layout

class TestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain", "CMakeDeps"

class UtkiTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
# Current dir is "test_package/build/<build_id>" and CMakeLists.txt is
# in "test_package"
cmake.configure()
cmake.build()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def imports(self):
self.copy("*.dll", dst="bin", src="bin")
self.copy("*.dylib*", dst="bin", src="lib")
self.copy('*.so*', dst='bin', src='lib')
def layout(self):
cmake_layout(self)

def test(self):
if not tools.cross_building(self):
os.chdir("bin")
self.run(".%sexample" % os.sep, run_environment=True) # run_environment sets LD_LIBRARY_PATH etc. to find dependency libs
def test(self):
self.run(".%sexample" % os.sep, env="conanrun") # env sets LD_LIBRARY_PATH etc. to find dependency libs

0 comments on commit a0f8db0

Please sign in to comment.