Skip to content

Commit

Permalink
(conan-io#13402) cctag: conan v2 support
Browse files Browse the repository at this point in the history
* conan v2 support

* bump boost

* modernize more

* add patch fields

* back to boost 1.80.0

waiting bugfix in boost phoenix 1.81.0, otherwise it breaks cctag shared libs build due to duplicated definitions (see boostorg/phoenix#111).

* bump boost

* raise for the specific configuration which cannot be built in c3i due to mising pre-built binary of onetbb shared with static runtime

* back to boost 1.80.0 again
  • Loading branch information
SpaceIm authored and StellaSmith committed Feb 2, 2023
1 parent fb3f51b commit d48b63c
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 70 deletions.
7 changes: 0 additions & 7 deletions recipes/cctag/all/CMakeLists.txt

This file was deleted.

3 changes: 2 additions & 1 deletion recipes/cctag/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ sources:
patches:
"1.0.1":
- patch_file: "patches/0001-honor-vc-runtime.patch"
base_path: "source_subfolder"
patch_description: "Honor vc runtime"
patch_type: "conan"
105 changes: 53 additions & 52 deletions recipes/cctag/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
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
from conan.tools.microsoft import is_msvc_static_runtime
import os

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


class CCTagConan(ConanFile):
Expand Down Expand Up @@ -33,27 +36,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.80.0")
self.requires("eigen/3.4.0")
self.requires("onetbb/2020.3")
self.requires("opencv/4.5.5")
Expand All @@ -67,74 +65,77 @@ 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 == "Visual Studio" and not self.options.shared and \
is_msvc_static_runtime(self) and self.dependencies["onetbb"].options.shared:
raise ConanInvalidConfiguration("this specific configuration is prevented due to internal c3i limitations")

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)

0 comments on commit d48b63c

Please sign in to comment.