Skip to content

Commit

Permalink
conan
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Nov 8, 2024
1 parent eedf9a8 commit d9db90f
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
80 changes: 80 additions & 0 deletions conan/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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 VegConan(ConanFile):
name = "veg"
license = "MIT"
author = "Ivan Gagis <igagis@gmail.com>"
url = "http://github.com/cppfw/" + name
description = "Vector graphics C++ library"
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)
self.requires("rasterimage/[>=0.1.3]@cppfw/main", transitive_headers=True)
self.requires("agg/[>=0.0.0]@cppfw/main", transitive_headers=False)

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 = [self.name]

def package_id(self):
# change package id only when minor or major version changes, i.e. when ABI breaks
self.info.requires.minor_mode()
9 changes: 9 additions & 0 deletions conan/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)

# set(CMAKE_VERBOSE_MAKEFILE on)

find_package(veg CONFIG REQUIRED)

add_executable(example example.cpp)
target_link_libraries(example veg::veg)
22 changes: 22 additions & 0 deletions conan/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os

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"

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def layout(self):
cmake_layout(self)

def test(self):
self.run(".%sexample" % os.sep, env="conanrun") # env sets LD_LIBRARY_PATH etc. to find dependency libs
8 changes: 8 additions & 0 deletions conan/test_package/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <veg/canvas.hpp>

#include <iostream>

int main(int argc, const char** argv){
std::cout << "Hello veg!" << '\n';
return 0;
}

0 comments on commit d9db90f

Please sign in to comment.