mirror of https://github.com/ecmwf/eccodes.git
177 lines
5.0 KiB
CMake
177 lines
5.0 KiB
CMake
############################################################################################
|
|
# cmake options:
|
|
#
|
|
# -DCMAKE_BUILD_TYPE=Debug|RelWithDebInfo|Release|Production
|
|
# -DCMAKE_INSTALL_PREFIX=/path/to/install
|
|
#
|
|
# -DCMAKE_MODULE_PATH=/path/to/ecbuild/cmake
|
|
|
|
# TODO:
|
|
# * support for jpg and png
|
|
# * build fortran bindings
|
|
# * build python bindings
|
|
|
|
cmake_minimum_required( VERSION 2.8.4 FATAL_ERROR )
|
|
|
|
project( grib_api C )
|
|
|
|
set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} )
|
|
|
|
include( ecbuild_system )
|
|
|
|
###############################################################################
|
|
# local project
|
|
|
|
ecbuild_declare_project()
|
|
|
|
###############################################################################
|
|
# some variables/options of this project
|
|
|
|
option( GRIB_API_JPG "try to add support for JPG encoding" ON )
|
|
option( GRIB_API_PNG "try to add support for PNG encoding" ON )
|
|
option( GRIB_API_NETCDF "try to add support for NetCDF" ON )
|
|
option( GRIB_API_SZIP "try to add support for SZip encoding" ON )
|
|
option( GRIB_API_PYTHON "try to build the GRIB_API Python interface" ON )
|
|
option( GRIB_API_FORTRAN "try to build the GRIB_API Fortran interface" OFF )
|
|
|
|
###############################################################################
|
|
# macro processing
|
|
|
|
find_package( CMath )
|
|
|
|
find_package( SWIG )
|
|
if( SWIG_FOUND )
|
|
include( ${SWIG_USE_FILE} )
|
|
endif()
|
|
|
|
### SZIP support
|
|
|
|
if( GRIB_API_SZIP )
|
|
find_package( SZip )
|
|
set( HAVE_LIBSZIP ${SZIP_FOUND} )
|
|
endif()
|
|
|
|
### JPG support
|
|
|
|
set( GRIB_API_JPG_LIBRARIES "" )
|
|
set( GRIB_API_JPG_INCLUDE_DIRS "" )
|
|
|
|
set( HAVE_JPEG 0 )
|
|
set( HAVE_LIBJASPER 0 )
|
|
set( HAVE_LIBOPENJPEG 0 )
|
|
|
|
if( GRIB_API_JPG )
|
|
|
|
find_package( Jasper )
|
|
find_package( OpenJPEG )
|
|
|
|
if( JASPER_FOUND )
|
|
list( APPEND GRIB_API_JPG_LIBRARIES ${JASPER_LIBRARIES} )
|
|
list( APPEND GRIB_API_JPG_INCLUDE_DIRS ${JASPER_INCLUDE_DIR} )
|
|
set( HAVE_JPEG 1 )
|
|
set( HAVE_LIBJASPER 1 )
|
|
endif()
|
|
|
|
if( OpenJPEG_FOUND )
|
|
list( APPEND GRIB_API_JPG_LIBRARIES ${OPENJPEG_LIBRARIES} )
|
|
list( APPEND GRIB_API_JPG_INCLUDE_DIRS ${OPENJPEG_INCLUDE_DIR} )
|
|
set( HAVE_JPEG 1 )
|
|
set( HAVE_LIBOPENJPEG 1 )
|
|
endif()
|
|
|
|
endif()
|
|
|
|
### PNG support
|
|
|
|
set( GRIB_API_PNG_LIBRARIES "" )
|
|
set( GRIB_API_PNG_INCLUDE_DIRS "" )
|
|
|
|
set( HAVE_LIBPNG 0 )
|
|
|
|
if( GRIB_API_JPG )
|
|
|
|
find_package( PNG )
|
|
|
|
if( PNG_FOUND )
|
|
list( APPEND GRIB_API_PNG_LIBRARIES ${PNG_LIBRARIES} )
|
|
list( APPEND GRIB_API_PNG_INCLUDE_DIRS ${PNG_INCLUDE_DIR} )
|
|
list( APPEND GRIB_API_PNG_DEFINITIONS ${PNG_DEFINITIONS} )
|
|
add_definitions( ${PNG_DEFINITIONS} )
|
|
set( HAVE_LIBPNG 1 )
|
|
endif()
|
|
|
|
endif()
|
|
|
|
### NetCDF support
|
|
|
|
set( GRIB_API_NETCDF_LIBRARIES "" )
|
|
set( GRIB_API_NETCDF_INCLUDE_DIRS "" )
|
|
|
|
set( HAVE_NETCDF 0 )
|
|
|
|
if( GRIB_API_NETCDF )
|
|
|
|
find_package( NetCDF )
|
|
|
|
if( NETCDF_FOUND )
|
|
list( APPEND GRIB_API_NETCDF_LIBRARIES ${NETCDF_LIBRARIES} )
|
|
list( APPEND GRIB_API_NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR} )
|
|
set( HAVE_NETCDF 1 )
|
|
endif()
|
|
|
|
endif()
|
|
|
|
###############################################################################
|
|
# contents
|
|
|
|
if( NOT DEFINED GRIB_API_DEFINITION_PATH )
|
|
set( GRIB_API_DEFINITION_PATH ${CMAKE_INSTALL_PREFIX}/share/grib_api/definitions )
|
|
endif()
|
|
if( NOT DEFINED GRIB_API_SAMPLES_PATH )
|
|
set( GRIB_API_SAMPLES_PATH ${CMAKE_INSTALL_PREFIX}/share/grib_api/samples )
|
|
endif()
|
|
|
|
### config header
|
|
|
|
configure_file( grib_api_config.h.in grib_api_config.h )
|
|
|
|
install( FILES ${CMAKE_BINARY_DIR}/grib_api_config.h DESTINATION include/${PROJECT_NAME} )
|
|
|
|
### include directories
|
|
|
|
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
|
|
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src )
|
|
|
|
add_definitions( -DHAVE_GRIB_API_CONFIG_H )
|
|
|
|
add_subdirectory( src )
|
|
add_subdirectory( tools )
|
|
add_subdirectory( fortran )
|
|
add_subdirectory( python )
|
|
add_subdirectory( definitions )
|
|
add_subdirectory( tests )
|
|
add_subdirectory( tigge )
|
|
add_subdirectory( examples )
|
|
|
|
add_subdirectory( samples )
|
|
add_subdirectory( ifs_samples ) # must come after samples
|
|
|
|
# ecbuild_dont_pack( DIRS samples DONT_PACK_REGEX "*.grib" )
|
|
|
|
############################################################################################
|
|
# export to other projects
|
|
|
|
if( NOT ${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME} )
|
|
set( GRIB_API_DEFINITIONS ${GRIB_API_PNG_DEFINITIONS} PARENT_SCOPE )
|
|
set( GRIB_API_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src ${NETCDF_INCLUDE_DIR} ${GRIB_API_JPG_INCLUDE_DIRS} ${GRIB_API_PNG_INCLUDE_DIRS} PARENT_SCOPE )
|
|
set( GRIB_API_LIBRARIES grib_api ${NETCDF_LIBRARIES} ${GRIB_API_JPG_LIBRARIES} ${GRIB_API_PNG_LIBRARIES} ${CMATH_LIBRARIES} PARENT_SCOPE )
|
|
set( GRIB_API_FOUND TRUE PARENT_SCOPE )
|
|
endif()
|
|
|
|
############################################################################################
|
|
# finalize
|
|
|
|
ecbuild_install_project( NAME grib_api )
|
|
|
|
ecbuild_print_summary()
|