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

tinycthread: support conan v2 #17001

Merged
merged 2 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions recipes/tinycthread/all/CMakeLists.txt

This file was deleted.

59 changes: 25 additions & 34 deletions recipes/tinycthread/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,56 @@
from conans import CMake, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import get, copy, load, save
from conan.tools.microsoft import msvc_runtime_flag, is_msvc
import functools
import os

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.54.0"

class TinycthreadConan(ConanFile):
name = "tinycthread"
description = "Small, portable implementation of the C11 threads API"
license = "zlib"
license = "Zlib"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/tinycthread/tinycthread"
topics = ("thread", "c11", "portable")
package_type = "static-library"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def export_sources(self):
self.copy("CMakeLists.txt")

def configure(self):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.settings.compiler.rm_safe("libcxx")
self.settings.compiler.rm_safe("cppstd")

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

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

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["TINYCTHREAD_DISABLE_TESTS"] = True
cmake.definitions["TINYCTHREAD_INSTALL"] = True
cmake.configure(build_folder=self._build_subfolder)
return cmake
def generate(self):
tc = CMakeToolchain(self)
tc.variables["TINYCTHREAD_DISABLE_TESTS"] = True
tc.variables["TINYCTHREAD_INSTALL"] = True
tc.generate()

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

def _extract_license(self):
file = os.path.join(self.source_folder, self._source_subfolder, "source", "tinycthread.h")
file_content = tools.load(file)
file = os.path.join(self.source_folder, "source", "tinycthread.h")
file_content = load(self, file)

license_start = file_content.find("Copyright")
license_end = file_content.find("*/")
license_contents = file_content[license_start:license_end]
tools.save(os.path.join(self.package_folder, "licenses", "LICENSE"), license_contents)
save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), license_contents)

def package(self):
self._extract_license()
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
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):
Expand Down
4 changes: 0 additions & 4 deletions recipes/tinycthread/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ cmake_minimum_required(VERSION 3.1)

project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)

conan_basic_setup(TARGETS)

find_package(tinycthread REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
Expand Down
20 changes: 15 additions & 5 deletions recipes/tinycthread/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

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

def layout(self):
cmake_layout(self)

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/tinycthread/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.15)
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/)
16 changes: 16 additions & 0 deletions recipes/tinycthread/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from conans import ConanFile, CMake, tools
import os

class TestPackageConan(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 tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)