Skip to content

Commit 5d89434

Browse files
committed
added support for windows
1 parent bb6c8c5 commit 5d89434

File tree

2 files changed

+78
-11
lines changed

2 files changed

+78
-11
lines changed

README.md

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22

33
python_bladerf is a cython wrapper for [bladerf](https://github.com/Nuand/bladeRF). It also contains some additional tools.
44

5-
Before installing python_bladerf library, you must have bladerf host software installed. Because this library uses dynamic linking with an existing library file.
5+
Before installing python_bladerf library, you must have bladerf host software installed. Because this library uses dynamic linking with an existing library file. Minimum libbladeRF version: 2.5.5
66

7+
For windows users please use [additional steps](#installation-on-windows) to install python_bladerf
78
You can install this library using
89
```
910
pip install git+https://github.com/GvozdevLeonid/python_bladerf.git
1011
```
1112

1213
If your bladerf files are in non-standard paths and during installation the python_bladerf cannot find libbladeRF.h and bladeRF2.h or the library files, you can specify the paths via environment variables
1314
```
14-
export PYTHON_BLADERF_CFLAGS=path_to_libbladeRF.h_andbladeRF2.h
15-
export PYTHON_BLADERF_LDFLAGS=path_to_libbladerf.(so, dylib, dll)
15+
export/set {linux and macos / windows} PYTHON_BLADERF_CFLAGS=path_to_libbladeRF.h_andbladeRF2.h
16+
export/set {linux and macos / windows} PYTHON_BLADERF_LDFLAGS=path_to_libbladerf.(so, dylib, dll)
1617
```
1718

1819
## Requirements:
19-
* libusb-1.0 (https://github.com/libusb/libusb)
20-
* libBladeRF (https://github.com/Nuand/bladeRF)
21-
* Cython==0.29.37
2220
* Numpy>=2.2.1
2321
* Scipy (optional, for faster work)
2422
* pyFFTW (optional, for faster work)
@@ -125,4 +123,45 @@ pythonforandroidrecipes/
125123
```
126124

127125
## Examples
128-
Please use the original bladerf documentation
126+
Please use the original bladerf documentation
127+
128+
## Installation on Windows
129+
To install python_bladerf, you must first install the BladeRF software. Official installation instructions are available on the [BladeRF documentation site](https://github.com/Nuand/bladeRF/wiki/Getting-Started%3A-Windows).
130+
Alternatively, you can download the ZIP archive from the Releases tab of this repository. Extract the archive and move its contents to the standard location: `C:\Program Files\BladeRF`
131+
132+
The BladeRF directory should contain the following subfolders and files:
133+
```
134+
├── include
135+
│ └── libbladeRF.h
136+
│ └── bladeRF2.h
137+
│ └── bladeRF1.h
138+
│ └── pthread.h
139+
├── lib
140+
│ └── bladeRF.dll
141+
│ └── bladeRF.lib ← for MSVC
142+
│ └── libbladeRF.a ← for MinGW
143+
│ └── libusb-1.0.dll
144+
│ └── pthreadVC2.dll
145+
│ └── msvcr100.dll
146+
```
147+
148+
149+
In addition, the archive includes other required DLLs and dependencies to ensure proper operation of HackRF on Windows.
150+
libusb-1.0.dll
151+
pthreadVC2.dll
152+
msvcr100.dll
153+
154+
If you install bladerf yourself or via another path, set the following environment variables
155+
156+
MSVC:
157+
```
158+
set PYTHON_BLADERF_CFLAGS=/I"{path to .h file directory}"
159+
set PYTHON_BLADERF_LDFLAGS=/LIBPATH:"{path to .dll and .lib file directory}" bladeRF.lib
160+
set BLADERF_LIB_DIR="{path to .dll and .lib file directory}"
161+
```
162+
MinGW:
163+
```
164+
set PYTHON_BLADERF_CFLAGS=-I"{path to .h file directory}"
165+
set PYTHONBLADERFF_LDFLAGS=-L"{path to .dll and .a file directory}" -lbladeRF'
166+
set BLADERF_LIB_DIR="{path to .dll and .lib file directory}"
167+
```

setup.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import subprocess
22
import sys
3-
from os import environ, getenv
3+
from os import environ, getenv, path
44

55
import numpy
66
from setuptools import Extension, find_packages, setup
7+
from setuptools.command.install import install
78
from setuptools.command.build_ext import build_ext
89
from Cython.Build import cythonize
910

@@ -44,8 +45,22 @@
4445
else:
4546
new_ldflags = environ.get('PYTHON_BLADERF_LDFLAGS', '')
4647

47-
elif PLATFORM == 'win32':
48-
pass
48+
elif PLATFORM.startswith('win'):
49+
include_path = 'C:\\Program Files\\BladeRF\\include'
50+
lib_path = 'C:\\Program Files\\BladeRF\\lib'
51+
52+
if environ.get('PYTHON_BLADERF_CFLAGS', None) is None:
53+
new_cflags = f'-I"{include_path}"'
54+
else:
55+
new_cflags = environ.get('PYTHON_BLADERF_CFLAGS', '')
56+
57+
if environ.get('PYTHON_BLADERF_LDFLAGS', None) is None:
58+
new_ldflags = f'-L"{lib_path}" -lbladeRF'
59+
else:
60+
new_ldflags = environ.get('PYTHON_BLADERF_LDFLAGS', '')
61+
62+
environ['CL'] = f'/I"{include_path}"'
63+
environ['LINK'] = f'/LIBPATH:"{lib_path}" bladeRF.lib'
4964

5065
environ['CFLAGS'] = f'{cflags} {new_cflags}'.strip()
5166
environ['LDFLAGS'] = f'{ldflags} {new_ldflags}'.strip()
@@ -61,9 +76,22 @@ def run(self) -> None:
6176
super().run()
6277

6378

79+
class InstallWithPth(install):
80+
def run(self) -> None:
81+
super().run()
82+
83+
if PLATFORM.startswith('win'):
84+
pth_code = (
85+
'import os; '
86+
'os.add_dll_directory(os.getenv("BLADERF_LIB_DIR", "C:\\Program Files\\BladeRF\\lib"))'
87+
)
88+
with open(path.join(self.install_lib, "python_bladerf.pth"), mode='w', encoding='utf-8') as file:
89+
file.write(pth_code)
90+
91+
6492
setup(
6593
name='python_bladerf',
66-
cmdclass={'build_ext': CustomBuildExt},
94+
cmdclass={'build_ext': CustomBuildExt, 'install': InstallWithPth},
6795
install_requires=INSTALL_REQUIRES,
6896
setup_requires=SETUP_REQUIRES,
6997
ext_modules=[

0 commit comments

Comments
 (0)