2014-10-24 12:36:19 +00:00
|
|
|
if( HAVE_PYTHON )
|
2013-04-03 10:45:13 +00:00
|
|
|
|
2015-01-17 23:47:40 +00:00
|
|
|
#find_package( SWIG )
|
|
|
|
#if( SWIG_FOUND )
|
|
|
|
# include( ${SWIG_USE_FILE} )
|
|
|
|
#endif()
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2013-04-10 15:46:41 +00:00
|
|
|
###############################################################################
|
|
|
|
# swig python interface
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2015-09-29 13:40:48 +00:00
|
|
|
#if( SWIG_FOUND AND PYTHONLIBS_FOUND )
|
|
|
|
if( PYTHONLIBS_FOUND )
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2013-04-10 15:46:41 +00:00
|
|
|
# preparing for generating setup.py -- this may not be needed as cmake can do the swig + shared libs without libtool
|
|
|
|
|
2014-10-24 12:36:19 +00:00
|
|
|
if( HAVE_LIBJASPER )
|
|
|
|
get_filename_component(JASPER_DIR ${JASPER_INCLUDE_DIR} PATH )
|
|
|
|
endif()
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2014-10-24 12:36:19 +00:00
|
|
|
if( HAVE_LIBOPENJPEG )
|
|
|
|
get_filename_component(OPENJPEG_DIR ${OPENJPEG_INCLUDE_DIR} PATH )
|
|
|
|
endif()
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2013-04-10 15:46:41 +00:00
|
|
|
configure_file( setup.py.in setup.py )
|
|
|
|
|
|
|
|
# compile swig interface
|
|
|
|
|
2016-07-13 16:43:27 +00:00
|
|
|
# set(CMAKE_SWIG_FLAGS "")
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2016-07-13 16:43:27 +00:00
|
|
|
# set_source_files_properties( gribapi_swig.i PROPERTIES C ON )
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2016-07-13 16:43:27 +00:00
|
|
|
# if( NUMPY_FOUND )
|
|
|
|
# set( CMAKE_SWIG_FLAGS "-DNUMPY" )
|
|
|
|
# include_directories( ${NUMPY_INCLUDE_DIRS} )
|
|
|
|
# endif()
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2015-01-17 23:47:40 +00:00
|
|
|
####### Do not invoke swig. Use our own generated C wrapper file ######
|
2016-02-16 18:05:11 +00:00
|
|
|
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}
|
2016-06-09 15:07:01 +00:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} setup.py build_ext --inplace -R ${CMAKE_BINARY_DIR}/lib
|
2016-07-13 16:48:20 +00:00
|
|
|
DEPENDS grib_interface.h grib_interface.c swig_wrap_numpy.c setup.py.in eccodes )
|
2016-07-13 16:15:27 +00:00
|
|
|
add_custom_target(build_swig_wrapper ALL DEPENDS ${_gribapi_swig})
|
2016-02-16 18:05:11 +00:00
|
|
|
|
|
|
|
#ecbuild_add_library(TARGET _gribapi_swig
|
|
|
|
# TYPE SHARED
|
|
|
|
# NOINSTALL
|
2016-07-13 16:48:20 +00:00
|
|
|
# SOURCES grib_interface.h grib_interface.c swig_wrap_numpy.c
|
2016-07-13 16:43:27 +00:00
|
|
|
# INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${PYTHON_INCLUDE_DIRS}
|
2016-02-16 18:05:11 +00:00
|
|
|
# LIBS eccodes ${PYTHON_LIBRARIES} )
|
2015-01-17 23:47:40 +00:00
|
|
|
# Don't use the lib prefix. This is needed for the python case where a _modulename.so is generated
|
2016-02-16 18:05:11 +00:00
|
|
|
#set_target_properties(_gribapi_swig PROPERTIES PREFIX "")
|
2015-01-17 23:47:40 +00:00
|
|
|
|
2016-07-13 16:15:27 +00:00
|
|
|
# Copy gribapi and eccodes python modules to build area
|
|
|
|
file( COPY eccodes gribapi DESTINATION . )
|
2016-07-13 16:48:20 +00:00
|
|
|
configure_file( swig_wrap_numpy.py gribapi/gribapi_swig.py COPYONLY )
|
2016-07-13 16:15:27 +00:00
|
|
|
|
|
|
|
# Call distutils for installation
|
2016-07-19 08:02:20 +00:00
|
|
|
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} setup.py install --prefix $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2013-03-25 12:04:10 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
endif()
|