Skip to content

Commit

Permalink
address reviews in conan-io#13722
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm committed Dec 9, 2022
1 parent a076f03 commit ef3ac7d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 141 deletions.
178 changes: 52 additions & 126 deletions recipes/wavelet_buffer/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout
from conan.tools.files import get, copy, rmdir
from conan.tools.microsoft import check_min_vs, is_msvc
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rmdir
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration

import os

required_conan_version = ">=1.50"
required_conan_version = ">=1.53.0"


class WaveletBufferConan(ConanFile):
Expand All @@ -18,160 +17,87 @@ class WaveletBufferConan(ConanFile):
topics = ("compression", "signal-processing", "wavelet")
homepage = "https://github.com/panda-official/WaveletBuffer"
url = "https://github.com/conan-io/conan-center-index"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"cimg/*:enable_fftw": False,
"cimg/*:enable_jpeg": False,
"cimg/*:enable_openexr": False,
"cimg/*:enable_png": False,
"cimg/*:enable_tiff": False,
"cimg/*:enable_ffmpeg": False,
"cimg/*:enable_opencv": False,
"shared": False,
"fPIC": True,
}

# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
@property
def _min_cppstd(self):
return 20

def requirements(self):
self.requires("openblas/0.3.20")
self.requires("blaze/3.8")
self.requires("libjpeg-turbo/2.1.2")
self.requires("cimg/3.0.2")
@property
def _minimum_compilers_version(self):
return {
"gcc": "8",
"clang": "12",
"apple-clang": "12",
"Visual Studio": "16",
"msvc": "192",
}

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

def configure(self):
if self.options.shared:
try:
del self.options.fPIC
except Exception:
pass

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

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CONAN_EXPORTED"] = True
tc.generate()

tc = CMakeDeps(self)
tc.generate()

@property
def _minimum_cpp_standard(self):
return 20

@property
def _minimum_compilers_version(self):
return {
"gcc": "8",
"clang": "12",
"apple-clang": "12",
}
def requirements(self):
self.requires("blaze/3.8")
self.requires("cimg/3.0.2")
self.requires("libjpeg-turbo/2.1.2")
self.requires("openblas/0.3.20")

def validate(self):
if self.info.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._minimum_cpp_standard)

# Compiler version check
check_min_vs(self, 192)
if not is_msvc(self):
minimum_version = self._minimum_compilers_version.get(
str(self.info.settings.compiler), False
)
if not minimum_version:
self.output.warn(
"{} recipe lacks information about the {} compiler support.".format(
self.name, self.settings.compiler
)
)
else:
if Version(self.info.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
"{} requires C++{} support. The current compiler {} {} does not support it.".format(
self.ref,
self._minimum_cpp_standard,
self.settings.compiler,
self.settings.compiler.version,
)
)

if is_msvc(self) and self.info.options.shared:
raise ConanInvalidConfiguration(
f"{self.ref} can not be built as shared on Visual Studio and msvc."
)
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)

# Dependency options check
cimg = self.dependencies["cimg"]
if cimg.options.enable_fftw:
raise ConanInvalidConfiguration(
f"{self.ref} requires the option 'cimg:enable_fftw=False'"
)
if cimg.options.enable_jpeg:
raise ConanInvalidConfiguration(
f"{self.ref} requires the option 'cimg:enable_jpeg=False'"
)
if cimg.options.enable_openexr:
raise ConanInvalidConfiguration(
f"{self.ref} requires the option 'cimg:enable_openexr=False'"
)
if cimg.options.enable_tiff:
raise ConanInvalidConfiguration(
f"{self.ref} requires the option 'cimg:enable_tiff=False'"
)
if cimg.options.enable_png:
raise ConanInvalidConfiguration(
f"{self.ref} requires the option 'cimg:enable_png=False'"
)
if cimg.options.enable_ffmpeg:
minimum_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires the option 'cimg:enable_ffmpeg=False'"
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)
if cimg.options.enable_opencv:

if is_msvc(self) and self.options.shared:
raise ConanInvalidConfiguration(
f"{self.ref} requires the option 'cimg:enable_opencv=False'"
f"{self.ref} can not be built as shared on Visual Studio and msvc."
)

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CONAN_EXPORTED"] = True
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(
self,
pattern="LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder,
)

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

rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.libs = ["wavelet_buffer", "sf_compressor"]
self.cpp_info.set_property("cmake_file_name", "wavelet_buffer")
self.cpp_info.set_property(
"cmake_target_name", "wavelet_buffer::wavelet_buffer"
)

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "wavelet_buffer"
self.cpp_info.filenames["cmake_find_package_multi"] = "wavelet_buffer"
self.cpp_info.names["cmake_find_package"] = "wavelet_buffer"
self.cpp_info.names["cmake_find_package_multi"] = "wavelet_buffer"
self.cpp_info.set_property("cmake_target_name", "wavelet_buffer::wavelet_buffer")
8 changes: 4 additions & 4 deletions recipes/wavelet_buffer/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(WaveletBufferTest CXX)
cmake_minimum_required(VERSION 3.12)
project(WaveletBufferTest LANGUAGES CXX)

find_package(wavelet_buffer CONFIG REQUIRED)

add_executable(test_package test_package.cpp)
target_compile_features(test_package PUBLIC cxx_std_20)
target_link_libraries(test_package wavelet_buffer::wavelet_buffer)
target_compile_features(test_package PRIVATE cxx_std_20)
target_link_libraries(test_package PRIVATE wavelet_buffer::wavelet_buffer)
17 changes: 7 additions & 10 deletions recipes/wavelet_buffer/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import os

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake
from conan.tools.layout import cmake_layout
from conan.tools.cmake import CMake, cmake_layout
import os


class HelloTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"

test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

Expand All @@ -20,9 +20,6 @@ def build(self):
cmake.configure()
cmake.build()

def layout(self):
cmake_layout(self)

def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindirs[0], "test_package")
Expand Down
1 change: 0 additions & 1 deletion recipes/wavelet_buffer/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os


# legacy validation with Conan 1.x
class TestPackageV1Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
Expand Down

0 comments on commit ef3ac7d

Please sign in to comment.