Skip to content

Commit

Permalink
(#14250) khrplatform: conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored Nov 26, 2022
1 parent 62f515b commit ba0aea3
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 23 deletions.
38 changes: 25 additions & 13 deletions recipes/khrplatform/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from conan import ConanFile
from conan.tools.files import copy, download, load, save
from conan.tools.layout import basic_layout
import os
from conans import ConanFile, tools
from conans.errors import ConanInvalidConfiguration

required_conan_version = ">=1.50.0"

required_conan_version = ">=1.37.0"

class KhrplatformConan(ConanFile):
name = "khrplatform"
Expand All @@ -12,20 +13,31 @@ class KhrplatformConan(ConanFile):
homepage = "https://www.khronos.org/registry/EGL/"
description = "Khronos EGL platform interfaces"
topics = ("opengl", "gl", "egl", "khr", "khronos")
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

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

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

def source(self):
tools.download(filename="khrplatform.h", **self.conan_data["sources"][self.version])
download(self, filename="khrplatform.h", **self.conan_data["sources"][self.version])

def package(self):
self.copy(pattern="khrplatform.h", dst=os.path.join("include", "KHR"))
license_data = tools.load(os.path.join(self.source_folder, "khrplatform.h"))
def build(self):
pass

def _extract_license(self):
license_data = load(self, os.path.join(self.source_folder, "khrplatform.h"))
begin = license_data.find("/*") + len("/*")
end = license_data.find("*/")
license_data = license_data[begin:end]
license_data = license_data.replace("**", "")
tools.save("LICENSE", license_data)
self.copy("LICENSE", dst="licenses")
return license_data[begin:end].replace("**", "")

def package_id(self):
self.info.header_only()
def package(self):
save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), self._extract_license())
copy(self, "khrplatform.h", src=self.source_folder, dst=os.path.join(self.package_folder, "include", "KHR"))

def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
5 changes: 1 addition & 4 deletions recipes/khrplatform/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
project(test_package LANGUAGES C)

find_package(khrplatform REQUIRED CONFIG)

Expand Down
21 changes: 15 additions & 6 deletions recipes/khrplatform/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
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):
bin_path = os.path.join("bin", "test_package")
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")
8 changes: 8 additions & 0 deletions recipes/khrplatform/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/khrplatform/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 ba0aea3

Please sign in to comment.