Skip to content

Commit

Permalink
(#14324) hedley: conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored Nov 29, 2022
1 parent cb85824 commit 98a080e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 25 deletions.
36 changes: 22 additions & 14 deletions recipes/hedley/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from conans import ConanFile, tools
from conan import ConanFile
from conan.tools.files import copy, get
from conan.tools.layout import basic_layout
import os
import glob

required_conan_version = ">=1.50.0"


class HedleyConan(ConanFile):
Expand All @@ -9,22 +12,27 @@ class HedleyConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://nemequ.github.io/hedley/"
description = "A C/C++ header to help move #ifdefs out of your code"
topics = ("header", 'header-only', 'preprocessor', "#ifdef", "cross-platform")
topics = ("header", "header-only", "preprocessor", "#ifdef", "cross-platform")
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

@property
def _source_subfolder(self):
return "source_subfolder"
def layout(self):
basic_layout(self, src_folder="src")

def package_id(self):
self.info.clear()

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = glob.glob(self.name + "-*/")[0]
os.rename(extracted_dir, self._source_subfolder)
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def build(self):
pass

def package(self):
include_folder = self._source_subfolder
self.copy(pattern="*.h", dst="include", src=include_folder)
self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder)
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, "*.h", src=self.source_folder, dst=os.path.join(self.package_folder, "include"))

def package_id(self):
self.info.header_only()
def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
9 changes: 4 additions & 5 deletions recipes/hedley/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest CXX)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(hedley REQUIRED CONFIG)

add_executable(example example.cpp)
target_link_libraries(example ${CONAN_LIBS})
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE hedley::hedley)
21 changes: 15 additions & 6 deletions recipes/hedley/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os
from conans import ConanFile, CMake, tools


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

def layout(self):
cmake_layout(self)

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

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

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
File renamed without changes.
8 changes: 8 additions & 0 deletions recipes/hedley/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.1)
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)
17 changes: 17 additions & 0 deletions recipes/hedley/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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)

0 comments on commit 98a080e

Please sign in to comment.