Skip to content

Commit

Permalink
(#14323) heatshrink: conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored Nov 29, 2022
1 parent afcf3ba commit cb85824
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 65 deletions.
47 changes: 20 additions & 27 deletions recipes/heatshrink/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
cmake_minimum_required(VERSION 3.4)
project(heatshrink C)
cmake_minimum_required(VERSION 3.8)
project(heatshrink LANGUAGES C)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup()

if (WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

SET(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder")

SET (CMAKE_C_STANDARD 99)
LIST(APPEND SRC_HEATSHRINK
"${SOURCE_DIR}/heatshrink_decoder.c"
"${SOURCE_DIR}/heatshrink_encoder.c")

include_directories(${SOURCE_DIR})

add_library(heatshrink ${SRC_HEATSHRINK})
add_library(heatshrink
${HEATSHRINK_SRC_DIR}/heatshrink_decoder.c
${HEATSHRINK_SRC_DIR}/heatshrink_encoder.c
)
target_include_directories(heatshrink PUBLIC ${HEATSHRINK_SRC_DIR})
set_target_properties(heatshrink PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
target_compile_features(heatshrink PRIVATE c_std_99)

include(GNUInstallDirs)
install(
FILES
${SOURCE_DIR}/heatshrink_common.h
${SOURCE_DIR}/heatshrink_config.h
${SOURCE_DIR}/heatshrink_decoder.h
${SOURCE_DIR}/heatshrink_encoder.h
${HEATSHRINK_SRC_DIR}/heatshrink_common.h
${HEATSHRINK_SRC_DIR}/heatshrink_config.h
${HEATSHRINK_SRC_DIR}/heatshrink_decoder.h
${HEATSHRINK_SRC_DIR}/heatshrink_encoder.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(
TARGETS heatshrink
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
54 changes: 28 additions & 26 deletions recipes/heatshrink/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, replace_in_file
import os

from conans import ConanFile, CMake, tools
required_conan_version = ">=1.53.0"

required_conan_version = ">=1.36.0"

class HeatshrinkConan(ConanFile):
name = "heatshrink"
Expand All @@ -11,9 +13,8 @@ class HeatshrinkConan(ConanFile):
description = "data compression library for embedded/real-time systems"
topics = ("compression", "embedded", "realtime")
homepage = "https://github.com/atomicobject/heatshrink"
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
exports_sources = "CMakeLists.txt"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [False, True],
"fPIC": [True, False],
Expand All @@ -29,54 +30,55 @@ class HeatshrinkConan(ConanFile):
"use_index": True,
}

@property
def _source_subfolder(self):
return "source_subfolder"
exports_sources = "CMakeLists.txt"

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

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

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

def source(self):
tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["HEATSHRINK_SRC_DIR"] = self.source_folder.replace("\\", "/")
tc.generate()

def _patch_sources(self):
config_file = os.path.join(self._source_subfolder, "heatshrink_config.h")
config_file = os.path.join(self.source_folder, "heatshrink_config.h")
if not self.options.dynamic_alloc:
tools.replace_in_file(config_file,
replace_in_file(self, config_file,
"#define HEATSHRINK_DYNAMIC_ALLOC 1",
"#define HEATSHRINK_DYNAMIC_ALLOC 0")
if self.options.debug_log:
tools.replace_in_file(config_file,
replace_in_file(self, config_file,
"#define HEATSHRINK_DEBUGGING_LOGS 0",
"#define HEATSHRINK_DEBUGGING_LOGS 1")
if not self.options.use_index:
tools.replace_in_file(config_file,
replace_in_file(self, config_file,
"#define HEATSHRINK_USE_INDEX 1",
"#define HEATSHRINK_USE_INDEX 0")

def _configure_cmake(self):
cmake = CMake(self)
cmake.configure()
return cmake

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
cmake.build()

def package(self):
self.copy("LICENSE", "licenses", self._source_subfolder)

cmake = self._configure_cmake()
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["heatshrink"]

9 changes: 3 additions & 6 deletions recipes/heatshrink/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)
project(test_package LANGUAGES C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(heatshrink CONFIG REQUIRED)
find_package(heatshrink REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} heatshrink::heatshrink)
target_link_libraries(${PROJECT_NAME} PRIVATE heatshrink::heatshrink)
23 changes: 17 additions & 6 deletions recipes/heatshrink/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,15 +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 DawHeaderLibrariesTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

class TestPackageConan(ConanFile):
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):
self.run(os.path.join("bin", "test_package"), 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/heatshrink/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/heatshrink/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 cb85824

Please sign in to comment.