Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tinycthreadpool #14703

Merged
merged 10 commits into from
Apr 17, 2023
4 changes: 4 additions & 0 deletions recipes/tinycthreadpool/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0":
url: "https://github.com/bennyhuo/tinycthreadpool/archive/refs/tags/v1.0.tar.gz"
sha256: "a3e9876d3e3008cffed96216d026504b57ab6be6ee3df62d5916fecd4106ede5"
66 changes: 66 additions & 0 deletions recipes/tinycthreadpool/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os

from conan import ConanFile
from conan.tools.files import get, copy
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout

required_conan_version = ">=1.54.0"


class TinyCThreadPoolConan(ConanFile):
name = "tinycthreadpool"
description = "Portable C thread pool"
license = "BSD-2-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/bennyhuo/tinycthreadpool"
topics = ("thread-pool", "threading", "pure-c")
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

bennyhuo marked this conversation as resolved.
Show resolved Hide resolved
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("tinycthread/cci.20161001", transitive_headers=True)

def generate(self):
tc = CMakeToolchain(self)
tc.generate()

tc = CMakeDeps(self)
tc.generate()

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

def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["tinycthreadpool"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("pthread")
8 changes: 8 additions & 0 deletions recipes/tinycthreadpool/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
bennyhuo marked this conversation as resolved.
Show resolved Hide resolved
project(PackageTest C)

find_package(tinycthreadpool REQUIRED CONFIG)

add_executable(example example.c)
target_link_libraries(example tinycthreadpool::tinycthreadpool)
target_compile_features(example PRIVATE c_std_11)
26 changes: 26 additions & 0 deletions recipes/tinycthreadpool/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout


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

def layout(self):
cmake_layout(self)

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

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

def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "example")
self.run(cmd, env="conanrun")
14 changes: 14 additions & 0 deletions recipes/tinycthreadpool/all/test_package/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <threadpool.h>
#include <tinycthread.h>
#include <stdio.h>

int main(void) {
puts("Start Testing!");
threadpool_t *threadpool = threadpool_create(3, 5, 0);
printf("Create thread pool: %#x.\n", threadpool);
if (threadpool){
int result = threadpool_destroy(threadpool, 0);
printf("End Testing! result: %d\n", result);
}
return 0;
}
8 changes: 8 additions & 0 deletions recipes/tinycthreadpool/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
19 changes: 19 additions & 0 deletions recipes/tinycthreadpool/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


# legacy validation with Conan 1.x
class TestPackageV1Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

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

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)
4 changes: 4 additions & 0 deletions recipes/tinycthreadpool/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
versions:
# Newer versions at the top
"1.0":
folder: all