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

Allow passing custom CMake arguments #235

Merged
merged 1 commit into from Aug 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 20 additions & 10 deletions README.md
Expand Up @@ -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

Expand All @@ -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

Expand Down
6 changes: 6 additions & 0 deletions setup.py
Expand Up @@ -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
Expand Down