[DO-972][DO-980] add freetype and pkgconf recipes (!6)

Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/6
This commit is contained in:
Aleksandr Vodyanov
2024-12-06 16:48:28 +03:00
parent 25212f3eed
commit cb6a88b7f4
184 changed files with 1708 additions and 9302 deletions

View File

@@ -0,0 +1,83 @@
from io import StringIO
import os
from pathlib import Path
import re
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake, CMakeDeps, CMakeToolchain
from conan.tools.env import Environment, VirtualBuildEnv
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.microsoft import unix_path
# It will become the standard on Conan 2.x
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
test_type = "explicit"
@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
def requirements(self):
self.requires(self.tested_reference_str, run=True)
def layout(self):
cmake_layout(self, src_folder="src")
def generate(self):
# Expose `PKG_CONFIG_PATH` to be able to find libexample1.pc
env = Environment()
self.output.info(f"Source folder: {self.source_folder}")
env.prepend_path("PKG_CONFIG_PATH", self.source_folder)
env.vars(self, scope="run").save_script("pkgconf-config-path")
# CMake project to test that we can link against the library,
# when the library is built
if self.dependencies[self.tested_reference_str].options.enable_lib:
ct = CMakeToolchain(self)
ct.generate()
deps = CMakeDeps(self)
deps.generate()
# Check build environment postconditions
buildenv = VirtualBuildEnv(self)
env = buildenv.vars(scope='build')
assert 'PKG_CONFIG' in env.keys()
assert 'ACLOCAL_PATH' in env.keys()
assert 'AUTOMAKE_CONAN_INCLUDES' in env.keys()
buildenv.generate()
@property
def _testing_library(self):
# Workaround, in Conan >=2.0 we should be able to remove this in favour of:
# self.dependencies[self.tested_reference_str].options.enable_lib
has_toolchain = sorted(Path(self.build_folder).rglob('conan_toolchain.cmake'))
return has_toolchain
def build(self):
if self._testing_library:
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
# Check that we can find pkgconf in build environment
# and that it is the expected version
if can_run(self):
output = StringIO()
self.run("pkgconf --about", output, env="conanrun")
# TODO: When recipe is Conan 2+ only, this can be simplified
# to: self.dependencies['pkgconf'].ref.version
tokens = re.split('[@#]', self.tested_reference_str)
pkgconf_expected_version = tokens[0].split("/", 1)[1]
assert f"pkgconf {pkgconf_expected_version}" in output.getvalue()
self.run("pkgconf libexample1 -cflags", env="conanrun")
# Test that executable linked against library runs as expected
if can_run(self) and self._testing_library:
test_executable = unix_path(self, os.path.join(self.cpp.build.bindirs[0], "test_package"))
self.run(test_executable, env="conanrun")

View File

@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)
find_package(pkgconf REQUIRED)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE pkgconf::pkgconf)

View File

@@ -0,0 +1,6 @@
Name: libexample1
Description: This is a description of libexample1.
Requires:
Version: 0.42
Libs: -L/usr/lib -lexample1
Cflags: -I/usr/include/libexample1 -I/usr/include -DEXAMPLE1_STATIC

View File

@@ -0,0 +1,24 @@
#include "libpkgconf/libpkgconf.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
bool error_callback(const char *msg, const pkgconf_client_t *client, const void *data) {
printf("error callback: %s\n", msg);
fflush(stdout);
return 1; // 1/true means message handled
}
int main() {
pkgconf_client_t client;
memset(&client, 0, sizeof(client));
pkgconf_client_init(&client, error_callback, NULL, pkgconf_cross_personality_default());
pkgconf_error(&client, "%s:%d %s: %s", __FILE__, __LINE__, __FUNCTION__, "test error");
pkgconf_client_deinit(&client);
return 0;
}