Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cctag: conan v2 support #13402

Merged
merged 8 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions recipes/cctag/all/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion recipes/cctag/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ sources:
patches:
"1.0.1":
- patch_file: "patches/0001-honor-vc-runtime.patch"
base_path: "source_subfolder"
100 changes: 48 additions & 52 deletions recipes/cctag/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import functools
from conan import ConanFile
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 apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rmdir
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.53.0"


class CCTagConan(ConanFile):
Expand Down Expand Up @@ -33,27 +35,22 @@ class CCTagConan(ConanFile):
"with_cuda": False,
}

generators = "cmake", "cmake_find_package"

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

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
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
self.options.rm_safe("fPIC")

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

def requirements(self):
self.requires("boost/1.78.0")
self.requires("boost/1.81.0")
self.requires("eigen/3.4.0")
self.requires("onetbb/2020.3")
self.requires("opencv/4.5.5")
Expand All @@ -67,74 +64,73 @@ def _required_boost_components(self):

def validate(self):
miss_boost_required_comp = \
any(getattr(self.options["boost"],
"without_{}".format(boost_comp),
any(getattr(self.dependencies["boost"].options,
f"without_{boost_comp}",
True) for boost_comp in self._required_boost_components)
if self.options["boost"].header_only or miss_boost_required_comp:
if self.dependencies["boost"].options.header_only or miss_boost_required_comp:
raise ConanInvalidConfiguration(
"{0} requires non header-only boost with these components: {1}".format(
self.name, ", ".join(self._required_boost_components),
)
f"{self.ref} requires non header-only boost with these components: "
f"{', '.join(self._required_boost_components)}",
)

if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 14)
check_min_cppstd(self, 14)

# FIXME: add cuda support
if self.options.with_cuda:
raise ConanInvalidConfiguration("CUDA not supported yet")

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], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CCTAG_SERIALIZE"] = self.options.serialize
tc.variables["CCTAG_VISUAL_DEBUG"] = self.options.visual_debug
tc.variables["CCTAG_NO_COUT"] = self.options.no_cout
tc.variables["CCTAG_WITH_CUDA"] = self.options.with_cuda
tc.variables["CCTAG_BUILD_APPS"] = False
tc.variables["CCTAG_CUDA_CC_CURRENT_ONLY"] = False
tc.variables["CCTAG_NVCC_WARNINGS"] = False
tc.variables["CCTAG_EIGEN_NO_ALIGN"] = True
tc.variables["CCTAG_USE_POSITION_INDEPENDENT_CODE"] = self.options.get_safe("fPIC", True)
tc.variables["CCTAG_ENABLE_SIMD_AVX2"] = False
tc.variables["CCTAG_BUILD_TESTS"] = False
tc.variables["CCTAG_BUILD_DOC"] = False
tc.variables["CCTAG_NO_THRUST_COPY_IF"] = False
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
apply_conandata_patches(self)
# Cleanup RPATH if Apple in shared lib of install tree
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)",
"")
# Link to OpenCV targets
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "CMakeLists.txt"),
replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"),
"${OpenCV_LIBS}",
"opencv_core opencv_videoio opencv_imgproc opencv_imgcodecs")

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["CCTAG_SERIALIZE"] = self.options.serialize
cmake.definitions["CCTAG_VISUAL_DEBUG"] = self.options.visual_debug
cmake.definitions["CCTAG_NO_COUT"] = self.options.no_cout
cmake.definitions["CCTAG_WITH_CUDA"] = self.options.with_cuda
cmake.definitions["CCTAG_BUILD_APPS"] = False
cmake.definitions["CCTAG_CUDA_CC_CURRENT_ONLY"] = False
cmake.definitions["CCTAG_NVCC_WARNINGS"] = False
cmake.definitions["CCTAG_EIGEN_NO_ALIGN"] = True
cmake.definitions["CCTAG_USE_POSITION_INDEPENDENT_CODE"] = self.options.get_safe("fPIC", True)
cmake.definitions["CCTAG_ENABLE_SIMD_AVX2"] = False
cmake.definitions["CCTAG_BUILD_TESTS"] = False
cmake.definitions["CCTAG_BUILD_DOC"] = False
cmake.definitions["CCTAG_NO_THRUST_COPY_IF"] = False
cmake.configure()
return cmake

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

def package(self):
self.copy("COPYING.md", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "COPYING.md", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "CCTag")
self.cpp_info.set_property("cmake_target_name", "CCTag::CCTag")
suffix = "d" if self.settings.build_type == "Debug" else ""
self.cpp_info.libs = ["CCTag{}".format(suffix)]
self.cpp_info.libs = [f"CCTag{suffix}"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["dl", "pthread"])
self.cpp_info.requires = [
Expand Down
7 changes: 2 additions & 5 deletions recipes/cctag/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
project(test_package LANGUAGES CXX)

find_package(CCTag REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} CCTag::CCTag)
target_link_libraries(${PROJECT_NAME} PRIVATE CCTag::CCTag)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
19 changes: 14 additions & 5 deletions recipes/cctag/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
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", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
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):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, 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/cctag/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/cctag/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)