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
| # netcdf-fortran 依赖库 netcdf_dep = dependency('netcdf-fortran', required : true)
# include path,除了标准路径,还将源码路径添加了进来 fortran_include = include_directories('/usr/include', 'palm/src')
# 设置 PALM 源码文件列表 src_dir = meson.current_source_dir() / 'palm/src' palm_sources = files( join_paths(src_dir, 'kinds.f90'), join_paths(src_dir, 'control_parameters.f90'), join_paths(src_dir, 'indices.f90'), join_paths(src_dir, 'pegrid.f90'), join_paths(src_dir, 'arrays_3d.f90'), join_paths(src_dir, 'basic_constants_and_equations_mod.f90'), join_paths(src_dir, 'boundary_settings_mod.f90'), join_paths(src_dir, 'exchange_horiz_mod.f90'), join_paths(src_dir, 'general_utilities.f90'), join_paths(src_dir, 'grid_variables.f90'), join_paths(src_dir, 'nc_input.f90'), join_paths(src_dir, 'topo.f90'), )
# wrapper Fortran 代码文件 wrapper_source = files(join_paths(src_dir, 'palm-test.f90'))
# 先将 PALM 源码编译成静态库 palm_lib = static_library( 'palmcore', palm_sources, include_directories: fortran_include, dependencies: netcdf_dep, install: false )
# 利用 f2py 生成 pyf 头文件 palm_pyf = custom_target( 'palm_pyf', input: wrapper_source, output: 'palm.pyf', command: [ py3, '-m', 'numpy.f2py', '@INPUT@', '-m', 'palm', '-h', meson.current_build_dir() / 'palm.pyf' ] )
# 利用 f2py 和头文件生成两个 wrapper 文件 palm_f2py_wrapper = custom_target( 'palmcore', input: [palm_pyf, wrapper_source], output: ['palmmodule.c', 'palm-f2pywrappers2.f90'], command: [ py3, '-m', 'numpy.f2py', '@INPUT@', '-m', 'palm', '--lower', '--build-dir', meson.current_build_dir() ] )
# 最终进行编译时需要的头文件和依赖 py_dep = py3.dependency()
include_dir_numpy = run_command( py3, ['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], check : true ).stdout().strip()
include_dir_f2py = run_command( py3, ['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'], check : true ).stdout().strip()
include_numpy = include_directories(include_dir_numpy, include_dir_f2py)
# 编译 Python 扩展,并安装到指定路径下 py3.extension_module( 'palm', [ wrapper_source, palm_f2py_wrapper, include_dir_f2py / 'fortranobject.c' ], include_directories: include_numpy, dependencies: py_dep, link_with: palm_lib, install: true, install_dir: join_paths(py3.get_install_dir(), 'syize/fortran/palm') )
|
Comments