Skip to content

Commit

Permalink
(#9237) itk: add components
Browse files Browse the repository at this point in the history
* relocatable shared libs on macOS

* bump dependencies

* modernize

* use proper openjpeg target in the patch

* add components

* depend on onetbb recipe instead of deprecated tbb recipe
  • Loading branch information
SpaceIm authored Mar 12, 2022
1 parent 2341f93 commit 4a04b81
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 35 deletions.
2 changes: 1 addition & 1 deletion recipes/itk/all/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10.2)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(KEEP_RPATHS)

# conan created FindXXX.cmake modules that create IMPORTED targets
# that not have the GLOBAL option set. By requiring them here,
Expand Down
10 changes: 5 additions & 5 deletions recipes/itk/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
sources:
"5.1.0":
url: "https://github.com/InsightSoftwareConsortium/ITK/releases/download/v5.1.0/InsightToolkit-5.1.0.tar.gz"
sha256: "121020a1611508cec8123eb5226215598cec07be627d843a2e6b6da891e61d13"
"5.1.2":
url: "https://github.com/InsightSoftwareConsortium/ITK/releases/download/v5.1.2/InsightToolkit-5.1.2.tar.gz"
sha256: "f1e5a78e11125348f68f655c6b89b617c3a8b2c09f710081f621054811a70c98"
patches:
"5.1.0":
url: "https://github.com/InsightSoftwareConsortium/ITK/releases/download/v5.1.0/InsightToolkit-5.1.0.tar.gz"
sha256: "121020a1611508cec8123eb5226215598cec07be627d843a2e6b6da891e61d13"
patches:
"5.1.2":
- patch_file: "patches/0001-find-conan-packages.patch"
base_path: "source_subfolder"
"5.1.2":
"5.1.0":
- patch_file: "patches/0001-find-conan-packages.patch"
base_path: "source_subfolder"
271 changes: 251 additions & 20 deletions recipes/itk/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from conans.errors import ConanInvalidConfiguration
import glob
import os
import textwrap

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.43.0"


class ITKConan(ConanFile):
Expand All @@ -13,7 +14,7 @@ class ITKConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
license = "Apache-2.0"
description = "Insight Segmentation and Registration Toolkit"
exports_sources = "CMakeLists.txt", "patches/**"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -23,9 +24,9 @@ class ITKConan(ConanFile):
"shared": False,
"fPIC": True,
}
generators = "cmake", "cmake_find_package"
short_paths = True

short_paths = True
generators = "cmake", "cmake_find_package"
_cmake = None

@property
Expand All @@ -41,6 +42,11 @@ def _build_subfolder(self):
# - vtk
# - opencv

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand All @@ -50,19 +56,19 @@ def configure(self):
del self.options.fPIC

def requirements(self):
self.requires("libjpeg/9d")
self.requires("dcmtk/3.6.6")
self.requires("double-conversion/3.1.5")
self.requires("eigen/3.3.9")
self.requires("expat/2.4.1")
self.requires("double-conversion/3.2.0")
self.requires("eigen/3.4.0")
self.requires("expat/2.4.3")
self.requires("fftw/3.3.9")
self.requires("gdcm/3.0.9")
self.requires("hdf5/1.12.0")
self.requires("icu/69.1")
self.requires("libtiff/4.2.0")
self.requires("icu/70.1") # TODO: to remove? Seems to be a transitivie dependency through dcmtk
self.requires("libjpeg/9d")
self.requires("libpng/1.6.37")
self.requires("libtiff/4.3.0")
self.requires("openjpeg/2.4.0")
self.requires("tbb/2020.3")
self.requires("onetbb/2020.3")
self.requires("zlib/1.2.11")

@property
Expand Down Expand Up @@ -254,6 +260,27 @@ def package(self):
if os.path.basename(cmake_file) != "UseITK.cmake":
os.remove(cmake_file)

self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{target:"ITK::{}".format(target) for target in self._itk_components.keys()},
)

@staticmethod
def _create_cmake_module_alias_targets(module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""".format(alias=alias, aliased=aliased))
tools.save(module_file, content)

@property
def _module_file_rel_path(self):
return os.path.join(self._cmake_module_dir, "conan-official-{}-targets.cmake".format(self.name))

@property
def _cmake_module_dir(self):
return os.path.join("lib", "cmake", self._itk_subdir)
Expand All @@ -263,15 +290,219 @@ def _itk_subdir(self):
v = tools.Version(self.version)
return "ITK-{}.{}".format(v.major, v.minor)

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self) # FIXME: correct order?
self.cpp_info.includedirs.append(os.path.join("include", self._itk_subdir))
if self.settings.os == "Linux":
self.cpp_info.system_libs.extend(["pthread", "dl", "rt"])
@property
def _itk_components(self):
def libm():
return ["m"] if self.settings.os in ["Linux", "FreeBSD"] else []

# FIXME: use conan components
return {
"itksys": {},
"itkvcl": {"system_libs": libm()},
"itkv3p_netlib": {"system_libs": libm()},
"itkvnl": {"requires": ["itkvcl"]},
"itkvnl_algo": {"requires": ["itkv3p_netlib", "itkvnl"]},
"itktestlib": {"requires": ["itkvcl"]},
"ITKVNLInstantiation": {
"requires": [
"itkvnl_algo", "itkvnl", "itkv3p_netlib", "itkvcl",
],
},
"ITKCommon": {
"requires": [
"itksys", "ITKVNLInstantiation", "eigen::eigen",
"onetbb::onetbb", "double-conversion::double-conversion",
],
"system_libs": libm(),
},
"itkNetlibSlatec": {"requires": ["itkv3p_netlib"]},
"ITKStatistics": {"requires": ["ITKCommon", "itkNetlibSlatec"]},
"ITKTransform": {"requires": ["ITKCommon"]},
"ITKMesh": {"requires": ["ITKTransform"]},
"ITKMetaIO": {"requires": ["zlib::zlib"]},
"ITKSpatialObjects": {"requires": ["ITKTransform", "ITKCommon", "ITKMesh"]},
"ITKPath": {"requires": ["ITKCommon"]},
"ITKImageIntensity": {},
"ITKLabelMap": {
"requires": [
"ITKCommon", "ITKStatistics", "ITKTransform",
"ITKSpatialObjects", "ITKPath",
],
},
"ITKQuadEdgeMesh": {"requires": ["ITKMesh"]},
"ITKFastMarching": {},
"ITKIOImageBase": {"requires": ["ITKCommon"]},
"ITKSmoothing": {},
"ITKImageFeature": {"requires": ["ITKSmoothing", "ITKSpatialObjects"]},
"ITKOptimizers": {"requires": ["ITKStatistics"]},
"ITKPolynomials": {"requires": ["ITKCommon"]},
"ITKBiasCorrection": {
"requires": [
"ITKCommon", "ITKStatistics", "ITKTransform",
"ITKSpatialObjects", "ITKPath",
],
},
"ITKColormap": {},
"ITKFFT": {"requires": ["ITKCommon", "fftw::fftw"]},
"ITKConvolution": {
"requires": [
"ITKFFT", "ITKCommon", "ITKStatistics", "ITKTransform",
"ITKSpatialObjects", "ITKPath",
],
},
"ITKDICOMParser": {},
"ITKDeformableMesh": {
"requires": [
"ITKCommon", "ITKStatistics", "ITKTransform", "ITKImageFeature",
"ITKSpatialObjects", "ITKPath", "ITKMesh",
],
},
"ITKDenoising": {},
"ITKDiffusionTensorImage": {},
"ITKIOXML": {"requires": ["ITKIOImageBase", "expat::expat"]},
"ITKIOSpatialObjects": {"requires": ["ITKSpatialObjects", "ITKIOXML", "ITKMesh"]},
"ITKFEM": {
"requires": [
"ITKCommon", "ITKStatistics", "ITKTransform",
"ITKSpatialObjects", "ITKPath",
"ITKSmoothing", "ITKImageFeature", "ITKOptimizers", "ITKMetaIO",
],
},
"ITKPDEDeformableRegistration": {
"requires": [
"ITKCommon", "ITKStatistics", "ITKTransform",
"ITKSpatialObjects", "ITKPath", "ITKSmoothing",
"ITKImageFeature", "ITKOptimizers",
],
},
"ITKFEMRegistration": {
"requires": [
"ITKFEM", "ITKImageFeature", "ITKCommon", "ITKSpatialObjects",
"ITKTransform", "ITKPDEDeformableRegistration",
],
},
"ITKznz": {"requires": ["zlib::zlib"]},
"ITKniftiio": {"requires": ["ITKznz"], "system_libs": libm()},
"ITKgiftiio": {"requires": ["ITKznz", "ITKniftiio", "expat::expat"]},
"ITKIOBMP": {"requires": ["ITKIOImageBase"]},
"ITKIOBioRad": {"requires": ["ITKIOImageBase"]},
"ITKIOCSV": {"requires": ["ITKIOImageBase"]},
"ITKIODCMTK": {"requires": ["ITKIOImageBase", "dcmtk::dcmtk", "icu::icu"]},
"ITKIOGDCM": {"requires": ["ITKCommon", "ITKIOImageBase", "gdcm::gdcmDICT", "gdcm::gdcmMSFF"]},
"ITKIOIPL": {"requires": ["ITKIOImageBase"]},
"ITKIOGE": {"requires": ["ITKIOIPL", "ITKIOImageBase"]},
"ITKIOGIPL": {"requires": ["ITKIOImageBase", "zlib::zlib"]},
"ITKIOHDF5": {"requires": ["ITKIOImageBase", "hdf5::hdf5"]},
"ITKIOJPEG": {"requires": ["ITKIOImageBase", "libjpeg::libjpeg"]},
"ITKIOMeshBase": {
"requires": [
"ITKCommon", "ITKIOImageBase", "ITKMesh", "ITKQuadEdgeMesh",
],
},
"ITKIOMeshBYU": {"requires": ["ITKCommon", "ITKIOMeshBase"]},
"ITKIOMeshFreeSurfer": {"requires": ["ITKCommon", "ITKIOMeshBase"]},
"ITKIOMeshGifti": {"requires": ["ITKCommon", "ITKIOMeshBase", "ITKgiftiio"]},
"ITKIOMeshOBJ": {"requires": ["ITKCommon", "ITKIOMeshBase"]},
"ITKIOMeshOFF": {"requires": ["ITKCommon", "ITKIOMeshBase"]},
"ITKIOMeshVTK": {"requires": ["ITKCommon", "ITKIOMeshBase", "double-conversion::double-conversion"]},
"ITKIOMeta": {"requires": ["ITKIOImageBase", "ITKMetaIO"]},
"ITKIONIFTI": {"requires": ["ITKIOImageBase", "ITKznz", "ITKniftiio", "ITKTransform"]},
"ITKNrrdIO": {"requires": ["zlib::zlib"]},
"ITKIONRRD": {"requires": ["ITKIOImageBase", "ITKNrrdIO"]},
"ITKIOPNG": {"requires": ["ITKIOImageBase", "libpng::libpng"]},
"ITKIOPhilipsREC": {"requires": ["zlib::zlib"]},
"ITKIOSiemens": {"requires": ["ITKIOImageBase", "ITKIOIPL"]},
"ITKIOStimulate": {"requires": ["ITKIOImageBase"]},
"ITKIOTIFF": {"requires": ["ITKIOImageBase", "libtiff::libtiff"]},
"ITKTransformFactory": {"requires": ["ITKCommon", "ITKTransform"]},
"ITKIOTransformBase": {"requires": ["ITKCommon", "ITKTransform", "ITKTransformFactory"]},
"ITKIOTransformHDF5": {"requires": ["ITKIOTransformBase", "hdf5::hdf5"]},
"ITKIOTransformInsightLegacy": {"requires": ["ITKIOTransformBase", "double-conversion::double-conversion"]},
"ITKIOTransformMatlab": {"requires": ["ITKIOTransformBase"]},
"ITKIOVTK": {"requires": ["ITKIOImageBase"]},
"ITKKLMRegionGrowing": {"requires": ["ITKCommon"]},
"itklbfgs": {},
"ITKMarkovRandomFieldsClassifiers": {
"requires": [
"ITKCommon", "ITKStatistics", "ITKTransform",
"ITKSpatialObjects", "ITKPath",
],
},
"ITKOptimizersv4": {"requires": ["ITKOptimizers", "itklbfgs"]},
"itkopenjpeg": {"header_only": True, "requires": ["openjpeg::openjpeg"]},
"ITKQuadEdgeMeshFiltering": {"requires": ["ITKMesh"]},
"ITKRegionGrowing": {
"requires": [
"ITKCommon", "ITKStatistics", "ITKTransform",
"ITKSpatialObjects", "ITKPath",
],
},
"ITKRegistrationMethodsv4": {
"requires": [
"ITKCommon", "ITKOptimizersv4", "ITKStatistics", "ITKTransform",
"ITKSpatialObjects", "ITKPath", "ITKSmoothing", "ITKImageFeature",
"ITKOptimizers",
],
},
"ITKVTK": {"requires": ["ITKCommon"]},
"ITKWatersheds": {
"requires": [
"ITKCommon", "ITKStatistics", "ITKTransform", "ITKSpatialObjects",
"ITKPath", "ITKSmoothing",
],
},
"ITKReview": {
"requires": [
"ITKCommon", "ITKStatistics", "ITKTransform", "ITKLabelMap",
"ITKSpatialObjects", "ITKPath", "ITKFastMarching", "ITKIOImageBase",
"ITKImageFeature", "ITKOptimizers", "ITKBiasCorrection",
"ITKDeformableMesh", "ITKDiffusionTensorImage", "ITKSmoothing",
"ITKFFT", "ITKIOBMP", "ITKIOBioRad", "ITKIOGDCM", "ITKIOGE",
"ITKIOGIPL", "ITKIOIPL", "ITKIOJPEG", "ITKIOMeta", "ITKIONIFTI",
"ITKIONRRD", "ITKIOPNG", "ITKIOSiemens", "ITKIOStimulate", "ITKIOTIFF",
"ITKIOTransformHDF5", "ITKIOTransformInsightLegacy",
"ITKIOTransformMatlab", "ITKIOVTK", "ITKIOXML", "ITKKLMRegionGrowing",
"ITKMarkovRandomFieldsClassifiers", "ITKMesh", "ITKPDEDeformableRegistration",
"ITKPolynomials", "ITKQuadEdgeMesh", "ITKQuadEdgeMeshFiltering",
"ITKRegionGrowing", "ITKVTK", "ITKWatersheds", "itkopenjpeg",
],
},
"ITKTestKernel": {
"requires": [
"ITKCommon", "ITKIOImageBase", "ITKIOBMP", "ITKIOGDCM", "ITKIOGIPL",
"ITKIOJPEG", "ITKIOMeshBYU", "ITKIOMeshFreeSurfer", "ITKIOMeshGifti",
"ITKIOMeshOBJ", "ITKIOMeshOFF", "ITKIOMeshVTK", "ITKIOMeta", "ITKIONIFTI",
"ITKIONRRD", "ITKIOPNG", "ITKIOTIFF", "ITKIOVTK",
],
},
"ITKVideoCore": {"requires": ["ITKCommon"]},
}

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "ITK")
self.cpp_info.set_property("cmake_build_modules", [os.path.join(self._cmake_module_dir, "UseITK.cmake")])

itk_version = tools.Version(self.version)
lib_suffix = "-{}.{}".format(itk_version.major, itk_version.minor)

for name, values in self._itk_components.items():
is_header_only = values.get("header_only", False)
system_libs = values.get("system_libs", [])
requires = values.get("requires", [])
self.cpp_info.components[name].set_property("cmake_target_name", name)
self.cpp_info.components[name].builddirs.append(self._cmake_module_dir)
self.cpp_info.components[name].includedirs.append(os.path.join("include", self._itk_subdir))
if not is_header_only:
self.cpp_info.components[name].libs = ["{}{}".format(name, lib_suffix)]
self.cpp_info.components[name].system_libs = system_libs
self.cpp_info.components[name].requires = requires

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.components[name].names["cmake_find_package"] = name
self.cpp_info.components[name].names["cmake_find_package_multi"] = name
self.cpp_info.components[name].build_modules.append(os.path.join(self._cmake_module_dir, "UseITK.cmake"))
self.cpp_info.components[name].build_modules["cmake_find_package"].append(self._module_file_rel_path)
self.cpp_info.components[name].build_modules["cmake_find_package_multi"].append(self._module_file_rel_path)

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.names["cmake_find_package"] = "ITK"
self.cpp_info.names["cmake_find_package_multi"] = "ITK"

self.cpp_info.builddirs.append(self._cmake_module_dir)
self.cpp_info.build_modules = [os.path.join(self._cmake_module_dir, "UseITK.cmake")]
2 changes: 1 addition & 1 deletion recipes/itk/all/patches/0001-find-conan-packages.patch
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
-itk_module_target(itkopenjpeg NO_INSTALL)
+find_package(OpenJPEG REQUIRED)
+add_library(itkopenjpeg INTERFACE)
+set_property(TARGET itkopenjpeg PROPERTY INTERFACE_LINK_LIBRARIES OpenJPEG::OpenJPEG)
+set_property(TARGET itkopenjpeg PROPERTY INTERFACE_LINK_LIBRARIES openjp2)
+#target_compile_definitions(itkopenjpeg INTERFACE)
+install(TARGETS itkopenjpeg EXPORT ${ITK3P_INSTALL_EXPORT_NAME})
--- Modules/ThirdParty/TBB/CMakeLists.txt
Expand Down
7 changes: 5 additions & 2 deletions recipes/itk/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(TARGETS)

find_package(ITK REQUIRED CONFIG)
find_package(HDF5 COMPONENTS CXX)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} ITKCommon hdf5::hdf5_cpp)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
Loading

0 comments on commit 4a04b81

Please sign in to comment.