otb: fix python support (#393187)

This commit is contained in:
Gaétan Lepage
2025-03-27 10:12:46 +01:00
committed by GitHub
2 changed files with 49 additions and 4 deletions
@@ -0,0 +1,17 @@
diff --git a/Modules/Core/Wrappers/SWIG/src/python/CMakeLists.txt b/Modules/Core/Wrappers/SWIG/src/python/CMakeLists.txt
index 1a33064..d791805 100644
--- a/Modules/Core/Wrappers/SWIG/src/python/CMakeLists.txt
+++ b/Modules/Core/Wrappers/SWIG/src/python/CMakeLists.txt
@@ -17,6 +17,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+# Add ITK
+find_package(ITK REQUIRED)
+include(${ITK_USE_FILE})
+include_directories(${ITK_INCLUDE_DIRS})
+message(STATUS "ITK FOUND: ${ITK_INCLUDE_DIRS}")
+
include_directories( ${Python_INCLUDE_DIRS} )
include_directories ( ${CMAKE_CURRENT_SOURCE_DIR})
set_source_files_properties ( ../otbApplication.i PROPERTIES CPLUSPLUS ON )
+32 -4
View File
@@ -32,7 +32,7 @@
enableLearning ? true,
enableMiscellaneous ? true,
enableOpenMP ? false,
enablePython ? false,
enablePython ? true,
extraPythonPackages ? ps: with ps; [ ],
enableRemote ? true,
enableShark ? true,
@@ -49,12 +49,24 @@ let
# ITK configs for OTB requires 5.3.0 and
# filter out gdcm, libminc from list of ITK deps as it's not needed for OTB
itkVersion = "5.3.0";
itkMajorMinorVersion = lib.versions.majorMinor itkVersion;
itkDepsToRemove = [
"gdcm"
"libminc"
];
itkIsInDepsToRemove = dep: builtins.any (d: d == dep.name) itkDepsToRemove;
# remove after https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/-/issues/2451
otbSwig = swig.overrideAttrs (oldArgs: {
version = "4.2.1";
src = fetchFromGitHub {
owner = "swig";
repo = "swig";
tag = "v4.2.1";
hash = "sha256-VlUsiRZLScmbC7hZDzKqUr9481YXVwo0eXT/jy6Fda8=";
};
});
# override the ITK version with OTB version
# https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/-/blob/develop/SuperBuild/CMake/External_itk.cmake?ref_type=heads#L145
otb-itk = (itk.override { enableRtk = false; }).overrideAttrs (oldArgs: {
@@ -78,6 +90,13 @@ let
})
];
# fix the CMake config files for ITK which contains double slashes
postInstall =
(oldArgs.postInstall or "")
+ ''
sed -i 's|''${ITK_INSTALL_PREFIX}//nix/store|/nix/store|g' $out/lib/cmake/ITK-${itkMajorMinorVersion}/ITKConfig.cmake
'';
cmakeFlags = oldArgs.cmakeFlags or [ ] ++ [
(lib.cmakeBool "ITK_USE_SYSTEM_EIGEN" true)
@@ -205,12 +224,16 @@ stdenv.mkDerivation (finalAttrs: {
url = "https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/-/merge_requests/1056/diffs.patch";
hash = "sha256-Zj/wkx0vxn5vqj0hszn7NxoYW1yf63G3HPVKbSdZIOY=";
})
./1-otb-swig-include-itk.diff
];
postPatch = (
"substituteInPlace Modules/Core/Wrappers/SWIG/src/python/CMakeLists.txt --replace-fail '''$''{ITK_INCLUDE_DIRS}' ${otb-itk}/include/ITK-${itkMajorMinorVersion}"
);
nativeBuildInputs = [
cmake
makeWrapper
swig
which
];
@@ -246,11 +269,16 @@ stdenv.mkDerivation (finalAttrs: {
otb-itk
otb-shark
perl
swig
tinyxml
]
++ otb-itk.propagatedBuildInputs
++ optionals enablePython ([ python3 ] ++ pythonInputs)
++ optionals enablePython (
[
python3
otbSwig
]
++ pythonInputs
)
++ optionals enableShark [ otb-shark ];
doInstallCheck = true;