reproc: new recipe (#24508)

* reproc: new recipe

* reproc: reproc++ requires reproc

* reproc: add Ws2_32 dependency

* reproc: require GCC 6

* reproc: Windows shared builds are broken

* update recipe and test package

* change components name

* fix name

* Windows works!

* Update recipes/reproc/all/conanfile.py

---------

Co-authored-by: czoido <mrgalleta@gmail.com>
Co-authored-by: Abril Rincón Blanco <git@rinconblanco.es>
This commit is contained in:
Martin Valgur
2024-11-18 12:09:51 +02:00
committed by GitHub
parent 7abb9ee39e
commit c3c5910dea
7 changed files with 187 additions and 0 deletions

View File

@ -0,0 +1,4 @@
sources:
"14.2.5":
url: "https://github.com/DaanDeMeyer/reproc/archive/refs/tags/v14.2.5.tar.gz"
sha256: "69467be0cfc80734b821c54ada263c8f1439f964314063f76b7cf256c3dc7ee8"

View File

@ -0,0 +1,98 @@
import os
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rm, rmdir
from conan.tools.scm import Version
class PackageConan(ConanFile):
name = "reproc"
description = "A cross-platform C99 process library"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/DaanDeMeyer/reproc"
topics = ("process-management", "process", "cross-platform")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"cxx": [True, False],
"multithreaded": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"cxx": True,
"multithreaded": True,
}
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
if not self.options.cxx:
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")
def layout(self):
cmake_layout(self, src_folder="src")
def validate(self):
if self.options.cxx:
check_min_cppstd(self, 11)
if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "6":
# drain.hpp:55:43: error: stream is not a class, namespace, or enumeration
raise ConanInvalidConfiguration("GCC < 6 is not supported")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["REPROC++"] = self.options.cxx
tc.variables["REPROC_MULTITHREADED"] = self.options.multithreaded
tc.variables["REPROC_TEST"] = False
tc.variables["REPROC_EXAMPLES"] = False
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rm(self, "*.pdb", self.package_folder, recursive=True)
def package_info(self):
cmake_config_name = "reproc++" if self.options.cxx else "reproc"
self.cpp_info.set_property("cmake_file_name", cmake_config_name)
self.cpp_info.components["reproc_c"].set_property("pkg_config_name", "reproc")
self.cpp_info.components["reproc_c"].set_property("cmake_target_name", "reproc")
self.cpp_info.components["reproc_c"].libs = ["reproc"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["reproc_c"].system_libs.append("rt")
if self.options.multithreaded:
self.cpp_info.components["reproc_c"].system_libs.append("pthread")
elif self.settings.os == "Windows":
self.cpp_info.components["reproc_c"].system_libs.append("Ws2_32")
if self.options.cxx:
self.cpp_info.components["reproc_cxx"].set_property("pkg_config_name", "reproc++")
self.cpp_info.components["reproc_cxx"].set_property("cmake_target_name", "reproc++")
self.cpp_info.components["reproc_cxx"].libs = ["reproc++"]
self.cpp_info.components["reproc_cxx"].requires = ["reproc_c"]

View File

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C CXX)
if(WITH_CXX)
find_package(reproc++ REQUIRED CONFIG)
else()
find_package(reproc REQUIRED CONFIG)
endif()
add_executable(${PROJECT_NAME}_c test_package.c)
target_link_libraries(${PROJECT_NAME}_c PRIVATE reproc)
target_compile_features(${PROJECT_NAME}_c PRIVATE c_std_99)
if(WITH_CXX)
add_executable(${PROJECT_NAME}_cpp test_package.cpp)
target_link_libraries(${PROJECT_NAME}_cpp PRIVATE reproc++)
target_compile_features(${PROJECT_NAME}_cpp PRIVATE cxx_std_11)
endif()

View File

@ -0,0 +1,34 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires(self.tested_reference_str)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["WITH_CXX"] = self.dependencies["reproc"].options.get_safe("cxx")
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package_c")
self.run(bin_path, env="conanrun")
if (self.dependencies["reproc"].options.get_safe("cxx")):
bin_path = os.path.join(self.cpp.build.bindir, "test_package_cpp")
self.run(bin_path, env="conanrun")

View File

@ -0,0 +1,14 @@
#include <reproc/reproc.h>
#include <stdio.h>
int main()
{
reproc_t *process = reproc_new();
if (!process) {
fprintf(stderr, "Failed to create reproc process.\n");
return 1;
}
printf("reproc setup successful. Process object created.\n");
reproc_destroy(process);
return 0;
}

View File

@ -0,0 +1,16 @@
#include <reproc++/reproc.hpp>
#include <iostream>
int main()
{
try {
reproc::process process;
reproc::options options;
options.redirect.parent = true;
std::cout << "reproc++ setup successful. Process object created.\n";
} catch (const std::exception &e) {
std::cerr << "Error: " << e.what() << '\n';
return 1;
}
return 0;
}

View File

@ -0,0 +1,3 @@
versions:
"14.2.5":
folder: all