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

Add ITK 5.3.0 #25246

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 7 additions & 0 deletions recipes/itk/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
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"
"5.1.0":
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"
Expand Down
49 changes: 44 additions & 5 deletions recipes/itk/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ''
Expand All @@ -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")
Expand Down Expand Up @@ -455,6 +470,16 @@ def libdl():
"ITKVideoCore": {"requires": ["ITKCommon"]},
}

def _create_cmake_module_variables(self):
itk_version = Version(self.version)
lib_suffix = f"{itk_version.major}.{itk_version.minor}"

content = textwrap.dedent("""\
set(ITK_CMAKE_DIR "${itk_LIB_DIRS_RELEASE}/cmake/ITK-%(version)s")
""" % {"version":lib_suffix})

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 = ""
Expand All @@ -475,18 +500,32 @@ 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

keep_list =["UseITK.cmake", "ITKFactoryRegistration.cmake", "ITKInitializeCXXStandard.cmake"]
# 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 keep_list:
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 = [os.path.join(self._cmake_module_dir, f"conan-official-{self.name}-variables.cmake")]
#itk5.3 added two more additional cmake files.
if lib_suffix == "-5.3":
# Add two additional items to build_modules
build_modules.extend([
os.path.join(self._cmake_module_dir, "ITKFactoryRegistration.cmake"),
os.path.join(self._cmake_module_dir, "ITKInitializeCXXStandard.cmake")
])
build_modules.append(os.path.join(self._cmake_module_dir, "UseITK.cmake"))

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)
Expand Down
189 changes: 189 additions & 0 deletions recipes/itk/all/patches/0002-find-conan-packages.patch
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions recipes/itk/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"5.3.0":
folder: "all"
"5.1.2":
folder: "all"
"5.1.0":
Expand Down
Loading