diff --git a/Modules/Wrappers/SWIG/src/python/CMakeLists.txt b/Modules/Wrappers/SWIG/src/python/CMakeLists.txt index a1d4553894edaa2921305a3eb6ecf994eeb90170..de676f70272dadc3fd7b5678f675560cd89d437c 100644 --- a/Modules/Wrappers/SWIG/src/python/CMakeLists.txt +++ b/Modules/Wrappers/SWIG/src/python/CMakeLists.txt @@ -87,3 +87,20 @@ if(PYTHON_VERSION_STRING VERSION_LESS "3.2.0") else() # TODO : pyc file is in a subfolder. endif() + +configure_file(StandaloneWrapper.in CMakeLists.txt @ONLY) + +install( FILES ${CMAKE_SWIG_OUTDIR}/otbApplicationPYTHON_wrap.cxx + ${CMAKE_SWIG_OUTDIR}/otbApplicationPYTHON_wrap.h + itkPyCommand.cxx + itkPyCommand.h + otbPythonLogOutput.cxx + otbPythonLogOutput.h + otbSwigPrintCallback.h + otbProgressReporterManager.cxx + otbProgressReporterManager.h + ../itkBase.includes + ../otbWrapperSWIGIncludes.h + ${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.txt + DESTINATION ${OTB_INSTALL_DATA_DIR}/swig + COMPONENT Resources ) diff --git a/Modules/Wrappers/SWIG/src/python/StandaloneWrapper.in b/Modules/Wrappers/SWIG/src/python/StandaloneWrapper.in new file mode 100644 index 0000000000000000000000000000000000000000..8b045020e8c07db0281ad62490a4dd6843b57312 --- /dev/null +++ b/Modules/Wrappers/SWIG/src/python/StandaloneWrapper.in @@ -0,0 +1,57 @@ +cmake_minimum_required(VERSION 3.10.1) +project(OTBPythonWrappers) + +get_filename_component(PKG_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}" PATH) +get_filename_component(PKG_PREFIX "${PKG_PREFIX}" PATH) +get_filename_component(PKG_PREFIX "${PKG_PREFIX}" PATH) + +find_package(OTB REQUIRED HINTS ${PKG_PREFIX}/@OTB_INSTALL_PACKAGE_DIR@) +list(APPEND CMAKE_MODULE_PATH ${OTB_CMAKE_DIR}) +include(${OTB_USE_FILE}) + +set ( Python_ADDITIONAL_VERSIONS "3;2" ) +set ( PythonInterp_FIND_REQUIRED ${OTB_WRAP_PYTHON} ) +set ( PythonLibs_FIND_REQUIRED ${OTB_WRAP_PYTHON} ) +find_package( PythonInterp ) +if ( OTB_WRAP_PYTHON AND ( ${PYTHON_VERSION_MAJOR} EQUAL 2 ) ) + message (WARNING "Python3 not found. There is no longer support of \ + wrapping in python2 in OTB, but it can still be used.") +endif() +# Now that we have a python version the addditional versions should only +# contain the version we have to get the corresponding libs +set (Python_ADDITIONAL_VERSIONS "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") +find_package ( PythonLibs ) +include_directories(${PYTHON_INCLUDE_DIR}) + +find_package(Numpy) +if ( NUMPY_FOUND ) + include_directories(${NUMPY_INCLUDE_DIRS}) +else() + message( WARNING + "OTB wrappers will be done without support for NumPy (not found).") +endif() + +include_directories("${CMAKE_CURRENT_SOURCE_DIR}") + +file(GLOB OTBPythonWrappers_SOURCES "*.cxx") + +# declare the python wrapper library +add_library(PythonWrapperLib MODULE ${OTBPythonWrappers_SOURCES}) +target_link_libraries(PythonWrapperLib ${PYTHON_LIBRARIES} OTBApplicationEngine) + +set_target_properties(PythonWrapperLib PROPERTIES + OUTPUT_NAME "_otbApplication" + NO_SONAME ON + PREFIX "") + +if(WIN32 AND NOT CYGWIN) + set_target_properties(PythonWrapperLib PROPERTIES SUFFIX ".pyd") +endif() + +if(NUMPY_FOUND) + add_definitions(-DOTB_SWIGNUMPY=1) +endif() + +install(TARGETS PythonWrapperLib + DESTINATION lib/python + COMPONENT RuntimeLibraries ) diff --git a/Packaging/install_python_bindings.cmake b/Packaging/install_python_bindings.cmake index 754986de0a96b845f761ca02143a73ac839ee843..01b10490bd346ac3c24d681b9f38d900748da9bd 100644 --- a/Packaging/install_python_bindings.cmake +++ b/Packaging/install_python_bindings.cmake @@ -24,6 +24,9 @@ function(install_python_bindings) PATTERN "*.pyc" EXCLUDE PATTERN "__pycache__" EXCLUDE ) + install(DIRECTORY ${SUPERBUILD_INSTALL_DIR}/share/otb/swig + DESTINATION ${PKG_STAGE_DIR}/share/otb + ) endif() # Handle GDAL python bindings file(GLOB gdal_python_scripts "${SUPERBUILD_INSTALL_DIR}/bin/gdal*.py")