From 9797de13a241fd99d1115e7959fc3c18b67d3b1f Mon Sep 17 00:00:00 2001 From: Guillaume Pasero <guillaume.pasero@c-s.fr> Date: Fri, 2 Aug 2019 12:50:57 +0200 Subject: [PATCH] PKG: also install a ctest script and README --- .../SWIG/src/python/StandaloneWrapper.in | 20 ++++++++ Packaging/Files/build_wrapping.cmake | 47 +++++++++++++++++++ Packaging/Files/build_wrapping.md | 47 +++++++++++++++++++ Packaging/install_python_bindings.cmake | 5 ++ 4 files changed, 119 insertions(+) create mode 100644 Packaging/Files/build_wrapping.cmake create mode 100644 Packaging/Files/build_wrapping.md diff --git a/Modules/Wrappers/SWIG/src/python/StandaloneWrapper.in b/Modules/Wrappers/SWIG/src/python/StandaloneWrapper.in index 8b045020e8..9a657eabcd 100644 --- a/Modules/Wrappers/SWIG/src/python/StandaloneWrapper.in +++ b/Modules/Wrappers/SWIG/src/python/StandaloneWrapper.in @@ -1,3 +1,23 @@ +# +# Copyright (C) 2005-2019 CS Systemes d'Information (CS SI) +# +# This file is part of Orfeo Toolbox +# +# https://www.orfeo-toolbox.org/ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + cmake_minimum_required(VERSION 3.10.1) project(OTBPythonWrappers) diff --git a/Packaging/Files/build_wrapping.cmake b/Packaging/Files/build_wrapping.cmake new file mode 100644 index 0000000000..3b1f28dd15 --- /dev/null +++ b/Packaging/Files/build_wrapping.cmake @@ -0,0 +1,47 @@ +# +# Copyright (C) 2005-2019 CS Systemes d'Information (CS SI) +# +# This file is part of Orfeo Toolbox +# +# https://www.orfeo-toolbox.org/ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +get_filename_component(PKG_PREFIX "${CTEST_SCRIPT_DIRECTORY}" PATH) +get_filename_component(PKG_PREFIX "${PKG_PREFIX}" PATH) +get_filename_component(PKG_PREFIX "${PKG_PREFIX}" PATH) + +set(CTEST_SOURCE_DIRECTORY ${CTEST_SCRIPT_DIRECTORY}) +set(CTEST_BINARY_DIRECTORY ${CTEST_SCRIPT_DIRECTORY}/build) +if(WIN32) + set(CTEST_CMAKE_GENERATOR "NMake Makefiles") +else() + set(CTEST_CMAKE_GENERATOR "Unix Makefiles") +endif() +set(CTEST_BUILD_CONFIGURATION "Release") + +if(IS_DIRECTORY "${CTEST_BINARY_DIRECTORY}") + file(REMOVE_RECURSE "${CTEST_BINARY_DIRECTORY}") +endif() + +set(CONFIGURE_OPTIONS + "-DCMAKE_INSTALL_PREFIX=${PKG_PREFIX}" + "-DCMAKE_BUILD_TYPE=Release") +if(PYTHON_EXECUTABLE) + list(APPEND CONFIGURE_OPTIONS "-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}") +endif() + +ctest_start(Experimental) +ctest_configure(OPTIONS "${CONFIGURE_OPTIONS}") +ctest_build(TARGET install) diff --git a/Packaging/Files/build_wrapping.md b/Packaging/Files/build_wrapping.md new file mode 100644 index 0000000000..3fe735393f --- /dev/null +++ b/Packaging/Files/build_wrapping.md @@ -0,0 +1,47 @@ +# How to recompile OTB Python bindings with your Python version? + +The OTB Python bindings are made of: + +* a Python module `otbApplication.py` +* a Python C++ extension `_otbApplication.so` (or `_otbApplication.pyd` on Windows) + +The Python module should be independent from the Python version you are using, +but the compiled C++ extension is linked to a specific Python library. If this +library is not present on your system, you can recompile the extension to use +your Python version. + +The procedure is simple, once you have the following prerequisite: + +* A C++ compiler: + * On Linux: GCC >= 5.0 + * On macos: XCode + * On Windows: either Visual Studio >= 2015 with the desktop C++ workload, + or just the MSVC Build Tools. +* CMake >= 3.10 +* Python library and headers for your Python version + * On macos and Windows: they are usually supplied with installers from + official website + * On Linux packages: you should look for a `python-dev` package matching + your Python interpreter version. +* Numpy module for your Python version + +The compilation and installation of the C++ extension can be launched from the +command line (on Windows you can use `cmd.exe`): + +``` +ctest -S build_wrapping.cmake +``` + +If you want to use a specific Python interpreter: + +``` +ctest -DPYTHON_EXECUTABLE=/my/own/python -S build_wrapping.cmake +``` + +Note: on Windows, you have to setup MSVC compiler before calling `ctest`. Use +the `vcvarsall.bat` script with the right architecture (x32 or x64). For +instance: + +``` +call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 +``` diff --git a/Packaging/install_python_bindings.cmake b/Packaging/install_python_bindings.cmake index 01b10490bd..5de31587c0 100644 --- a/Packaging/install_python_bindings.cmake +++ b/Packaging/install_python_bindings.cmake @@ -27,6 +27,11 @@ function(install_python_bindings) install(DIRECTORY ${SUPERBUILD_INSTALL_DIR}/share/otb/swig DESTINATION ${PKG_STAGE_DIR}/share/otb ) + install(FILES Files/build_wrapping.cmake + DESTINATION ${PKG_STAGE_DIR}/share/otb/swig) + install(FILES Files/build_wrapping.md + DESTINATION ${PKG_STAGE_DIR}/share/otb/swig + RENAME README.md) endif() # Handle GDAL python bindings file(GLOB gdal_python_scripts "${SUPERBUILD_INSTALL_DIR}/bin/gdal*.py") -- GitLab