eccodes/python/CMakeLists.txt

82 lines
2.7 KiB
CMake
Raw Normal View History

2013-12-09 14:47:14 +00:00
if( ENABLE_PYTHON )
2013-04-03 10:45:13 +00:00
ecbuild_find_python( VERSION 2.5)
2013-04-23 09:04:23 +00:00
2013-04-10 15:46:41 +00:00
find_package( SWIG )
if( SWIG_FOUND )
include( ${SWIG_USE_FILE} )
2013-03-25 12:04:10 +00:00
endif()
2013-04-23 09:04:23 +00:00
2013-04-10 15:46:41 +00:00
# check for Numpy
2013-04-23 09:04:23 +00:00
2013-04-10 15:46:41 +00:00
if(PYTHON_EXECUTABLE)
2013-04-23 09:04:23 +00:00
2013-04-10 15:46:41 +00:00
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/numpy_path.py "try: import numpy; print numpy.get_include()\nexcept: pass\n")
exec_program( ${PYTHON_EXECUTABLE}
ARGS "\"${CMAKE_CURRENT_BINARY_DIR}/determineNumpyPath.py\""
OUTPUT_VARIABLE NUMPY_PATH )
endif()
2013-04-23 09:04:23 +00:00
2013-04-10 15:46:41 +00:00
find_path( PYTHON_NUMPY_INCLUDE_DIR arrayobject.h
"${NUMPY_PATH}/numpy/"
"${PYTHON_INCLUDE_PATH}/numpy/"
/usr/include/python2.6/numpy/
/usr/include/python2.5/numpy/
/usr/include/python2.4/numpy/
/usr/include/python2.3/numpy/
DOC "Directory where the arrayobject.h header file can be found. This file is part of the numpy package" )
2013-04-23 09:04:23 +00:00
2013-04-10 15:46:41 +00:00
if( PYTHON_NUMPY_INCLUDE_DIR )
set(PYTHON_NUMPY_FOUND 1 CACHE INTERNAL "Python numpy development package is available")
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
2013-12-09 14:47:14 +00:00
if( ENABLE_PYTHON AND SWIG_FOUND AND 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
2013-04-23 09:04:23 +00:00
2013-04-10 15:46:41 +00:00
if( PYTHON_NUMPY_FOUND )
set( DATA_HANDLER "numpy" )
else()
set( DATA_HANDLER "array" )
endif()
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} )
get_filename_component(JASPER_DIR ${JASPER_INCLUDE_DIR} PATH )
2013-04-23 09:04:23 +00:00
2013-04-10 15:46:41 +00:00
set( LIB_OPENJPEG ${HAVE_LIBOPENJPEG} )
get_filename_component(OPENJPEG_DIR ${OPENJPEG_INCLUDE_DIR} PATH )
2013-04-23 09:04:23 +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
set_source_files_properties( gribapi_swig.i PROPERTIES C ON )
2013-04-23 09:04:23 +00:00
swig_add_module( gribapi_swig python grib_interface.h grib_interface.c gribapi_swig.i )
2013-04-23 09:04:23 +00:00
swig_link_libraries( gribapi_swig grib_api ${PYTHON_LIBRARIES} )
2013-04-23 09:04:23 +00:00
2013-04-10 15:46:41 +00:00
set(PYTHON_DEST "lib/python${PYTHON_VERSION}/site-packages" )
2013-04-23 09:04:23 +00:00
install(TARGETS _gribapi_swig DESTINATION ${PYTHON_DEST} )
2013-04-23 09:04:23 +00:00
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gribapi_swig.py DESTINATION ${PYTHON_DEST})
install(FILES gribapi.py DESTINATION ${PYTHON_DEST})
2013-04-23 09:04:23 +00:00
2013-03-25 12:04:10 +00:00
endif()
endif()