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

hscpp: new recipe #23802

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
16 changes: 16 additions & 0 deletions recipes/hscpp/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.15)
project(conan_wrapper CXX)

if(UNIX AND NOT APPLE)
find_package(libuuid REQUIRED)
add_library(uuid ALIAS libuuid::libuuid)
endif()

add_subdirectory(src)

install(TARGETS hscpp hscpp-mem
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)
install(DIRECTORY src/include/ DESTINATION include)
4 changes: 4 additions & 0 deletions recipes/hscpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0.0-alpha":
url: "https://github.com/jheruty/hscpp/archive/refs/tags/1.0.0-alpha.tar.gz"
sha256: "1c032bff3647c561231de98e819fb3248ea9ff2e9b247b78881170d6277f7c70"
127 changes: 127 additions & 0 deletions recipes/hscpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import os

from conan import ConanFile
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd, valid_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, replace_in_file, rm, rmdir
from conan.tools.microsoft import is_msvc

required_conan_version = ">=1.53.0"


class HscppConan(ConanFile):
name = "hscpp"
description = "A library to hot-reload C++ at runtime"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/jheruty/hscpp"
topics = ("hot-reload", "hot-swapping", "live-coding", "gamedev", "header-only")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

def export_sources(self):
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)

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

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

def requirements(self):
if not valid_min_cppstd(self, 17):
self.requires("ghc-filesystem/1.5.14")
if self.settings.os in ["Linux", "FreeBSD"]:
self.requires("util-linux-libuuid/2.39.2")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, 11)

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["HSCPP_BUILD_EXAMPLES"] = False
tc.variables["HSCPP_BUILD_TESTS"] = False
if not valid_min_cppstd(self, 17):
tc.variables["HSCPP_USE_GHC_FILESYSTEM"] = True
tc.variables["CMAKE_CXX_STANDARD"] = 11
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
tc.generate()

deps = CMakeDeps(self)
deps.set_property("ghc-filesystem", "cmake_target_name", "ghc_filesystem")
deps.generate()

def _patch_sources(self):
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"add_subdirectory(lib/filesystem-1.3.4)",
"find_package(ghc_filesystem REQUIRED CONFIG)")

def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure(build_script_folder=self.source_path.parent)
cmake.build()

def package(self):
copy(self, "LICENSE.txt", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rm(self, "*.pdb", self.package_folder, recursive=True)

@property
def _public_defines(self):
defines = []
if self.settings.build_type == "Debug":
defines.append("HSCPP_DEBUG")
if self.settings.os == "Windows":
defines.append("HSCPP_PLATFORM_WIN32")
defines.append("_CRT_SECURE_NO_WARNINGS")
elif is_apple_os(self):
defines.append("HSCPP_PLATFORM_APPLE")
defines.append("HSCPP_PLATFORM_UNIX")
else:
defines.append("HSCPP_PLATFORM_UNIX")
if is_msvc(self):
defines.append("HSCPP_COMPILER_MSVC")
elif self.settings.os == "Windows" and self.settings.compiler == "clang":
defines.append("HSCPP_COMPILER_CLANG_CL")
elif self.settings.compiler in ["clang", "apple-clang"]:
defines.append("HSCPP_COMPILER_CLANG")
defines.append("HSCPP_COMPILER_GCC")
elif self.settings.compiler == "gcc":
defines.append("HSCPP_COMPILER_GCC")
if valid_min_cppstd(self, 17):
defines.append(f"HSCPP_CXX_STANDARD={self.settings.compiler.cppstd}")
else:
defines.append("HSCPP_CXX_STANDARD=11")
defines.append("HSCPP_USE_GHC_FILESYSTEM")
return defines

def package_info(self):
self.cpp_info.libs = ["hscpp", "hscpp-mem"]
self.cpp_info.defines = self._public_defines

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("dl")
elif is_apple_os(self):
self.cpp_info.frameworks.extend(["CoreServices"])
8 changes: 8 additions & 0 deletions recipes/hscpp/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)
project(test_package LANGUAGES CXX)

find_package(hscpp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE hscpp::hscpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
26 changes: 26 additions & 0 deletions recipes/hscpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 = "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 can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
10 changes: 10 additions & 0 deletions recipes/hscpp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <hscpp/Hotswapper.h>

class Demo {};

int main()
{
hscpp::Hotswapper swapper;
Demo demo;
swapper.SetGlobalUserData(&demo);
}
3 changes: 3 additions & 0 deletions recipes/hscpp/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.0-alpha":
folder: all
Loading