From 252118ab6637c7805a925fb8c92e3f5678694f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Mon, 16 Sep 2024 17:02:22 +0200 Subject: [PATCH] (#25246) Add ITK 5.3.0 * Add ITK 5.3.0 --------- Co-authored-by: Ray Co-authored-by: Uilian Ries * Add missing patch * Fix test v1 package Signed-off-by: Uilian Ries * Simplify itk cmake dir Signed-off-by: Uilian Ries --------- Signed-off-by: Uilian Ries Co-authored-by: Ray Co-authored-by: Uilian Ries --- recipes/itk/all/conandata.yml | 7 + recipes/itk/all/conanfile.py | 47 ++++- .../patches/0002-find-conan-packages.patch | 189 ++++++++++++++++++ recipes/itk/config.yml | 2 + 4 files changed, 238 insertions(+), 7 deletions(-) create mode 100644 recipes/itk/all/patches/0002-find-conan-packages.patch diff --git a/recipes/itk/all/conandata.yml b/recipes/itk/all/conandata.yml index 9e7f86e6f5246..74a479bc9586a 100644 --- a/recipes/itk/all/conandata.yml +++ b/recipes/itk/all/conandata.yml @@ -1,4 +1,7 @@ sources: + "5.3.0": + url: "https://github.com/InsightSoftwareConsortium/ITK/releases/download/v5.3.0/InsightToolkit-5.3.0.tar.gz" + sha256: "57a4471133dc8f76bde3d6eb45285c440bd40d113428884a1487472b7b71e383" "5.1.2": url: "https://github.com/InsightSoftwareConsortium/ITK/releases/download/v5.1.2/InsightToolkit-5.1.2.tar.gz" sha256: "f1e5a78e11125348f68f655c6b89b617c3a8b2c09f710081f621054811a70c98" @@ -6,6 +9,10 @@ sources: url: "https://github.com/InsightSoftwareConsortium/ITK/releases/download/v5.1.0/InsightToolkit-5.1.0.tar.gz" sha256: "121020a1611508cec8123eb5226215598cec07be627d843a2e6b6da891e61d13" patches: + "5.3.0": + - patch_file: "patches/0002-find-conan-packages.patch" + patch_description: "inject thirdparties from conan" + patch_type: "conan" "5.1.2": - patch_file: "patches/0001-find-conan-packages.patch" patch_description: "inject thirdparties from conan" diff --git a/recipes/itk/all/conanfile.py b/recipes/itk/all/conanfile.py index 61b826eb365a1..0ab11f37d60c6 100644 --- a/recipes/itk/all/conanfile.py +++ b/recipes/itk/all/conanfile.py @@ -1,6 +1,7 @@ from conan import ConanFile from conan.tools.build import check_min_cppstd from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.env import VirtualBuildEnv from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rmdir, save from conan.tools.microsoft import check_min_vs, is_msvc from conan.tools.scm import Version @@ -80,6 +81,10 @@ def requirements(self): self.requires("onetbb/2021.9.0") self.requires("zlib/[>=1.2.11 <2]") + def build_requirements(self): + if Version(self.version) >= "5.3.0": + self.tool_requires("cmake/[>=3.16.3 <4]") + def validate(self): if self.options.shared and not self.dependencies["hdf5"].options.shared: raise ConanInvalidConfiguration("When building a shared itk, hdf5 needs to be shared too (or not linked to by the consumer).\n" @@ -107,6 +112,9 @@ def generate(self): tc.variables["BUILD_EXAMPLES"] = False tc.variables["BUILD_TESTING"] = False tc.variables["BUILD_DOCUMENTATION"] = False + tc.variables["DO_NOT_BUILD_ITK_TEST_DRIVER"] = True + tc.variables["DO_NOT_INSTALL_ITK_TEST_DRIVER"] = True + tc.variables["DISABLE_MODULE_TESTS"] = True tc.variables["ITK_SKIP_PATH_LENGTH_CHECKS"] = True tc.variables["ITK_USE_SYSTEM_LIBRARIES"] = True @@ -238,6 +246,9 @@ def generate(self): tc = CMakeDeps(self) tc.generate() + venv = VirtualBuildEnv(self) + venv.generate() + def _patch_sources(self): apply_conandata_patches(self) #The CMake policy CMP0091 must be NEW, but is '' @@ -261,6 +272,10 @@ def _itk_subdir(self): def _cmake_module_dir(self): return os.path.join("lib", "cmake", self._itk_subdir) + @property + def _module_variables_file_rel_path(self): + return os.path.join(self._cmake_module_dir, f"conan-official-{self.name}-variables.cmake") + @property def _module_file_rel_path(self): return os.path.join(self._cmake_module_dir, f"conan-official-{self.name}-targets.cmake") @@ -455,6 +470,10 @@ def libdl(): "ITKVideoCore": {"requires": ["ITKCommon"]}, } + def _create_cmake_module_variables(self): + content = 'set(ITK_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}")' + save(self, os.path.join(self.package_folder, self._module_variables_file_rel_path), content) + def _create_cmake_module_alias_targets(self): targets = {target:f"ITK::{target}" for target in self._itk_components.keys()} content = "" @@ -467,6 +486,14 @@ def _create_cmake_module_alias_targets(self): """) save(self, os.path.join(self.package_folder, self._module_file_rel_path), content) + @property + def _itk_modules_files(self): + cmake_files = [] + if Version(self.version) >= "5.3": + cmake_files.extend(["ITKFactoryRegistration.cmake", "ITKInitializeCXXStandard.cmake"]) + cmake_files.append("UseITK.cmake") + return cmake_files + def package(self): copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) cmake = CMake(self) @@ -475,18 +502,23 @@ def package(self): rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) rmdir(self, os.path.join(self.package_folder, "share")) rmdir(self, os.path.join(self.package_folder, self._cmake_module_dir, "Modules")) - # Do not remove UseITK.cmake and *.h.in files + + # Do not remove UseITK.cmake, ITKFactoryRegistration.cmake, ITKInitializeCXXStandard.cmake and *.h.in files for cmake_file in glob.glob(os.path.join(self.package_folder, self._cmake_module_dir, "*.cmake")): - if os.path.basename(cmake_file) != "UseITK.cmake": + file_name = os.path.basename(cmake_file) + if file_name not in self._itk_modules_files: os.remove(cmake_file) + + self._create_cmake_module_variables() self._create_cmake_module_alias_targets() 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 = Version(self.version) lib_suffix = f"-{itk_version.major}.{itk_version.minor}" + build_modules = [self._module_variables_file_rel_path] + build_modules.extend([os.path.join(self._cmake_module_dir, f) for f in self._itk_modules_files]) + self.cpp_info.set_property("cmake_file_name", "ITK") + self.cpp_info.set_property("cmake_build_modules", build_modules) for name, values in self._itk_components.items(): is_header_only = values.get("header_only", False) @@ -504,8 +536,9 @@ def package_info(self): # TODO: to remove in conan v2 once cmake_find_package* generators removed for generator in ["cmake_find_package", "cmake_find_package_multi"]: self.cpp_info.components[name].names[generator] = name - self.cpp_info.components[name].build_modules[generator].append(self._module_file_rel_path) - self.cpp_info.components[name].build_modules[generator].append(os.path.join(self._cmake_module_dir, "UseITK.cmake")) + self.cpp_info.components[name].build_modules[generator].extend([self._module_file_rel_path, self._module_variables_file_rel_path]) + self.cpp_info.components[name].build_modules[generator].extend( + [os.path.join(self._cmake_module_dir, f) for f in self._itk_modules_files]) # TODO: to remove in conan v2 once cmake_find_package* generators removed for generator in ["cmake_find_package", "cmake_find_package_multi"]: diff --git a/recipes/itk/all/patches/0002-find-conan-packages.patch b/recipes/itk/all/patches/0002-find-conan-packages.patch new file mode 100644 index 0000000000000..34b81a5788250 --- /dev/null +++ b/recipes/itk/all/patches/0002-find-conan-packages.patch @@ -0,0 +1,189 @@ +--- Modules/ThirdParty/Eigen3/itk-module-init.cmake ++++ Modules/ThirdParty/Eigen3/itk-module-init.cmake +@@ -1,3 +1,3 @@ + if(ITK_USE_SYSTEM_EIGEN) +- find_package(Eigen3 REQUIRED CONFIG) ++ find_package(Eigen3 REQUIRED) + endif() +--- Modules/ThirdParty/DCMTK/itk-module-init.cmake ++++ Modules/ThirdParty/DCMTK/itk-module-init.cmake +@@ -24,7 +24,7 @@ + if(ITK_USE_SYSTEM_DCMTK) + # Use local FindDCMTK.cmake. + list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/CMake") +- find_package(DCMTK REQUIRED NO_MODULE) ++ find_package(DCMTK REQUIRED) + else(ITK_USE_SYSTEM_DCMTK) + # Copied and mofified from DCMTK/CMake/3rdparty.cmake + if(NOT DEFINED DCMTK_USE_ICU) +--- Modules/ThirdParty/Eigen3/CMakeLists.txt ++++ Modules/ThirdParty/Eigen3/CMakeLists.txt +@@ -52,9 +52,9 @@ + + if(ITK_USE_SYSTEM_EIGEN) + set(_Eigen3_SYSTEM_OR_INTERNAL "Eigen3") +- find_package(${_Eigen3_SYSTEM_OR_INTERNAL} ${_Eigen3_min_version} REQUIRED CONFIG) +- set(Eigen3_DIR_INSTALL ${Eigen3_DIR}) +- set(Eigen3_DIR_BUILD ${Eigen3_DIR}) ++ find_package(${_Eigen3_SYSTEM_OR_INTERNAL} ${_Eigen3_min_version} REQUIRED) ++ set(Eigen3_DIR_INSTALL ${Eigen3_INCLUDE_DIR}) ++ set(Eigen3_DIR_BUILD ${Eigen3_INCLUDE_DIR}) + else() + set(_Eigen3_SYSTEM_OR_INTERNAL "ITKInternalEigen3") + find_package(${_Eigen3_SYSTEM_OR_INTERNAL} ${_Eigen3_min_version} REQUIRED CONFIG) +@@ -66,7 +66,7 @@ + # Eigen3 is header only, but there are compile definitions that we want to provide + # to enforce use of MPL only code, and to disable warnings. + # We only need to add the location of the header itk_eigen.h used internally. +-get_target_property(Eigen_INCLUDE_DIRS ${_eigen_itk_target} INTERFACE_INCLUDE_DIRECTORIES) ++set(Eigen_INCLUDE_DIRS ${Eigen3_INCLUDE_DIRS}) + set(ITKEigen3_INCLUDE_DIRS + ${Eigen_INCLUDE_DIRS} + ${ITKEigen3_BINARY_DIR}/src # For the generated itk_eigen.h +@@ -75,14 +75,10 @@ + # When this module is loaded by an app, load Eigen too. + # Load ITKInternalEigen3 or Eigen3 depending on ITK_USE_SYSTEM_EIGEN + set(ITKEigen3_EXPORT_CODE_INSTALL " +-set(ITK_USE_SYSTEM_EIGEN \"${ITK_USE_SYSTEM_EIGEN}\") +-set(${_Eigen3_SYSTEM_OR_INTERNAL}_DIR \"${Eigen3_DIR_INSTALL}\") +-find_package(${_Eigen3_SYSTEM_OR_INTERNAL} ${_Eigen3_min_version} REQUIRED CONFIG) ++find_package(${_Eigen3_SYSTEM_OR_INTERNAL} ${_Eigen3_min_version} REQUIRED) + ") + set(ITKEigen3_EXPORT_CODE_BUILD " +-set(ITK_USE_SYSTEM_EIGEN \"${ITK_USE_SYSTEM_EIGEN}\") +-set(${_Eigen3_SYSTEM_OR_INTERNAL}_DIR \"${Eigen3_DIR_BUILD}\") +-find_package(${_Eigen3_SYSTEM_OR_INTERNAL} ${_Eigen3_min_version} REQUIRED CONFIG) ++find_package(${_Eigen3_SYSTEM_OR_INTERNAL} ${_Eigen3_min_version} REQUIRED) + ") + + # Eigen3 targets are not installed if ITK_USE_SYSTEM_EIGEN==True +--- Modules/ThirdParty/Eigen3/src/itk_eigen.h.in ++++ Modules/ThirdParty/Eigen3/src/itk_eigen.h.in +@@ -43,10 +43,10 @@ + set(Eigen3_DIR ${ITKInternalEigen3_DIR}) + endif() + message(STATUS "From ITK: Eigen3_DIR: ${Eigen3_DIR}") +-find_package(Eigen3 REQUIRED CONFIG) ++find_package(Eigen3 REQUIRED) + add_executable(main main.cpp) + target_link_libraries(main PUBLIC ${ITK_LIBRARIES}) + target_link_libraries(main PUBLIC Eigen3::Eigen) + \endcode + * + * Then, the user can use Eigen3 as usual: +--- Modules/ThirdParty/JPEG/CMakeLists.txt ++++ Modules/ThirdParty/JPEG/CMakeLists.txt +@@ -6,13 +6,13 @@ + + if(ITK_USE_SYSTEM_JPEG) + find_package(JPEG REQUIRED) + set(ITKJPEG_INCLUDE_DIRS + ${ITKJPEG_BINARY_DIR}/src + ) + set(ITKJPEG_SYSTEM_INCLUDE_DIRS + ${JPEG_INCLUDE_DIR} + ) +- set(ITKJPEG_LIBRARIES "${JPEG_LIBRARIES}") ++ set(ITKJPEG_LIBRARIES JPEG::JPEG) + set(ITKJPEG_NO_SRC 1) + else() + set(ITKJPEG_INCLUDE_DIRS +--- Modules/ThirdParty/DoubleConversion/CMakeLists.txt ++++ Modules/ThirdParty/DoubleConversion/CMakeLists.txt +@@ -8,8 +8,8 @@ + + if(ITK_USE_SYSTEM_DOUBLECONVERSION) + find_package(double-conversion 3.1.6 REQUIRED) +- get_target_property(ITKDoubleConversion_INCLUDE_DIRS double-conversion::double-conversion INTERFACE_INCLUDE_DIRECTORIES) +- get_target_property(ITKDoubleConversion_LIBRARIES double-conversion::double-conversion LOCATION) ++ set(ITKDoubleConversion_INCLUDE_DIRS ${double-conversion_INCLUDE_DIRS}) ++ set(ITKDoubleConversion_LIBRARIES ${double-conversion_LIBRARIES}) + else() + set(ITKDoubleConversion_INCLUDE_DIRS + ${ITKDoubleConversion_SOURCE_DIR}/src +--- Modules/ThirdParty/Expat/CMakeLists.txt ++++ Modules/ThirdParty/Expat/CMakeLists.txt +@@ -6,9 +6,9 @@ + + if(ITK_USE_SYSTEM_EXPAT) + find_package(EXPAT REQUIRED) +- set(ITKExpat_INCLUDE_DIRS ${ITKExpat_BINARY_DIR}/src ) +- set(ITKExpat_SYSTEM_INCLUDE_DIRS "${EXPAT_INCLUDE_DIR}") +- set(ITKExpat_LIBRARIES "${EXPAT_LIBRARY}") ++ set(ITKExpat_INCLUDE_DIRS ${EXPAT_INCLUDE_DIRECTORIES}) ++ set(ITKExpat_SYSTEM_INCLUDE_DIRS ${EXPAT_INCLUDE_DIRECTORIES}) ++ set(ITKExpat_LIBRARIES EXPAT::EXPAT) + set(ITKExpat_NO_SRC 1) + else() + set(ITKExpat_INCLUDE_DIRS +--- Modules/ThirdParty/HDF5/CMakeLists.txt ++++ Modules/ThirdParty/HDF5/CMakeLists.txt +@@ -19,25 +19,9 @@ if(CMAKE_LINKER MATCHES "link.exe$") + endif() + + if(ITK_USE_SYSTEM_HDF5) +- +- if(HDF5_DIR) +- set(_HDF5_DIR_CODE "set(HDF5_DIR \"${HDF5_DIR}\")") +- endif() +- if(HDF5_NO_MODULE) +- set(_HDF5_NO_MODULE_ARG "NO_MODULE") +- endif() +- +- # When ITK's config is loaded, load HDF5 too. +- set(ITKHDF5_EXPORT_CODE_INSTALL " +-${_HDF5_DIR_CODE} +-find_package(HDF5 ${_HDF5_NO_MODULE_ARG} REQUIRED COMPONENTS CXX C HL) +-") +- set(ITKHDF5_EXPORT_CODE_BUILD " +-if(NOT ITK_BINARY_DIR) +- ${_HDF5_DIR_CODE} +- find_package(HDF5 ${_HDF5_NO_MODULE_ARG} REQUIRED COMPONENTS CXX C HL) +-endif() +-") ++ find_package(HDF5 REQUIRED) ++ set(HDF5_C_SHARED_LIBRARY HDF5::HDF5) ++ set(HDF5_C_STATIC_LIBRARY HDF5::HDF5) + + if(BUILD_SHARED_LIBS) + if (TARGET hdf5-shared) +--- Modules/ThirdParty/OpenJPEG/src/CMakeLists.txt ++++ Modules/ThirdParty/OpenJPEG/src/CMakeLists.txt +@@ -4,5 +4,8 @@ + set(ITK3P_INSTALL_RUNTIME_DIR "${ITKOpenJPEG_INSTALL_RUNTIME_DIR}") + set(ITK3P_INSTALL_LIBRARY_DIR "${ITKOpenJPEG_INSTALL_LIBRARY_DIR}") + set(ITK3P_INSTALL_ARCHIVE_DIR "${ITKOpenJPEG_INSTALL_ARCHIVE_DIR}") +-add_subdirectory(openjpeg) +-itk_module_target(itkopenjpeg NO_INSTALL) ++find_package(OpenJPEG REQUIRED) ++add_library(itkopenjpeg INTERFACE) ++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 ++++ Modules/ThirdParty/TBB/CMakeLists.txt +@@ -8,14 +8,14 @@ set(ITKTBB_NO_SRC 1) + # When this module is loaded by an app, load TBB too. + set(ITKTBB_EXPORT_CODE_INSTALL " + set(TBB_DIR \"${TBB_DIR}\") +-find_package(TBB REQUIRED CONFIG) ++find_package(TBB REQUIRED) + ") + + # When this module is configured by an app, configure TBB too. + set(ITKTBB_EXPORT_CODE_BUILD " + if(NOT ITK_BINARY_DIR) + set(TBB_DIR \"${TBB_DIR}\") +- find_package(TBB REQUIRED CONFIG) ++ find_package(TBB REQUIRED) + endif() + ") + +diff --git a/Modules/ThirdParty/TBB/itk-module-init.cmake b/Modules/ThirdParty/TBB/itk-module-init.cmake +index 1b7ee20a..0859ef33 100644 +--- a/Modules/ThirdParty/TBB/itk-module-init.cmake ++++ b/Modules/ThirdParty/TBB/itk-module-init.cmake +@@ -1,2 +1,2 @@ +-find_package(TBB REQUIRED CONFIG) # must have TBBConfig.cmake, provided since version tbb2017_20170604oss ++find_package(TBB REQUIRED) + get_target_property(TBB_INCLUDE_DIRS TBB::tbb INTERFACE_INCLUDE_DIRECTORIES) diff --git a/recipes/itk/config.yml b/recipes/itk/config.yml index 989b5ee90fe13..f362c6f4b0b84 100644 --- a/recipes/itk/config.yml +++ b/recipes/itk/config.yml @@ -1,4 +1,6 @@ versions: + "5.3.0": + folder: "all" "5.1.2": folder: "all" "5.1.0":