65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
from setuptools import setup
|
||
from setuptools.extension import Extension
|
||
from Cython.Distutils import build_ext
|
||
from Cython.Build import cythonize
|
||
import numpy
|
||
from pathlib import Path
|
||
import shutil
|
||
import sys
|
||
|
||
class MyBuildExt(build_ext):
|
||
def run(self):
|
||
build_ext.run(self)
|
||
|
||
build_dir = Path(self.build_lib)
|
||
root_dir = Path(__file__).parent
|
||
target_dir = build_dir if not self.inplace else root_dir
|
||
|
||
self.copy_file(Path('./WindSpeedTools') / '__init__.py', root_dir, target_dir)
|
||
#self.copy_file(Path('./pkg2') / '__init__.py', root_dir, target_dir)
|
||
self.copy_file(Path('.') / '__init__.py', root_dir, target_dir)
|
||
def copy_file(self, path, source_dir, destination_dir):
|
||
if not (source_dir / path).exists():
|
||
return
|
||
shutil.copyfile(str(source_dir / path), str(destination_dir / path))
|
||
|
||
|
||
# 判断平台和编译器,选择正确的OpenMP标志
|
||
compile_args = []
|
||
link_args = []
|
||
|
||
if sys.platform == "win32":
|
||
# 在Windows上使用MSVC编译器
|
||
compile_args = ['/openmp'] # 仅传递给编译器
|
||
# 链接器不需要此选项,因此 link_args 为空
|
||
else:
|
||
# 在Linux/macOS上使用GCC/Clang编译器
|
||
compile_args = ['-fopenmp']
|
||
link_args = ['-fopenmp'] # 对于GCC,通常需要同时传递给编译器和链接器
|
||
|
||
setup(
|
||
name="MyModule",
|
||
ext_modules=cythonize(
|
||
[
|
||
#Extension("pkg1.*", ["root/pkg1/*.py"]),
|
||
Extension("pkg2.*", ["WindSpeedModel.pyx"],
|
||
# 添加OpenMP支持
|
||
extra_compile_args=compile_args, # 选项只给编译器
|
||
extra_link_args=link_args, # 链接器使用单独的选项列表
|
||
),
|
||
#Extension("1.*", ["root/*.py"])
|
||
],
|
||
build_dir="build",
|
||
compiler_directives=dict(
|
||
always_allow_keywords=True
|
||
)),
|
||
cmdclass=dict(
|
||
build_ext=MyBuildExt
|
||
),
|
||
packages=[],
|
||
include_dirs=[numpy.get_include()],
|
||
|
||
)
|
||
|
||
# 指令: python setup.py build_ext --inplace
|