eccodes/CMakeLists.txt

238 lines
6.1 KiB
CMake
Raw Normal View History

2013-03-25 12:04:10 +00:00
############################################################################################
# cmake options:
#
# -DCMAKE_BUILD_TYPE=Debug|RelWithDebInfo|Release|Production
# -DCMAKE_INSTALL_PREFIX=/path/to/install
#
# -DCMAKE_MODULE_PATH=/path/to/ecbuild/cmake
2013-04-03 10:45:13 +00:00
# TODO:
# * build python bindings
2013-03-25 12:04:10 +00:00
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} )
2013-04-10 15:46:41 +00:00
set( GRIB_API_INSTALL_INCLUDE_DIR include CACHE PATH "GRIB_API override installation directory for header files")
2013-03-25 12:04:10 +00:00
include( ecbuild_system )
###############################################################################
# local project
ecbuild_declare_project()
###############################################################################
# some variables/options of this project
2013-04-10 15:46:41 +00:00
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" ON )
option( GRIB_API_MEMORY_MANAGEMENT "enable memory management" OFF )
option( GRIB_API_ALIGN_MEMORY "enable memory alignment" OFF )
option( GRIB_TIMER "enable timer" OFF )
option( GRIB_THREADS "enable threads" OFF )
2013-03-25 12:04:10 +00:00
###############################################################################
# macro processing
2013-04-10 15:46:41 +00:00
set( GRIB_API_EXTRA_LIBRARIES "" )
set( GRIB_API_EXTRA_INCLUDE_DIRS "" )
set( GRIB_API_EXTRA_DEFINITIONS "" )
2013-03-25 12:04:10 +00:00
2013-04-10 15:46:41 +00:00
find_package( CMath )
2013-03-25 12:04:10 +00:00
2013-04-03 10:45:13 +00:00
### SZIP support
2013-03-25 12:04:10 +00:00
2013-04-10 15:46:41 +00:00
set( HAVE_LIBSZIP 0 )
2013-04-03 10:45:13 +00:00
if( GRIB_API_SZIP )
2013-05-14 16:38:40 +00:00
2013-04-03 10:45:13 +00:00
find_package( SZip )
2013-05-14 16:38:40 +00:00
2013-04-10 15:46:41 +00:00
if( SZIP_FOUND )
set( HAVE_LIBSZIP 1 )
endif()
2013-04-03 10:45:13 +00:00
endif()
2013-03-25 12:04:10 +00:00
2013-04-03 10:45:13 +00:00
### JPG support
2013-03-25 12:04:10 +00:00
2013-04-03 10:45:13 +00:00
set( HAVE_JPEG 0 )
set( HAVE_LIBJASPER 0 )
set( HAVE_LIBOPENJPEG 0 )
2013-03-25 12:04:10 +00:00
2013-04-03 10:45:13 +00:00
if( GRIB_API_JPG )
find_package( Jasper )
find_package( OpenJPEG )
if( JASPER_FOUND )
2013-04-23 08:59:14 +00:00
set( HAVE_JPEG 1 )
set( HAVE_LIBJASPER 1 )
2013-04-03 10:45:13 +00:00
endif()
if( OpenJPEG_FOUND )
2013-04-23 08:59:14 +00:00
set( HAVE_JPEG 1 )
2013-04-03 10:45:13 +00:00
set( HAVE_LIBOPENJPEG 1 )
endif()
endif()
### PNG support
set( HAVE_LIBPNG 0 )
2013-04-10 15:46:41 +00:00
if( GRIB_API_PNG )
2013-04-03 10:45:13 +00:00
find_package( PNG )
if( PNG_FOUND )
set( HAVE_LIBPNG 1 )
2013-04-10 15:46:41 +00:00
add_definitions( ${PNG_DEFINITIONS} )
2013-04-03 10:45:13 +00:00
endif()
endif()
### NetCDF support
set( HAVE_NETCDF 0 )
if( GRIB_API_NETCDF )
find_package( NetCDF )
if( NETCDF_FOUND )
set( HAVE_NETCDF 1 )
endif()
endif()
2013-05-14 16:38:40 +00:00
###############################################################################
2013-04-10 15:46:41 +00:00
# other options
if( GRIB_TIMER )
set( GRIB_TIMER 1 )
else()
set( GRIB_TIMER 0 )
endif()
set( IS_BIG_ENDIAN 0 )
if( EC_BIG_ENDIAN )
set( IS_BIG_ENDIAN 1 )
endif()
set( MANAGE_MEM 0 )
if( GRIB_API_MEMORY_MANAGEMENT )
set( MANAGE_MEM 1 )
endif()
set( GRIB_PTHREADS 0 )
set( GRIB_LINUX_PTHREADS 0 )
if( GRIB_THREADS AND CMAKE_THREAD_LIBS_INIT )
if( CMAKE_USE_PTHREADS_INIT )
set( GRIB_PTHREADS 1 )
if( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
set( GRIB_LINUX_PTHREADS 1 )
endif()
endif()
endif()
set( GRIB_MEM_ALIGN 0 )
if( GRIB_API_ALIGN_MEMORY )
set( GRIB_MEM_ALIGN 1 )
endif()
# fix for #if IEEE_LE or IEE_BE instead of #ifdef
if( IEEE_BE )
set( IEEE_LE 0 )
endif()
if( IEEE_LE )
set( IEEE_BE 0 )
endif()
2013-04-03 10:45:13 +00:00
###############################################################################
# contents
2013-03-25 12:04:10 +00:00
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()
2013-04-03 10:45:13 +00:00
### config header
configure_file( grib_api_config.h.in grib_api_config.h )
2013-04-10 15:46:41 +00:00
add_definitions( -DHAVE_GRIB_API_CONFIG_H )
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/grib_api_config.h DESTINATION ${INSTALL_INCLUDE_DIR} )
if( CMAKE_COMPILER_IS_GNUCC )
cmake_add_c_flags("-pedantic")
endif()
2013-04-03 10:45:13 +00:00
2013-05-14 16:38:40 +00:00
############################################################################################
# contents
### define dependencies
set( GRIB_API_TPLS SZip PNG NetCDF Jasper OpenJPEG CMath )
set( GRIB_API_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src )
set( GRIB_API_LIBRARIES grib_api )
get_directory_property( COMPILE_DEFINITIONS GRIB_API_DEFINITIONS )
foreach( _tpl ${GRIB_API_TPLS} )
string( TOUPPER ${_tpl} TPL )
list( APPEND GRIB_API_EXTRA_DEFINITIONS ${${TPL}_DEFINITIONS} )
list( APPEND GRIB_API_EXTRA_INCLUDE_DIRS ${${TPL}_INCLUDE_DIRS} )
list( APPEND GRIB_API_EXTRA_LIBRARIES ${${TPL}_LIBRARIES} )
endforeach()
2013-04-03 10:45:13 +00:00
### include directories
2013-05-14 16:38:40 +00:00
include_directories( ${GRIB_API_INCLUDE_DIRS} )
2013-04-03 10:45:13 +00:00
2013-03-25 12:04:10 +00:00
add_subdirectory( src )
add_subdirectory( tools )
add_subdirectory( fortran )
add_subdirectory( python )
add_subdirectory( definitions )
add_subdirectory( tests )
add_subdirectory( tigge )
add_subdirectory( examples )
2013-04-02 14:17:46 +00:00
add_subdirectory( samples )
add_subdirectory( ifs_samples ) # must come after samples
2013-03-25 12:04:10 +00:00
# ecbuild_dont_pack( DIRS samples DONT_PACK_REGEX "*.grib" )
############################################################################################
2013-04-03 10:45:13 +00:00
# export to other projects
2013-03-25 12:04:10 +00:00
2013-05-14 16:38:40 +00:00
# temporary -- add support for ecbuild 1.0.x sub-project inclusion
# to remove once mars server & client use eckit & ecbuild >= 1.1
2013-04-23 08:59:14 +00:00
2013-04-03 10:45:13 +00:00
if( NOT ${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME} )
2013-05-14 16:38:40 +00:00
set( GRIB_API_DEFINITIONS ${GRIB_API_DEFINITIONS} PARENT_SCOPE )# includes already TPL definitions
set( GRIB_API_INCLUDE_DIRS ${GRIB_API_INCLUDE_DIRS} ${GRIB_API_EXTRA_INCLUDE_DIRS} PARENT_SCOPE )
set( GRIB_API_LIBRARIES ${GRIB_API_LIBRARIES} ${GRIB_API_EXTRA_LIBRARIES} ${CMATH_LIBRARIES} PARENT_SCOPE )
2013-03-25 12:04:10 +00:00
set( GRIB_API_FOUND TRUE PARENT_SCOPE )
endif()
############################################################################################
# finalize
ecbuild_install_project( NAME grib_api )
ecbuild_print_summary()