Skip to content

Commit a6eb05e

Browse files
togeStellaSmith
authored andcommitted
(conan-io#14765) kaitai_struct_cpp_stl_runtime: add version 0.10, support conan v 2
* kaitai_struct_cpp_stl_runtime: add version 0.10, support conan v 2 * declare cmake_minimum_required first * fix patch definition
1 parent 104237e commit a6eb05e

File tree

9 files changed

+104
-57
lines changed

9 files changed

+104
-57
lines changed

recipes/kaitai_struct_cpp_stl_runtime/all/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
sources:
2+
"0.10":
3+
url: "https://github.com/kaitai-io/kaitai_struct_cpp_stl_runtime/archive/refs/tags/0.10.tar.gz"
4+
sha256: "9a7d382b2acbbe6498ecca23fc7b6b98cbcc418af83fb569f94395f29712171c"
25
"cci.20210701":
36
url: "https://github.com/kaitai-io/kaitai_struct_cpp_stl_runtime/archive/cb09b3a84c7e905c6a3fecfe9617cf864d9af781.zip"
47
sha256: "058c01828692bf193cb862372651c572fcc43babbf2d664674409511b9f54e5b"
8+
patches:
9+
"0.10":
10+
- patch_file: "patches/0001-cmake-minimum-required.patch"
11+
patch_description: "declare cmake_minimum_required first"
12+
patch_type: "portability"
13+
"cci.20210701":
14+
- patch_file: "patches/0001-cmake-minimum-required.patch"
15+
patch_description: "declare cmake_minimum_required first"
16+
patch_type: "portability"
Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,64 @@
1+
from conan import ConanFile
2+
from conan.tools.files import get, copy, export_conandata_patches, apply_conandata_patches
3+
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
14
import os
25

3-
from conans import ConanFile, CMake, tools
4-
6+
required_conan_version = ">=1.53.0"
57

68
class KaitaiStructCppStlRuntimeConan(ConanFile):
79
name = "kaitai_struct_cpp_stl_runtime"
10+
description = "kaitai struct c++ runtime library"
811
license = "MIT"
912
url = "https://github.com/conan-io/conan-center-index"
1013
homepage = "https://kaitai.io/"
11-
description = "kaitai struct c++ runtime library"
12-
topics = ("parsers", "streams", "dsl")
13-
settings = "os", "compiler", "build_type", "arch"
14-
exports_sources = "CMakeLists.txt"
15-
generators = "cmake"
14+
topics = ("parsers", "streams", "dsl", "kaitai struct")
15+
settings = "os", "arch", "compiler", "build_type"
1616
options = {
1717
"with_zlib": [True, False],
18-
"with_iconv": [True, False]
18+
"with_iconv": [True, False],
1919
}
2020
default_options = {
2121
"with_zlib": False,
22-
"with_iconv": False
22+
"with_iconv": False,
2323
}
2424
short_paths = True
25-
_cmake = None
25+
26+
def export_sources(self):
27+
export_conandata_patches(self)
28+
29+
def layout(self):
30+
cmake_layout(self, src_folder="src")
2631

2732
def requirements(self):
2833
if self.options.with_zlib:
29-
self.requires("zlib/1.2.11")
34+
self.requires("zlib/1.2.13")
3035
if self.options.with_iconv:
31-
self.requires("libiconv/1.16")
32-
33-
@property
34-
def _source_subfolder(self):
35-
return "source_subfolder"
36-
37-
@property
38-
def _build_subfolder(self):
39-
return "build_subfolder"
36+
self.requires("libiconv/1.17")
4037

4138
def source(self):
42-
tools.get(**self.conan_data["sources"][self.version],
43-
destination=self._source_subfolder, strip_root=True)
44-
45-
def build(self):
46-
cmake = self._configure_cmake()
47-
cmake.build()
48-
49-
def _configure_cmake(self):
50-
if self._cmake:
51-
return self._cmake
52-
self._cmake = CMake(self)
39+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
5340

41+
def generate(self):
42+
tc = CMakeToolchain(self)
5443
if self.options.with_iconv:
55-
self._cmake.definitions["STRING_ENCODING_TYPE"] = "ICONV"
44+
tc.variables["STRING_ENCODING_TYPE"] = "ICONV"
5645
else:
57-
self._cmake.definitions["STRING_ENCODING_TYPE"] = "NONE"
46+
tc.variables["STRING_ENCODING_TYPE"] = "NONE"
47+
tc.generate()
5848

59-
self._cmake.configure(build_folder=self._build_subfolder)
60-
return self._cmake
49+
deps = CMakeDeps(self)
50+
deps.generate()
51+
52+
def build(self):
53+
apply_conandata_patches(self)
54+
cmake = CMake(self)
55+
cmake.configure()
56+
cmake.build()
6157

6258
def package(self):
63-
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
64-
cmake = self._configure_cmake()
59+
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
60+
cmake = CMake(self)
6561
cmake.install()
6662

6763
def package_info(self):
68-
self.cpp_info.libs = tools.collect_libs(self)
64+
self.cpp_info.libs = ["kaitai_struct_cpp_stl_runtime"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 7f72825..fa3d4e4 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -1,5 +1,5 @@
6+
-project (kaitai_struct_cpp_stl_runtime CXX)
7+
cmake_minimum_required (VERSION 3.3)
8+
+project (kaitai_struct_cpp_stl_runtime CXX)
9+
10+
set (CMAKE_INCLUDE_CURRENT_DIR ON)
11+
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
cmake_minimum_required(VERSION 3.1)
2-
project(PackageTest CXX)
2+
project(test_package LANGUAGES CXX)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup()
6-
7-
add_executable(test_package test_package.cpp)
8-
target_link_libraries(test_package ${CONAN_LIBS})
4+
find_package(kaitai_struct_cpp_stl_runtime REQUIRED CONFIG)
95

6+
add_executable(${PROJECT_NAME} test_package.cpp)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE kaitai_struct_cpp_stl_runtime::kaitai_struct_cpp_stl_runtime)
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
from conans import ConanFile, CMake, tools
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import cmake_layout, CMake
24
import os
35

46

57
class TestPackageConan(ConanFile):
6-
settings = "os", "compiler", "build_type", "arch"
7-
generators = "cmake"
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
10+
test_type = "explicit"
11+
12+
def requirements(self):
13+
self.requires(self.tested_reference_str)
14+
15+
def layout(self):
16+
cmake_layout(self)
817

918
def build(self):
1019
cmake = CMake(self)
1120
cmake.configure()
1221
cmake.build()
1322

1423
def test(self):
15-
if not tools.cross_building(self.settings):
16-
bin_path = os.path.join("bin", "test_package")
17-
self.run(bin_path, run_environment=True)
24+
if can_run(self):
25+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
26+
self.run(bin_path, env="conanrun")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
8+
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from conans import ConanFile, CMake
2+
from conan.tools.build import cross_building
3+
import os
4+
5+
6+
class TestPackageV1Conan(ConanFile):
7+
settings = "os", "arch", "compiler", "build_type"
8+
generators = "cmake", "cmake_find_package_multi"
9+
10+
def build(self):
11+
cmake = CMake(self)
12+
cmake.configure()
13+
cmake.build()
14+
15+
def test(self):
16+
if not cross_building(self):
17+
bin_path = os.path.join("bin", "test_package")
18+
self.run(bin_path, run_environment=True)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
versions:
2+
"0.10":
3+
folder: all
24
"cci.20210701":
35
folder: all

0 commit comments

Comments
 (0)