-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathsetup.py
More file actions
93 lines (77 loc) · 3.39 KB
/
setup.py
File metadata and controls
93 lines (77 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
import pathlib
from setuptools import setup
from setuptools import Extension
from setuptools.command.build_ext import build_ext
import distutils.sysconfig
import subprocess
pyinc = distutils.sysconfig.get_python_inc()
class CMakeExtension(Extension):
def __init__(self, name):
super().__init__(name, sources=[])
class BuildExt(build_ext):
def run(self):
for ext in self.extensions:
if isinstance(ext, CMakeExtension):
self.build_cmake(ext)
super().run()
def build_cmake(self, ext):
cwd = pathlib.Path().absolute()
build_temp = f"{pathlib.Path(self.build_temp)}/{ext.name}"
os.makedirs(build_temp, exist_ok=True)
extdir = pathlib.Path(self.get_ext_fullpath(ext.name))
extdir.mkdir(parents=True, exist_ok=True)
config = "Debug" if self.debug else "Release"
cmake_args = [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + str(extdir.parent.absolute())+"/pyrtklib",
"-DCMAKE_BUILD_TYPE=" + config,
"-DPYTHON_INCLUDE_DIR="+pyinc
]
if self.debug:
cmake_args.append("-DDEBUG=ON")
if os.sys.platform == "darwin":
#gcc_version_output = subprocess.check_output(["brew", "list", "--versions", "gcc"])
#gcc_version = gcc_version_output.decode("utf-8").split()[1].split('.')[0]
#gcc_path = '/'.join(subprocess.check_output(['which','gcc-13']).decode('utf8').split('/')[:-1])
#cmake_args.append("-DCMAKE_C_COMPILER="+gcc_path+'/gcc-'+gcc_version)
#cmake_args.append("-DCMAKE_CXX_COMPILER="+gcc_path+'/g++-'+gcc_version)
cmake_args.append("-DDARWIN=ON")
print("macos config successfully")
if os.name == "nt":
cmake_args += [
"-DCMAKE_GENERATOR=Visual Studio 17 2022", # or your specific Visual Studio version
"-A", "x64", # or your specific architecture
"-DCMAKE_C_FLAGS_RELEASE=/MT",
"-DCMAKE_CXX_FLAGS_RELEASE=/MT",
"-DWIN32=ON",
"-DCMAKE_CXX_FLAGS=/bigobj /DWIN32", # 添加 /bigobj 和 /DWIN32 选项
"-DCMAKE_C_FLAGS=/bigobj /DWIN32", # 添加 /bigobj 和 /DWIN32 选项
"-DCMAKE_EXE_LINKER_FLAGS=/bigobj", # 添加 /bigobj 选项
"-DCMAKE_SHARED_LINKER_FLAGS=/bigobj", # 添加 /bigobj 选项
"-DADDITIONAL_LIBRARIES=winmm;ws2_32"
]
print("Windows config successfully")
build_args = ["--config", config]
if os.name != "nt":
build_args += ["--", "-j8"]
os.chdir(build_temp)
self.spawn(["cmake", f"{str(cwd)}/{ext.name}"] + cmake_args)
if not self.dry_run:
self.spawn(["cmake", "--build", "."] + build_args)
os.chdir(str(cwd))
pyrtklib = CMakeExtension("pyrtklib")
setup(name="pyrtklib",
version="0.2.7",
description="This is a python binding for rtklib",
author="Runzhi Hu",
author_email = "run-zhi.hu@connect.polyu.hk",
url = "https://github.com/IPNL-POLYU/pyrtklib",
packages=["pyrtklib"],
package_data={
'pyrtklib':['pyrtklib.pyi','__init__.py']
},
ext_modules=[pyrtklib],
cmdclass={"build_ext": BuildExt},
long_description=open('readme.md').read(),
long_description_content_type='text/markdown',
)