Skip to content

Commit

Permalink
conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm committed Nov 19, 2022
1 parent 6f18438 commit ac9afa5
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 78 deletions.
52 changes: 22 additions & 30 deletions recipes/jpeg-compressor/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
cmake_minimum_required(VERSION 3.4)
project(jpeg-compressor)

include(conanbuildinfo.cmake)
conan_basic_setup()

set(JPEGCOMPRESSOR_SOURCE_SUBFOLDER "${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder")

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
cmake_minimum_required(VERSION 3.8)
project(jpeg-compressor LANGUAGES CXX)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

# jgpd lib

set(JPGD_SRC_LIST ${JPEGCOMPRESSOR_SOURCE_SUBFOLDER}/jpgd.cpp)
set(JPGD_HDR_LIST ${JPEGCOMPRESSOR_SOURCE_SUBFOLDER}/jpgd.h ${JPEGCOMPRESSOR_SOURCE_SUBFOLDER}/jpgd_idct.h)
add_library(jpgd ${JPGD_SRC_LIST} ${JPGD_HDR_LIST})
target_include_directories(jpgd PUBLIC ${JPEGCOMPRESSOR_SOURCE_SUBFOLDER})

install(TARGETS jpgd)
install(FILES ${JPGD_HDR_LIST} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# jgpe lib

set(JPGE_SRC_LIST ${JPEGCOMPRESSOR_SOURCE_SUBFOLDER}/jpge.cpp)
set(JPGE_HDR_LIST ${JPEGCOMPRESSOR_SOURCE_SUBFOLDER}/jpge.h ${JPEGCOMPRESSOR_SOURCE_SUBFOLDER}/jpge.h)
add_library(jpge ${JPGE_SRC_LIST} ${JPGE_HDR_LIST})
target_include_directories(jpge PUBLIC ${JPEGCOMPRESSOR_SOURCE_SUBFOLDER})

install(TARGETS jpge)
install(FILES ${JPGE_HDR_LIST} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# jpgd lib
set(JPGD_HDR_LIST ${JPEGCOMPRESSOR_SRC_DIR}/jpgd.h ${JPEGCOMPRESSOR_SRC_DIR}/jpgd_idct.h)
add_library(jpgd ${JPEGCOMPRESSOR_SRC_DIR}/jpgd.cpp)
target_include_directories(jpgd PUBLIC ${JPEGCOMPRESSOR_SRC_DIR})
target_compile_features(jpgd PRIVATE cxx_std_11)

# jpge lib
set(JPGE_HDR_LIST ${JPEGCOMPRESSOR_SRC_DIR}/jpge.h ${JPEGCOMPRESSOR_SRC_DIR}/jpge.h)
add_library(jpge ${JPEGCOMPRESSOR_SRC_DIR}/jpge.cpp)
target_include_directories(jpge PUBLIC ${JPEGCOMPRESSOR_SRC_DIR})
target_compile_features(jpge PRIVATE cxx_std_11)

include(GNUInstallDirs)
install(
TARGETS jpgd jpge
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBIR}
)
install(FILES ${JPGD_HDR_LIST} ${JPGE_HDR_LIST} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1 change: 0 additions & 1 deletion recipes/jpeg-compressor/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ sources:
patches:
"cci.20200507":
- patch_file: "patches/pr-18-remove-include-malloc.patch"
base_path: "source_subfolder"
71 changes: 36 additions & 35 deletions recipes/jpeg-compressor/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, save
from conan.tools.microsoft import is_msvc_static_runtime
import os
import glob
from conans import ConanFile, tools, CMake
from conans.errors import ConanInvalidConfiguration

required_conan_version = ">=1.53.0"


class JpegCompressorConan(ConanFile):
name = "jpeg-compressor"
description = "C++ JPEG compression/fuzzed low-RAM JPEG decompression codec with Public Domain or Apache 2.0 license"
homepage = "https://github.com/richgel999/jpeg-compressor"
topics = ("conan", "jpeg", "image", "compression", "decompression")
topics = ("jpeg", "image", "compression", "decompression")
url = "https://github.com/conan-io/conan-center-index"
license = "Unlicense", "Apache-2.0", "MIT"

settings = "os", "arch", "compiler", "build_type"
generators = "cmake"
exports_sources = ["CMakeLists.txt", "patches/*"]
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -23,57 +27,54 @@ class JpegCompressorConan(ConanFile):
"fPIC": True,
}

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"
def export_sources(self):
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)
export_conandata_patches(self)

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

def configure(self):
if self.options.shared:
del self.options.fPIC
if self.settings.compiler == "Visual Studio" and "MT" in self.settings.compiler.runtime:
raise ConanInvalidConfiguration("Visual Studio build for shared library with MT runtime is not supported")
self.options.rm_safe("fPIC")

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

def validate(self):
if self.info.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)
if self.info.options.shared and is_msvc_static_runtime(self):
raise ConanInvalidConfiguration("Visual Studio build for shared library with MT runtime is not supported")

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 _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure()
return self._cmake
def generate(self):
tc = CMakeToolchain(self)
tc.variables["JPEGCOMPRESSOR_SRC_DIR"] = self.source_folder.replace("\\", "/")
tc.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
cmake.build()

def _extract_license(self):
with open(os.path.join(self._source_subfolder, "jpge.cpp")) as f:
with open(os.path.join(self.source_folder, "jpge.cpp")) as f:
content_lines = f.readlines()
license_content = []
for i in range(4, 20):
license_content.append(content_lines[i][3:-1])
return "\n".join(license_content)

def package(self):
cmake = self._configure_cmake()
save(self, os.path.join(self.package_folder, "licenses", "LICENCE.txt"), self._extract_license())
cmake = CMake(self)
cmake.install()
self._extract_license()
tools.save(os.path.join(self.package_folder, "licenses", "LICENCE.txt"), self._extract_license())

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.libs = ["jpgd", "jpge"]
11 changes: 5 additions & 6 deletions recipes/jpeg-compressor/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(jpeg-compressor REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_link_libraries(${PROJECT_NAME} PRIVATE jpeg-compressor::jpeg-compressor)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
21 changes: 15 additions & 6 deletions recipes/jpeg-compressor/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
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"
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):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
img_path = os.path.join(self.source_folder, "testimg.jpg")
bin_path = os.path.join("bin", "test_package")
self.run("{} {}".format(bin_path, img_path), run_environment=True)
self.run(f"{bin_path} {img_path}", env="conanrun")
8 changes: 8 additions & 0 deletions recipes/jpeg-compressor/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)
18 changes: 18 additions & 0 deletions recipes/jpeg-compressor/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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")
img_path = os.path.join(self.source_folder, os.pardir, "test_package", "testimg.jpg")
self.run(f"{bin_path} {img_path}", run_environment=True)

0 comments on commit ac9afa5

Please sign in to comment.