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

conan recipe #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
49 changes: 49 additions & 0 deletions conan-package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)



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}
)

6 changes: 6 additions & 0 deletions conan-package/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -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")
10 changes: 10 additions & 0 deletions conan-package/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
72 changes: 72 additions & 0 deletions conan-package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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"]






69 changes: 69 additions & 0 deletions conan-package/patches/1.0.0-0001_add_installation.patch
Original file line number Diff line number Diff line change
@@ -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
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+)
+
+# 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")
8 changes: 8 additions & 0 deletions conan-package/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions conan-package/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.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")
13 changes: 13 additions & 0 deletions conan-package/test_package/src/example.cpp
Original file line number Diff line number Diff line change
@@ -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;
}