GRIB-927 python build/install with distutils

This commit is contained in:
Shahram Najm 2016-02-16 18:05:11 +00:00
parent c47980458b
commit 735a373c44
2 changed files with 37 additions and 30 deletions

View File

@ -65,32 +65,39 @@ if( HAVE_PYTHON )
include_directories( ${NUMPY_INCLUDE_DIRS} )
endif()
# Invoke swig to generate the C wrapper
# swig_add_module( gribapi_swig python grib_interface.h grib_interface.c gribapi_swig.i )
# swig_link_libraries( gribapi_swig grib_api ${PYTHON_LIBRARIES} )
####### Do not invoke swig. Use our own generated C wrapper file ######
ecbuild_add_library(TARGET _gribapi_swig
TYPE SHARED
NOINSTALL
SOURCES grib_interface.h grib_interface.c ${_swig_c_wrapper}
LIBS eccodes ${PYTHON_LIBRARIES} )
set( _gribapi_swig "_gribapi_swig${CMAKE_SHARED_LIBRARY_SUFFIX}" )
# Build the extension module for use in build tree with RPATH pointing to the build tree
add_custom_command( OUTPUT ${_gribapi_swig}
COMMAND ${PYTHON_EXECUTABLE} setup.py build_ext --inplace -R ${CMAKE_CURRENT_BINARY_DIR}/../lib
DEPENDS grib_interface.h grib_interface.c ${_swig_c_wrapper} setup.py.in eccodes )
# Build the extension module as target for installation with RPATH pointing to the install prefix
add_custom_command( OUTPUT build/${_gribapi_swig}
COMMAND ${PYTHON_EXECUTABLE} setup.py build_ext -b build -R ${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}
DEPENDS grib_interface.h grib_interface.c ${_swig_c_wrapper} setup.py.in eccodes )
#ecbuild_add_library(TARGET _gribapi_swig
# TYPE SHARED
# NOINSTALL
# SOURCES grib_interface.h grib_interface.c ${_swig_c_wrapper}
# LIBS eccodes ${PYTHON_LIBRARIES} )
# Don't use the lib prefix. This is needed for the python case where a _modulename.so is generated
set_target_properties(_gribapi_swig PROPERTIES PREFIX "")
#set_target_properties(_gribapi_swig PROPERTIES PREFIX "")
# Copy the wrapper python file to build area
set( _swig_py gribapi_swig.py )
add_custom_command(
OUTPUT ${_swig_py}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${_swig_py_wrapper} ${CMAKE_CURRENT_BINARY_DIR}/${_swig_py}
DEPENDS _gribapi_swig
DEPENDS ${_gribapi_swig} build/${_gribapi_swig}
)
add_custom_target(copy_swig_py ALL DEPENDS ${_swig_py})
#######################
install(TARGETS _gribapi_swig DESTINATION ${PYTHON_DEST_GRIBAPI} )
#install(TARGETS _gribapi_swig DESTINATION ${PYTHON_DEST_GRIBAPI} )
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gribapi_swig.py DESTINATION ${PYTHON_DEST_GRIBAPI})
#install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gribapi_swig.py DESTINATION ${PYTHON_DEST_GRIBAPI})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/build/${_gribapi_swig} ${CMAKE_CURRENT_BINARY_DIR}/gribapi_swig.py DESTINATION ${PYTHON_DEST_GRIBAPI})
install(FILES gribapi.py DESTINATION ${PYTHON_DEST_GRIBAPI})
install(FILES eccodes.py DESTINATION ${PYTHON_DEST_ECCODES})

View File

@ -4,23 +4,24 @@ from distutils.core import setup, Extension
import os,sys
attdict = dict(
sources = ['gribapi_swig_wrap.c','grib_interface.c'],
sources = ['@CMAKE_CURRENT_SOURCE_DIR@/@_swig_c_wrapper@',
'@CMAKE_CURRENT_SOURCE_DIR@/grib_interface.c'],
swig_opts = [],
include_dirs = ['.'],
library_dirs = ["%s/lib" % sys.prefix],
libraries = [],
include_dirs = ['.', '@CMAKE_CURRENT_BINARY_DIR@/../src', '@CMAKE_CURRENT_SOURCE_DIR@/../src'],
library_dirs = ['@CMAKE_CURRENT_BINARY_DIR@/../lib'],
libraries = ['eccodes'],
extra_objects = [],
extra_link_args = [], # See GRIB-616
extra_link_args = []
)
add_attribute = lambda **args: [list.append(attdict[key],value) for key,value in args.items()]
# assumes build_dir is same as source_dir -- not true for cmake builds
build_dir = '@BUILD_DIR@'
add_attribute(
include_dirs = os.path.join(build_dir,'src'),
extra_objects = os.path.join(build_dir, 'src', '.libs', 'libeccodes.a')
)
#build_dir = '@BUILD_DIR@'
#add_attribute(
# include_dirs = os.path.join(build_dir,'src'),
# extra_objects = os.path.join(build_dir, 'src', '.libs', 'libeccodes.a')
#)
with_jasper = '@LIB_JASPER@'
if with_jasper:
@ -33,7 +34,7 @@ if with_jasper:
)
add_attribute(libraries = 'jasper')
with_openjpeg = '@LIB_OPENJPEG@'
with_openjpeg = @HAVE_LIBOPENJPEG@
if with_openjpeg:
openjpeg_dir = '@OPENJPEG_DIR@'
if openjpeg_dir and openjpeg_dir != 'system':
@ -45,12 +46,12 @@ if with_openjpeg:
add_attribute(libraries = 'openjpeg')
# assumes png is supplied by system paths -- may not be true
png = '@LIB_PNG@'
png = @HAVE_PNG@
if png:
add_attribute(libraries = 'png')
with_aec = '@LIB_AEC@'
with_aec = @HAVE_AEC@
if with_aec:
aec_dir = '@AEC_DIR@'
if aec_dir and aec_dir != 'system':
@ -74,13 +75,12 @@ if data_handler == "numpy":
add_attribute(
include_dirs = numpy_include,
)
gribapi_module = Extension('_gribapi_swig',**attdict)
#gribapi_module = Extension('_gribapi_swig',**attdict)
setup (name = 'gribapi',
version = '0.1',
version = '@ECCODES_VERSION_STR@',
author = 'ECMWF',
description = """Grib API SWIG module""",
ext_modules = [gribapi_module],
ext_modules = [Extension('_gribapi_swig',**attdict)],
py_modules = ['gribapi_swig','gribapi'],
)