Skip to content

Commit cb85824

Browse files
authored
(#14323) heatshrink: conan v2 support
1 parent afcf3ba commit cb85824

File tree

6 files changed

+93
-65
lines changed

6 files changed

+93
-65
lines changed

recipes/heatshrink/all/CMakeLists.txt

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
1-
cmake_minimum_required(VERSION 3.4)
2-
project(heatshrink C)
1+
cmake_minimum_required(VERSION 3.8)
2+
project(heatshrink LANGUAGES C)
33

4-
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
5-
conan_basic_setup()
6-
7-
if (WIN32)
8-
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
9-
endif()
10-
11-
SET(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder")
12-
13-
SET (CMAKE_C_STANDARD 99)
14-
LIST(APPEND SRC_HEATSHRINK
15-
"${SOURCE_DIR}/heatshrink_decoder.c"
16-
"${SOURCE_DIR}/heatshrink_encoder.c")
17-
18-
include_directories(${SOURCE_DIR})
19-
20-
add_library(heatshrink ${SRC_HEATSHRINK})
4+
add_library(heatshrink
5+
${HEATSHRINK_SRC_DIR}/heatshrink_decoder.c
6+
${HEATSHRINK_SRC_DIR}/heatshrink_encoder.c
7+
)
8+
target_include_directories(heatshrink PUBLIC ${HEATSHRINK_SRC_DIR})
9+
set_target_properties(heatshrink PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
10+
target_compile_features(heatshrink PRIVATE c_std_99)
2111

12+
include(GNUInstallDirs)
2213
install(
2314
FILES
24-
${SOURCE_DIR}/heatshrink_common.h
25-
${SOURCE_DIR}/heatshrink_config.h
26-
${SOURCE_DIR}/heatshrink_decoder.h
27-
${SOURCE_DIR}/heatshrink_encoder.h
15+
${HEATSHRINK_SRC_DIR}/heatshrink_common.h
16+
${HEATSHRINK_SRC_DIR}/heatshrink_config.h
17+
${HEATSHRINK_SRC_DIR}/heatshrink_decoder.h
18+
${HEATSHRINK_SRC_DIR}/heatshrink_encoder.h
2819
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
2920
)
3021

31-
install(TARGETS ${PROJECT_NAME}
32-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
33-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
34-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
22+
install(
23+
TARGETS heatshrink
24+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
25+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
26+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
27+
)

recipes/heatshrink/all/conanfile.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from conan import ConanFile
2+
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
3+
from conan.tools.files import copy, get, replace_in_file
14
import os
25

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

5-
required_conan_version = ">=1.36.0"
68

79
class HeatshrinkConan(ConanFile):
810
name = "heatshrink"
@@ -11,9 +13,8 @@ class HeatshrinkConan(ConanFile):
1113
description = "data compression library for embedded/real-time systems"
1214
topics = ("compression", "embedded", "realtime")
1315
homepage = "https://github.com/atomicobject/heatshrink"
14-
settings = "os", "compiler", "build_type", "arch"
15-
generators = "cmake"
16-
exports_sources = "CMakeLists.txt"
16+
17+
settings = "os", "arch", "compiler", "build_type"
1718
options = {
1819
"shared": [False, True],
1920
"fPIC": [True, False],
@@ -29,54 +30,55 @@ class HeatshrinkConan(ConanFile):
2930
"use_index": True,
3031
}
3132

32-
@property
33-
def _source_subfolder(self):
34-
return "source_subfolder"
33+
exports_sources = "CMakeLists.txt"
3534

3635
def config_options(self):
3736
if self.settings.os == "Windows":
3837
del self.options.fPIC
3938

4039
def configure(self):
4140
if self.options.shared:
42-
del self.options.fPIC
43-
del self.settings.compiler.libcxx
44-
del self.settings.compiler.cppstd
41+
self.options.rm_safe("fPIC")
42+
self.settings.rm_safe("compiler.cppstd")
43+
self.settings.rm_safe("compiler.libcxx")
44+
45+
def layout(self):
46+
cmake_layout(self, src_folder="src")
4547

4648
def source(self):
47-
tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)
49+
get(self, **self.conan_data["sources"][self.version],
50+
destination=self.source_folder, strip_root=True)
51+
52+
def generate(self):
53+
tc = CMakeToolchain(self)
54+
tc.variables["HEATSHRINK_SRC_DIR"] = self.source_folder.replace("\\", "/")
55+
tc.generate()
4856

4957
def _patch_sources(self):
50-
config_file = os.path.join(self._source_subfolder, "heatshrink_config.h")
58+
config_file = os.path.join(self.source_folder, "heatshrink_config.h")
5159
if not self.options.dynamic_alloc:
52-
tools.replace_in_file(config_file,
60+
replace_in_file(self, config_file,
5361
"#define HEATSHRINK_DYNAMIC_ALLOC 1",
5462
"#define HEATSHRINK_DYNAMIC_ALLOC 0")
5563
if self.options.debug_log:
56-
tools.replace_in_file(config_file,
64+
replace_in_file(self, config_file,
5765
"#define HEATSHRINK_DEBUGGING_LOGS 0",
5866
"#define HEATSHRINK_DEBUGGING_LOGS 1")
5967
if not self.options.use_index:
60-
tools.replace_in_file(config_file,
68+
replace_in_file(self, config_file,
6169
"#define HEATSHRINK_USE_INDEX 1",
6270
"#define HEATSHRINK_USE_INDEX 0")
6371

64-
def _configure_cmake(self):
65-
cmake = CMake(self)
66-
cmake.configure()
67-
return cmake
68-
6972
def build(self):
7073
self._patch_sources()
71-
cmake = self._configure_cmake()
74+
cmake = CMake(self)
75+
cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
7276
cmake.build()
7377

7478
def package(self):
75-
self.copy("LICENSE", "licenses", self._source_subfolder)
76-
77-
cmake = self._configure_cmake()
79+
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
80+
cmake = CMake(self)
7881
cmake.install()
7982

8083
def package_info(self):
8184
self.cpp_info.libs = ["heatshrink"]
82-
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
cmake_minimum_required(VERSION 3.1)
2-
project(test_package C)
2+
project(test_package LANGUAGES C)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup(TARGETS)
6-
7-
find_package(heatshrink CONFIG REQUIRED)
4+
find_package(heatshrink REQUIRED CONFIG)
85

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

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

818
def build(self):
919
cmake = CMake(self)
1020
cmake.configure()
1121
cmake.build()
1222

1323
def test(self):
14-
if not tools.cross_building(self):
15-
self.run(os.path.join("bin", "test_package"), 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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from conans import ConanFile, CMake, tools
2+
import os
3+
4+
5+
class TestPackageConan(ConanFile):
6+
settings = "os", "arch", "compiler", "build_type"
7+
generators = "cmake", "cmake_find_package_multi"
8+
9+
def build(self):
10+
cmake = CMake(self)
11+
cmake.configure()
12+
cmake.build()
13+
14+
def test(self):
15+
if not tools.cross_building(self):
16+
bin_path = os.path.join("bin", "test_package")
17+
self.run(bin_path, run_environment=True)

0 commit comments

Comments
 (0)