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
|
|
|
# check for Numpy
|
2014-10-23 10:23:35 +00:00
|
|
|
find_package( NumPy )
|
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
|
|
|
|
2015-10-27 16:28:10 +00:00
|
|
|
set(PYTHON_DEST_ECCODES "${INSTALL_LIB_DIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/eccodes" )
|
|
|
|
set(PYTHON_DEST_GRIBAPI "${INSTALL_LIB_DIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/gribapi" )
|
2015-03-20 18:26:32 +00:00
|
|
|
|
2015-10-27 16:28:10 +00:00
|
|
|
file( RELATIVE_PATH relative_rpath "${CMAKE_INSTALL_PREFIX}/${PYTHON_DEST_ECCODES}" "${${PNAME}_FULL_INSTALL_LIB_DIR}" )
|
2015-03-20 18:26:32 +00:00
|
|
|
|
2015-06-09 13:50:51 +00:00
|
|
|
# debug_var( relative_rpath )
|
2015-03-20 18:26:32 +00:00
|
|
|
|
|
|
|
ecbuild_append_to_rpath( ${relative_rpath} )
|
|
|
|
ecbuild_append_to_rpath( "../../lib" ) # for ctest to find the libs
|
|
|
|
|
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
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2014-10-23 10:23:35 +00:00
|
|
|
if( NUMPY_FOUND )
|
2014-10-21 17:15:00 +00:00
|
|
|
set( DATA_HANDLER "numpy" )
|
2013-04-10 15:46:41 +00:00
|
|
|
else()
|
2014-10-21 17:15:00 +00:00
|
|
|
set( DATA_HANDLER "array" )
|
2013-04-10 15:46:41 +00:00
|
|
|
endif()
|
2015-01-17 23:47:40 +00:00
|
|
|
set( _swig_c_wrapper swig_wrap_${DATA_HANDLER}.c )
|
|
|
|
set( _swig_py_wrapper swig_wrap_${DATA_HANDLER}.py )
|
2013-04-10 15:46:41 +00:00
|
|
|
|
|
|
|
set( BUILD_DIR "${PROJECT_SOURCE_DIR}" ) # setup.py assumes build_dir is same as source_dir -- not true for cmake builds
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2013-04-10 15:46:41 +00:00
|
|
|
set( LIB_PNG "${HAVE_LIBPNG}" )
|
|
|
|
|
|
|
|
set( LIB_JASPER ${HAVE_LIBJASPER} )
|
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
|
|
|
|
2013-04-10 15:46:41 +00:00
|
|
|
set( LIB_OPENJPEG ${HAVE_LIBOPENJPEG} )
|
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-09-18 07:53:52 +00:00
|
|
|
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${PYTHON_INCLUDE_DIRS} )
|
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
|
|
|
|
|
|
|
|
set(CMAKE_SWIG_FLAGS "")
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2013-04-10 15:46:41 +00:00
|
|
|
include_directories( ${PYTHON_INCLUDE_PATH} )
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2013-06-14 12:56:55 +00:00
|
|
|
set_source_files_properties( gribapi_swig.i PROPERTIES C ON )
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2015-01-17 23:47:40 +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-02-16 18:05:11 +00:00
|
|
|
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} )
|
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
|
|
|
|
|
|
|
# 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}
|
2016-02-16 18:05:11 +00:00
|
|
|
DEPENDS ${_gribapi_swig} build/${_gribapi_swig}
|
2015-01-17 23:47:40 +00:00
|
|
|
)
|
|
|
|
add_custom_target(copy_swig_py ALL DEPENDS ${_swig_py})
|
|
|
|
#######################
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2016-02-16 18:05:11 +00:00
|
|
|
#install(TARGETS _gribapi_swig DESTINATION ${PYTHON_DEST_GRIBAPI} )
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2016-02-16 18:05:11 +00:00
|
|
|
#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})
|
2015-10-27 16:28:10 +00:00
|
|
|
install(FILES gribapi.py DESTINATION ${PYTHON_DEST_GRIBAPI})
|
|
|
|
install(FILES eccodes.py DESTINATION ${PYTHON_DEST_ECCODES})
|
|
|
|
|
|
|
|
install(FILES init_gribapi.py DESTINATION ${PYTHON_DEST_GRIBAPI} RENAME __init__.py)
|
|
|
|
install(FILES init_eccodes.py DESTINATION ${PYTHON_DEST_ECCODES} RENAME __init__.py)
|
2013-04-23 09:04:23 +00:00
|
|
|
|
2013-03-25 12:04:10 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
endif()
|