Skip to content

Commit 4b191f8

Browse files
committed
Allow passing custom CMake arguments
1 parent da7d022 commit 4b191f8

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

README.md

+20-10
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ The aim of this repository is to provide means to package each new [OpenCV relea
7777

7878
### Build process
7979

80-
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):
80+
The project is structured like a normal Python package with a standard ``setup.py`` file.
81+
The build process for a single entry in the build matrices is as follows (see for example ``appveyor.yml`` file):
82+
83+
0. In Linux and MacOS build: get OpenCV's optional C dependencies that we compile against
8184

8285
1. Checkout repository and submodules
8386

@@ -86,25 +89,32 @@ The project is structured like a normal Python package with a standard ``setup.p
8689
- Contrib modules are also included as a submodule
8790

8891
2. Find OpenCV version from the sources
89-
3. Install dependencies (numpy)
92+
3. Install Python dependencies
93+
94+
- ``setup.py`` installs the dependencies itself, so you need to run it in an environment
95+
where you have the rights to install modules with Pip for the running Python
96+
9097
4. Build OpenCV
9198

9299
- tests are disabled, otherwise build time increases too much
93100
- there are 4 build matrix entries for each build combination: with and without contrib modules, with and without GUI (headless)
94101
- Linux builds run in manylinux Docker containers (CentOS 5)
95102

96-
5. Copy each ``.pyd/.so`` file to cv2 folder of this project and
97-
generate wheel
103+
5. Rearrange OpenCV's build result, add our custom files and generate wheel
104+
105+
6. Linux and macOS wheels are transformed with auditwheel and delocate, correspondingly
98106

99-
- Linux and macOS wheels are checked with auditwheel and delocate
107+
7. Install the generated wheel
108+
8. Test that Python can import the library and run some sanity checks
109+
9. Use twine to upload the generated wheel to PyPI (only in release builds)
100110

101-
6. Install the generated wheel
102-
7. Test that Python can import the library and run some sanity checks
103-
8. Use twine to upload the generated wheel to PyPI (only in release builds)
111+
Steps 1--5 are handled by ``setup.py bdist_wheel``.
104112

105-
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.
113+
The build can be customized with environment variables.
114+
In addition to any variables that OpenCV's build accepts, we recognize:
106115

107-
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``.
116+
- ``ENABLE_CONTRIB`` and ``ENABLE_HEADLESS``. Set to ``1`` to build the contrib and/or headless version
117+
- ``CMAKE_ARGS``. Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build.
108118

109119
### Licensing
110120

setup.py

+6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ def main():
154154
if sys.platform.startswith('linux') and not x64:
155155
cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
156156

157+
158+
if 'CMAKE_ARGS' in os.environ:
159+
import shlex
160+
cmake_args.extend(shlex.split(os.environ['CMAKE_ARGS']))
161+
del shlex
162+
157163
# ABI config variables are introduced in PEP 425
158164
if sys.version_info[:2] < (3, 2):
159165
import warnings

0 commit comments

Comments
 (0)