From 4b191f860257297be04e57213b0d981bcfb9a841 Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Sat, 17 Aug 2019 16:08:13 +0300 Subject: [PATCH] Allow passing custom CMake arguments --- README.md | 30 ++++++++++++++++++++---------- setup.py | 6 ++++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 10229096..0db6eb08 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,10 @@ The aim of this repository is to provide means to package each new [OpenCV relea ### Build process -The project is structured like a normal Python package with a standard ``setup.py`` file. The build process for a single entry in the build matrices is as follows (see for example ``appveyor.yml`` file): +The project is structured like a normal Python package with a standard ``setup.py`` file. +The build process for a single entry in the build matrices is as follows (see for example ``appveyor.yml`` file): + +0. In Linux and MacOS build: get OpenCV's optional C dependencies that we compile against 1. Checkout repository and submodules @@ -86,25 +89,32 @@ The project is structured like a normal Python package with a standard ``setup.p - Contrib modules are also included as a submodule 2. Find OpenCV version from the sources -3. Install dependencies (numpy) +3. Install Python dependencies + + - ``setup.py`` installs the dependencies itself, so you need to run it in an environment + where you have the rights to install modules with Pip for the running Python + 4. Build OpenCV - tests are disabled, otherwise build time increases too much - there are 4 build matrix entries for each build combination: with and without contrib modules, with and without GUI (headless) - Linux builds run in manylinux Docker containers (CentOS 5) -5. Copy each ``.pyd/.so`` file to cv2 folder of this project and - generate wheel +5. Rearrange OpenCV's build result, add our custom files and generate wheel + +6. Linux and macOS wheels are transformed with auditwheel and delocate, correspondingly - - Linux and macOS wheels are checked with auditwheel and delocate +7. Install the generated wheel +8. Test that Python can import the library and run some sanity checks +9. Use twine to upload the generated wheel to PyPI (only in release builds) -6. Install the generated wheel -7. Test that Python can import the library and run some sanity checks -8. Use twine to upload the generated wheel to PyPI (only in release builds) +Steps 1--5 are handled by ``setup.py bdist_wheel``. -The ``cv2.pyd/.so`` file is normally copied to site-packages. To avoid polluting the root folder this package wraps the statically built binary into cv2 package and ``__init__.py`` file in the package handles the import logic correctly. +The build can be customized with environment variables. +In addition to any variables that OpenCV's build accepts, we recognize: -Since all packages use the same ``cv2`` namespace explained above, uninstall the other package before switching for example from ``opencv-python`` to ``opencv-contrib-python``. +- ``ENABLE_CONTRIB`` and ``ENABLE_HEADLESS``. Set to ``1`` to build the contrib and/or headless version +- ``CMAKE_ARGS``. Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build. ### Licensing diff --git a/setup.py b/setup.py index 65322dbc..1fbffa72 100644 --- a/setup.py +++ b/setup.py @@ -154,6 +154,12 @@ def main(): if sys.platform.startswith('linux') and not x64: cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__") + + if 'CMAKE_ARGS' in os.environ: + import shlex + cmake_args.extend(shlex.split(os.environ['CMAKE_ARGS'])) + del shlex + # ABI config variables are introduced in PEP 425 if sys.version_info[:2] < (3, 2): import warnings