Skip to content

Commit 65c7323

Browse files
authored
(#14257) butteraugli: conan v2 support
1 parent 5fa50ad commit 65c7323

File tree

7 files changed

+114
-73
lines changed

7 files changed

+114
-73
lines changed
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
cmake_minimum_required(VERSION 3.4)
2-
project(cmake_wrapper)
1+
cmake_minimum_required(VERSION 3.8)
2+
project(butteraugli LANGUAGES CXX)
33

4-
include(conanbuildinfo.cmake)
5-
conan_basic_setup()
4+
option(BUTTERAUGLI_TOOL "Build comparison tool" ON)
65

7-
if(WIN32 AND BUILD_SHARED_LIBS)
8-
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
9-
endif(WIN32 AND BUILD_SHARED_LIBS)
6+
add_library(butteraugli_lib ${BUTTERAUGLI_SRC_DIR}/butteraugli/butteraugli.cc)
7+
target_include_directories(butteraugli_lib PUBLIC ${BUTTERAUGLI_SRC_DIR})
8+
set_target_properties(butteraugli_lib PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
9+
target_compile_features(butteraugli_lib PUBLIC cxx_std_11)
1010

11-
set(butteraugli_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder)
12-
13-
set(SRCS_FILES ${butteraugli_DIR}/butteraugli/butteraugli.cc)
14-
set(HDRS_FILES ${butteraugli_DIR}/butteraugli/butteraugli.h)
15-
add_library(butteraugli_lib ${SRCS_FILES} ${HDRS_FILES})
16-
target_include_directories(butteraugli_lib PUBLIC ${butteraugli_DIR})
17-
set_property(TARGET butteraugli_lib PROPERTY CXX_STANDARD 11)
18-
19-
find_package(JPEG REQUIRED)
20-
find_package(PNG REQUIRED)
21-
22-
add_library(butteraugli ${butteraugli_DIR}/butteraugli/butteraugli_main.cc)
23-
target_link_libraries(butteraugli butteraugli_lib ${JPEG_LIBRARIES} ${PNG_LIBRARIES})
24-
set_property(TARGET butteraugli PROPERTY CXX_STANDARD 11)
25-
26-
install(TARGETS butteraugli butteraugli_lib
11+
install(
12+
TARGETS butteraugli_lib
2713
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
2814
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
2915
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
3016
)
31-
install(FILES ${HDRS_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/butteraugli)
17+
install(
18+
FILES ${BUTTERAUGLI_SRC_DIR}/butteraugli/butteraugli.h
19+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/butteraugli
20+
)
21+
22+
if(BUTTERAUGLI_TOOL)
23+
find_package(JPEG REQUIRED)
24+
find_package(PNG REQUIRED)
25+
26+
add_executable(butteraugli ${BUTTERAUGLI_SRC_DIR}/butteraugli/butteraugli_main.cc)
27+
target_link_libraries(butteraugli PRIVATE butteraugli_lib JPEG::JPEG PNG::PNG)
28+
target_compile_features(butteraugli PRIVATE cxx_std_11)
29+
30+
install(TARGETS butteraugli DESTINATION ${CMAKE_INSTALL_BINDIR})
31+
endif()

recipes/butteraugli/all/conandata.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ sources:
55
patches:
66
"cci.20190319":
77
- patch_file: "patches/0001-compilation-fixes-for-vs2015.patch"
8-
base_path: "source_subfolder"

recipes/butteraugli/all/conanfile.py

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,84 @@
1+
from conan import ConanFile
2+
from conan.tools.build import check_min_cppstd
3+
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
4+
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get
15
import os
2-
import glob
3-
from conans import ConanFile, CMake, tools
6+
7+
required_conan_version = ">=1.53.0"
8+
49

510
class ButteraugliConan(ConanFile):
611
name = "butteraugli"
712
description = "A tool for measuring perceived differences between images"
813
license = "Apache-2.0"
9-
topics = ("conan", "image", "butteraugli", "diff")
14+
topics = ("image", "diff")
1015
homepage = "https://github.com/google/butteraugli"
1116
url = "https://github.com/conan-io/conan-center-index"
17+
1218
settings = "os", "arch", "compiler", "build_type"
13-
exports_sources = ["CMakeLists.txt", "patches/**"]
14-
generators = "cmake", "cmake_find_package"
1519
options = {
1620
"shared": [True, False],
1721
"fPIC": [True, False],
22+
"tool": [True, False],
1823
}
1924
default_options = {
2025
"shared": False,
2126
"fPIC": True,
27+
"tool": True,
2228
}
2329

24-
_cmake = None
25-
26-
@property
27-
def _source_subfolder(self):
28-
return "source_subfolder"
29-
30-
@property
31-
def _build_subfolder(self):
32-
return "build_subfolder"
30+
def export_sources(self):
31+
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)
32+
export_conandata_patches(self)
3333

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

3838
def configure(self):
3939
if self.options.shared:
40-
del self.options.fPIC
40+
self.options.rm_safe("fPIC")
41+
42+
def layout(self):
43+
cmake_layout(self, src_folder="src")
4144

4245
def requirements(self):
43-
self.requires("libpng/1.6.37")
44-
self.requires("libjpeg/9d")
46+
if self.options.tool:
47+
self.requires("libpng/1.6.38")
48+
self.requires("libjpeg/9e")
4549

46-
def source(self):
47-
tools.get(**self.conan_data["sources"][self.version])
48-
extracted_dir = glob.glob('butteraugli-*/')[0]
49-
os.rename(extracted_dir, self._source_subfolder)
50+
def validate(self):
51+
if self.info.settings.compiler.get_safe("cppstd"):
52+
check_min_cppstd(self, 11)
5053

51-
def _patch_sources(self):
52-
for patch in self.conan_data.get("patches", {}).get(self.version, []):
53-
tools.patch(**patch)
54+
def source(self):
55+
get(self, **self.conan_data["sources"][self.version],
56+
destination=self.source_folder, strip_root=True)
5457

55-
def _configure_cmake(self):
56-
if self._cmake:
57-
return self._cmake
58-
self._cmake = CMake(self)
59-
self._cmake.configure(build_folder=self._build_subfolder)
60-
return self._cmake
58+
def generate(self):
59+
tc = CMakeToolchain(self)
60+
tc.variables["BUTTERAUGLI_SRC_DIR"] = self.source_folder.replace("\\", "/")
61+
tc.variables["BUTTERAUGLI_TOOL"] = self.options.tool
62+
tc.generate()
63+
deps = CMakeDeps(self)
64+
deps.generate()
6165

6266
def build(self):
63-
self._patch_sources()
64-
cmake = self._configure_cmake()
67+
apply_conandata_patches(self)
68+
cmake = CMake(self)
69+
cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
6570
cmake.build()
6671

6772
def package(self):
68-
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
69-
cmake = self._configure_cmake()
73+
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
74+
cmake = CMake(self)
7075
cmake.install()
7176

7277
def package_info(self):
73-
self.cpp_info.libs = tools.collect_libs(self)
74-
if self.settings.os == "Linux":
78+
self.cpp_info.libs = ["butteraugli_lib"]
79+
if self.settings.os in ["Linux", "FreeBSD"]:
7580
self.cpp_info.system_libs = ["m"]
81+
82+
if self.options.tool:
83+
# TODO: to remove in conan v2
84+
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
cmake_minimum_required(VERSION 3.1)
2-
project(test_package)
1+
cmake_minimum_required(VERSION 3.8)
2+
project(test_package LANGUAGES CXX)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup()
4+
find_package(butteraugli REQUIRED CONFIG)
65

76
add_executable(${PROJECT_NAME} test_package.cpp)
8-
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
9-
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE butteraugli::butteraugli)
8+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +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
25

3-
from conans import ConanFile, CMake, tools
46

57
class TestPackageConan(ConanFile):
6-
settings = "os", "compiler", "build_type", "arch"
7-
generators = "cmake"
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)
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: 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)