From 0de6cf2bc3cda4126fc0e79dd19bab4bb924f1f0 Mon Sep 17 00:00:00 2001 From: mmjvox Date: Thu, 26 Sep 2024 04:28:52 +0330 Subject: [PATCH 1/2] conan recipe --- conan-package/CMakeLists.txt | 49 +++++++++++++ conan-package/Config.cmake.in | 6 ++ conan-package/conandata.yml | 10 +++ conan-package/conanfile.py | 72 +++++++++++++++++++ .../patches/1.0.0-0001_add_installation.patch | 69 ++++++++++++++++++ conan-package/test_package/CMakeLists.txt | 8 +++ conan-package/test_package/conanfile.py | 26 +++++++ conan-package/test_package/src/example.cpp | 13 ++++ 8 files changed, 253 insertions(+) create mode 100644 conan-package/CMakeLists.txt create mode 100644 conan-package/Config.cmake.in create mode 100644 conan-package/conandata.yml create mode 100644 conan-package/conanfile.py create mode 100644 conan-package/patches/1.0.0-0001_add_installation.patch create mode 100644 conan-package/test_package/CMakeLists.txt create mode 100644 conan-package/test_package/conanfile.py create mode 100644 conan-package/test_package/src/example.cpp diff --git a/conan-package/CMakeLists.txt b/conan-package/CMakeLists.txt new file mode 100644 index 0000000..cadbe4a --- /dev/null +++ b/conan-package/CMakeLists.txt @@ -0,0 +1,49 @@ +cmake_minimum_required(VERSION 3.5) +project(subprocess.h + VERSION 1.0.0 + LANGUAGES CXX + DESCRIPTION "single header process launching solution for C and C++") + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + +set(SUBPROCESS_HEADER_FILE + subprocess.h +) + + +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $) + + + +file(GLOB_RECURSE SUBPROCESS_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.h) + +target_include_directories(subprocess PUBLIC include) + + +string(JOIN ";" SUBPROCESS_HEADERS_STRING ${SUBPROCESS_HEADERS}) +set_target_properties(subprocess PROPERTIES + PUBLIC_HEADER "${SUBPROCESS_HEADERS_STRING}" +) + +include(GNUInstallDirs) + +include(CMakePackageConfigHelpers) +configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/subprocessConfig.cmake" + INSTALL_DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake/subprocess +) + +install(FILES ${SUBPROCESS_HEADERS} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/subprocess) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/subprocessConfig.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/subprocess) +install(TARGETS subprocess + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + diff --git a/conan-package/Config.cmake.in b/conan-package/Config.cmake.in new file mode 100644 index 0000000..01490eb --- /dev/null +++ b/conan-package/Config.cmake.in @@ -0,0 +1,6 @@ +@PACKAGE_INIT@ + +get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} DIRECTORY) +get_filename_component(INSTALLED_LIB_DIR ${PARENT_DIR} DIRECTORY) +set(cappuccino_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include") +set(cappuccino_LIBRARIES "${INSTALLED_LIB_DIR}/libcappuccino.a") diff --git a/conan-package/conandata.yml b/conan-package/conandata.yml new file mode 100644 index 0000000..bc3564d --- /dev/null +++ b/conan-package/conandata.yml @@ -0,0 +1,10 @@ +sources: + "1.0.0": + url: "https://github.com/sheredom/subprocess.h.git" + type: "git" + revision: "master" +patches: + "1.0.0": + - patch_file: "patches/1.0.0-0001_add_installation.patch" + patch_description: "add installation targets to cmake project" + patch_type: "conan" diff --git a/conan-package/conanfile.py b/conan-package/conanfile.py new file mode 100644 index 0000000..0f375e7 --- /dev/null +++ b/conan-package/conanfile.py @@ -0,0 +1,72 @@ +from conan import ConanFile +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps +from conan.tools.files import copy, get, apply_conandata_patches, export_conandata_patches, rmdir +from conan.tools.scm import Git + + +class subprocessRecipe(ConanFile): + name = "subprocess.h" + version = "1.0.0" + package_type = "library" + + # Optional metadata + license = "unlicense.org" + author = " Neil Henning (sheredom)" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/sheredom/subprocess.h" + description = "single header process launching solution for C and C++" + topics = ("c", "cpp", "process", "subprocess", "subprocess-run") + + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + options = {"shared": [True, False], "fPIC": [True, False]} + default_options = {"shared": False, "fPIC": True} + + def export_sources(self): + export_conandata_patches(self) + + def source(self): + source_data = self.conan_data["sources"][self.version] + git = Git(self) + git.clone(url="https://github.com/sheredom/subprocess.h.git") + + + + def config_options(self): + if self.settings.os == "Windows": + self.options.rm_safe("fPIC") + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self) + + def generate(self): + deps = CMakeDeps(self) + deps.generate() + tc = CMakeToolchain(self) + tc.generate() + + def build(self): + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + cmake = CMake(self) + cmake.install() + + def package_info(self): + self.cpp_info.names["cmake_find_package"] = "subprocess.h" + self.cpp_info.names["cmake_find_package_multi"] = "subprocess.h" + self.cpp_info.libs = [] # No actual libraries, it's header-only + self.cpp_info.includedirs = ["include"] + + + + + + diff --git a/conan-package/patches/1.0.0-0001_add_installation.patch b/conan-package/patches/1.0.0-0001_add_installation.patch new file mode 100644 index 0000000..db1ca9d --- /dev/null +++ b/conan-package/patches/1.0.0-0001_add_installation.patch @@ -0,0 +1,69 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +new file mode 100644 +index 0000000..19f20d7 +--- /dev/null ++++ b/CMakeLists.txt +@@ -0,0 +1,50 @@ ++cmake_minimum_required(VERSION 3.5) ++ ++project(subprocess.h ++ VERSION 1.0.0 ++ LANGUAGES CXX ++ DESCRIPTION "single header process launching solution for C and C++") ++ ++set(CMAKE_EXPORT_COMPILE_COMMANDS ON) ++ ++# Header-only library ++set(SUBPROCESS_HEADER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/subprocess.h/subprocess.h) ++ ++# Create an INTERFACE target (header-only) ++add_library(subprocess.h INTERFACE) ++ ++# Specify the include directory for consumers of this library ++target_include_directories(subprocess.h INTERFACE ++ $ ++ $ ++) ++ ++# Installation directories ++include(GNUInstallDirs) ++ ++# Install the header file ++install(FILES ${SUBPROCESS_HEADER_FILE} ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) ++ ++# Install the target ++install(TARGETS subprocess.h EXPORT subprocess.h-targets) ++ ++# Package config helpers for relocatable package ++include(CMakePackageConfigHelpers) ++ ++# Create a config file for find_package to work in the installed project ++configure_package_config_file( ++ "${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in" ++ "${CMAKE_CURRENT_BINARY_DIR}/subprocess.hConfig.cmake" ++ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/subprocess.h ++) ++ ++# Install the config files ++install(FILES "${CMAKE_CURRENT_BINARY_DIR}/subprocess.hConfig.cmake" ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/subprocess.h) ++ ++# Install the export targets ++install(EXPORT subprocess.h-targets ++ FILE subprocess.h-targets.cmake ++ NAMESPACE subprocess.h:: ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/subprocess.h) +diff --git a/Config.cmake.in b/Config.cmake.in +new file mode 100644 +index 0000000..f4f5fcd +--- /dev/null ++++ b/Config.cmake.in +@@ -0,0 +1,7 @@ ++@PACKAGE_INIT@ ++ ++# Set the include directory for the package ++set(subprocess_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../include") ++ ++# Import the target from the installed targets file ++include("${CMAKE_CURRENT_LIST_DIR}/subprocess.h-targets.cmake") diff --git a/conan-package/test_package/CMakeLists.txt b/conan-package/test_package/CMakeLists.txt new file mode 100644 index 0000000..7acc326 --- /dev/null +++ b/conan-package/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(PackageTest CXX) + +find_package(subprocess.h CONFIG REQUIRED) + +add_executable(example src/example.cpp) + +target_link_libraries(example subprocess.h::subprocess.h) diff --git a/conan-package/test_package/conanfile.py b/conan-package/test_package/conanfile.py new file mode 100644 index 0000000..5e119c8 --- /dev/null +++ b/conan-package/test_package/conanfile.py @@ -0,0 +1,26 @@ +import os + +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout +from conan.tools.build import can_run + + +class subprocessTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeDeps", "CMakeToolchain" + + 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): + if can_run(self): + cmd = os.path.join(self.cpp.build.bindir, "example") + self.run(cmd, env="conanrun") diff --git a/conan-package/test_package/src/example.cpp b/conan-package/test_package/src/example.cpp new file mode 100644 index 0000000..6e4c192 --- /dev/null +++ b/conan-package/test_package/src/example.cpp @@ -0,0 +1,13 @@ +#include "subprocess.h" + +int main() +{ + const char *command_line[] = {"echo", "\"Hello, world!\"", NULL}; + struct subprocess_s subprocess; + int result = subprocess_create(command_line, 0, &subprocess); + if (0 != result) { + // an error occurred! + } + + return 0; +} From d06cd2ab94686e9f5c707e5e86e2e6afffdac59e Mon Sep 17 00:00:00 2001 From: mmjvox Date: Wed, 1 Oct 2025 23:28:01 +0330 Subject: [PATCH 2/2] fix inclide dir --- conan-package/Config.cmake.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conan-package/Config.cmake.in b/conan-package/Config.cmake.in index 01490eb..83bf468 100644 --- a/conan-package/Config.cmake.in +++ b/conan-package/Config.cmake.in @@ -2,5 +2,4 @@ get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} DIRECTORY) get_filename_component(INSTALLED_LIB_DIR ${PARENT_DIR} DIRECTORY) -set(cappuccino_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include") -set(cappuccino_LIBRARIES "${INSTALLED_LIB_DIR}/libcappuccino.a") +set(subprocess.h_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include")