eccodes/CMakeLists.txt

348 lines
11 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
cmake_minimum_required( VERSION 2.8.11 FATAL_ERROR )
2013-03-25 12:04:10 +00:00
2015-02-18 10:14:22 +00:00
project( eccodes C )
2013-03-25 12:04:10 +00:00
2013-12-11 10:12:34 +00:00
set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../ecbuild/cmake")
2013-03-25 12:04:10 +00:00
include( ecbuild_system NO_POLICY_SCOPE )
2013-03-25 12:04:10 +00:00
2015-09-18 10:07:02 +00:00
ecbuild_requires_macro_version( 1.9 )
2014-01-03 11:20:14 +00:00
2013-03-25 12:04:10 +00:00
###############################################################################
# local project
ecbuild_declare_project()
###############################################################################
# some variables/options of this project
2015-06-09 13:50:51 +00:00
ecbuild_add_option( FEATURE EXAMPLES
DESCRIPTION "Build the examples"
DEFAULT ON
)
ecbuild_add_option( FEATURE JPG
2015-01-09 15:18:52 +00:00
DESCRIPTION "support for JPG decoding/encoding"
DEFAULT ON
)
ecbuild_add_option( FEATURE PNG
2015-01-09 15:18:52 +00:00
DESCRIPTION "support for PNG decoding/encoding"
DEFAULT OFF
REQUIRED_PACKAGES PNG
)
if( HAVE_PNG )
2015-01-09 15:18:52 +00:00
set( HAVE_LIBPNG 1 ) # compatibility with autotools
add_definitions( ${PNG_DEFINITIONS} )
else()
2015-01-09 15:18:52 +00:00
set( HAVE_LIBPNG 0 )
endif()
ecbuild_add_option( FEATURE NETCDF
2015-01-09 15:18:52 +00:00
DESCRIPTION "support for GRIB to NetCDF conversion"
DEFAULT ON
REQUIRED_PACKAGES NetCDF
)
ecbuild_add_option( FEATURE AEC
2015-01-09 15:18:52 +00:00
DESCRIPTION "support for Adaptive Entropy Coding"
DEFAULT OFF
REQUIRED_PACKAGES AEC
)
ecbuild_add_option( FEATURE PYTHON
2015-02-18 10:14:22 +00:00
DESCRIPTION "build the ecCodes Python interface"
2015-01-09 15:18:52 +00:00
DEFAULT ON
REQUIRED_PACKAGES "Python VERSION 2.5" NumPy
)
ecbuild_add_option( FEATURE FORTRAN
2015-02-18 10:14:22 +00:00
DESCRIPTION "build the ecCodes Fortran interface"
2015-01-09 15:18:52 +00:00
DEFAULT ON
2015-06-09 13:50:51 +00:00
# REQUIRED_LANGUAGES Fortran # TODO
)
2015-06-09 13:50:51 +00:00
# TODO Remove this after REQUIRED_LANGUAGES
2014-03-31 12:57:06 +00:00
if( ENABLE_FORTRAN )
# will set EC_HAVE_FORTRAN with the result
ecbuild_enable_fortran( MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/fortran/modules )
2015-01-09 15:18:52 +00:00
set( HAVE_FORTRAN ${EC_HAVE_FORTRAN} )
2015-06-09 13:50:51 +00:00
else()
set( HAVE_FORTRAN 0 )
2014-03-31 12:57:06 +00:00
endif()
# advanced options (not visible in cmake-gui )
2015-12-30 14:39:02 +00:00
ecbuild_add_option( FEATURE MEMORY_MANAGEMENT DESCRIPTION "enable memory management" DEFAULT OFF ADVANCED )
ecbuild_add_option( FEATURE ALIGN_MEMORY DESCRIPTION "enable memory alignment" DEFAULT OFF ADVANCED )
ecbuild_add_option( FEATURE GRIB_TIMER DESCRIPTION "enable timer" DEFAULT OFF ADVANCED )
ecbuild_add_option( FEATURE ECCODES_THREADS DESCRIPTION "enable POSIX threads" DEFAULT OFF ADVANCED )
ecbuild_add_option( FEATURE ECCODES_OMP_THREADS DESCRIPTION "enable OMP threads" DEFAULT OFF ADVANCED )
2013-03-25 12:04:10 +00:00
###############################################################################
# macro processing
2015-02-18 10:14:22 +00:00
set( ECCODES_EXTRA_LIBRARIES "" )
set( ECCODES_EXTRA_INCLUDE_DIRS "" )
set( ECCODES_EXTRA_DEFINITIONS "" )
2013-03-25 12:04:10 +00:00
2013-04-10 15:46:41 +00:00
find_package( CMath )
2015-09-18 10:07:02 +00:00
list( APPEND ECCODES_TPLS CMath )
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-12-09 14:47:14 +00:00
if( ENABLE_JPG )
2013-04-03 10:45:13 +00:00
# Note: This is a deprecated feature but we need it to find Jasper at ECMWF.
# ecbuild_add_extra_search_paths modifies CMAKE_PREFIX_PATH
# which can affect future package discovery if not undone by the caller.
# The current CMAKE_PREFIX_PATH is backed up as _CMAKE_PREFIX_PATH
#
set(ECBUILD_NO_DEPRECATIONS ON) # Suppress deprecation message
ecbuild_add_extra_search_paths( jasper )
2013-04-03 10:45:13 +00:00
find_package( Jasper )
set(CMAKE_PREFIX_PATH ${_CMAKE_PREFIX_PATH}) # Restore CMAKE_PREFIX_PATH
set(ECBUILD_NO_DEPRECATIONS OFF) # Remove suppression
2013-04-03 10:45:13 +00:00
find_package( OpenJPEG )
if( JASPER_FOUND )
2015-09-18 10:07:02 +00:00
list( APPEND ECCODES_TPLS Jasper )
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 )
2015-09-18 10:07:02 +00:00
list( APPEND ECCODES_TPLS OpenJPEG )
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()
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 )
2013-12-09 14:47:14 +00:00
if( ENABLE_MEMORY_MANAGEMENT )
2013-04-10 15:46:41 +00:00
set( MANAGE_MEM 1 )
endif()
set( CMAKE_THREAD_PREFER_PTHREAD 1 ) # find thread library, but prefer pthreads
find_package(Threads REQUIRED)
2015-01-29 15:50:51 +00:00
# debug
message(STATUS " CMAKE_THREAD_LIBS_INIT=${CMAKE_THREAD_LIBS_INIT}")
message(STATUS " CMAKE_USE_PTHREADS_INIT=${CMAKE_USE_PTHREADS_INIT}")
message(STATUS " HAVE_ECCODES_THREADS=${HAVE_ECCODES_THREADS}")
2015-01-29 15:50:51 +00:00
2013-04-10 15:46:41 +00:00
set( GRIB_PTHREADS 0 )
2015-12-30 14:39:02 +00:00
set( GRIB_OMP_THREADS 0 )
2013-04-10 15:46:41 +00:00
set( GRIB_LINUX_PTHREADS 0 )
#if( HAVE_ECCODES_THREADS AND CMAKE_THREAD_LIBS_INIT )
if( HAVE_ECCODES_THREADS )
if( NOT ${CMAKE_USE_PTHREADS_INIT} )
message( FATAL_ERROR "Pthreads is not supported on your system: thread library found=[${CMAKE_THREAD_LIBS_INIT}]" )
endif()
set( GRIB_PTHREADS 1 )
if( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
set( GRIB_LINUX_PTHREADS 1 )
2013-04-10 15:46:41 +00:00
endif()
2015-12-30 14:39:02 +00:00
elseif(HAVE_ECCODES_OMP_THREADS)
ecbuild_enable_omp()
set( GRIB_OMP_THREADS 1 )
2013-04-10 15:46:41 +00:00
endif()
# Cannot have both options
if( HAVE_ECCODES_THREADS AND HAVE_ECCODES_OMP_THREADS )
message( FATAL_ERROR "Cannot enable both POSIX threads and OMP! Please specify just one option" )
endif()
2015-01-29 16:22:33 +00:00
message(STATUS " GRIB_PTHREADS=${GRIB_PTHREADS}")
2015-12-30 14:39:02 +00:00
message(STATUS " GRIB_OMP_THREADS=${GRIB_OMP_THREADS}")
2013-04-10 15:46:41 +00:00
set( GRIB_MEM_ALIGN 0 )
2013-12-09 14:47:14 +00:00
if( ENABLE_ALIGN_MEMORY )
2013-04-10 15:46:41 +00:00
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 ${DEVELOPER_MODE} )
set( the_default_data_prefix ${CMAKE_INSTALL_PREFIX} )
else()
set( the_default_data_prefix ${CMAKE_BINARY_DIR} )
endif()
if( NOT DEFINED ECCODES_DEFINITION_SUFF )
set( ECCODES_DEFINITION_SUFF share/eccodes/definitions )
2013-03-25 12:04:10 +00:00
endif()
if( NOT DEFINED ECCODES_SAMPLES_SUFF )
set( ECCODES_SAMPLES_SUFF share/eccodes/samples )
2013-03-25 12:04:10 +00:00
endif()
if( NOT DEFINED ECCODES_IFS_SAMPLES_SUFF )
set( ECCODES_IFS_SAMPLES_SUFF ifs_samples )
endif()
2013-03-25 12:04:10 +00:00
set( ECCODES_DEFINITION_PATH ${the_default_data_prefix}/${ECCODES_DEFINITION_SUFF} )
set( ECCODES_SAMPLES_PATH ${the_default_data_prefix}/${ECCODES_SAMPLES_SUFF} )
set( ECCODES_IFS_SAMPLES_PATH ${the_default_data_prefix}/${ECCODES_IFS_SAMPLES_SUFF} )
2013-04-03 10:45:13 +00:00
### config header
2014-01-03 11:20:14 +00:00
ecbuild_generate_config_headers()
2015-02-18 18:11:38 +00:00
configure_file( eccodes_config.h.in eccodes_config.h )
2013-04-03 10:45:13 +00:00
2015-02-18 18:11:38 +00:00
add_definitions( -DHAVE_ECCODES_CONFIG_H )
2013-04-10 15:46:41 +00:00
2015-02-18 18:11:38 +00:00
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/eccodes_config.h DESTINATION ${INSTALL_INCLUDE_DIR} )
2013-04-10 15:46:41 +00:00
if( CMAKE_COMPILER_IS_GNUCC )
ecbuild_add_c_flags("-pedantic")
2013-04-10 15:46:41 +00:00
endif()
2013-04-03 10:45:13 +00:00
2013-05-14 16:38:40 +00:00
############################################################################################
# contents
2014-03-31 12:57:06 +00:00
### export package to other ecbuild packages
2013-05-14 16:38:40 +00:00
2015-02-18 10:14:22 +00:00
set( ECCODES_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src )
set( ECCODES_LIBRARIES eccodes )
2013-05-14 16:38:40 +00:00
2015-01-26 22:28:46 +00:00
get_directory_property( COMPILE_DEFINITIONS ECCODES_DEFINITIONS )
2013-05-14 16:38:40 +00:00
2015-02-18 10:14:22 +00:00
foreach( _tpl ${ECCODES_TPLS} )
2014-06-18 16:14:01 +00:00
string( TOUPPER ${_tpl} TPL )
if( ${TPL}_FOUND )
2015-02-18 10:14:22 +00:00
list( APPEND ECCODES_EXTRA_DEFINITIONS ${${TPL}_DEFINITIONS} )
list( APPEND ECCODES_EXTRA_INCLUDE_DIRS ${${TPL}_INCLUDE_DIRS} ${${TPL}_INCLUDE_DIR} )
list( APPEND ECCODES_EXTRA_LIBRARIES ${${TPL}_LIBRARIES} )
2014-06-18 16:14:01 +00:00
endif()
2013-05-14 16:38:40 +00:00
endforeach()
2013-04-03 10:45:13 +00:00
### include directories
2015-02-18 10:14:22 +00:00
include_directories( ${ECCODES_INCLUDE_DIRS} ${ECCODES_EXTRA_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 )
2014-03-31 12:57:06 +00:00
add_subdirectory( data )
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" )
2014-07-11 15:31:24 +00:00
ecbuild_dont_pack( DIRS
concepts tests.ecmwf doxygen confluence examples.dev templates parameters java
gaussian_experimental gribex examples/F77
2015-03-30 10:46:28 +00:00
examples/extra bamboo fortran/fortranCtypes tigge/tools share/eccodes grib_api_for_mars
2015-04-01 08:50:46 +00:00
src/.deps tests/.deps tools/.deps tigge/.deps examples/C/.deps examples/python/.deps
python/.deps fortran/.deps
2014-07-11 15:31:24 +00:00
)
2014-11-04 14:49:23 +00:00
#ecbuild_dont_pack( DIRS data/bufr DONT_PACK_REGEX "*.bufr" )
#ecbuild_dont_pack( DIRS data/tigge DONT_PACK_REGEX "*.grib" )
2013-03-25 12:04:10 +00:00
2014-07-11 15:50:30 +00:00
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
2013-03-25 12:04:10 +00:00
############################################################################################
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
if( EC_HAVE_FORTRAN )
2015-02-18 10:14:22 +00:00
list( APPEND ECCODES_INCLUDE_DIRS ${CMAKE_Fortran_MODULE_DIRECTORY} )
list( APPEND ECCODES_LIBRARIES eccodes_f90 )
endif()
2015-01-27 10:26:33 +00:00
if( NOT PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME )
set( ECCODES_FOUND TRUE PARENT_SCOPE )
set( ECCODES_DEFINITIONS ${ECCODES_DEFINITIONS} PARENT_SCOPE )# includes already TPL definitions
set( ECCODES_INCLUDE_DIRS ${ECCODES_INCLUDE_DIRS} ${ECCODES_EXTRA_INCLUDE_DIRS} PARENT_SCOPE )
set( ECCODES_LIBRARIES ${ECCODES_LIBRARIES} ${ECCODES_EXTRA_LIBRARIES} ${CMATH_LIBRARIES} PARENT_SCOPE )
set( ECCODES_SAMPLES_PATH ${ECCODES_SAMPLES_PATH} PARENT_SCOPE )
set( ECCODES_IFS_SAMPLES_PATH ${ECCODES_IFS_SAMPLES_PATH} PARENT_SCOPE )
set( ECCODES_DEFINITION_PATH ${ECCODES_DEFINITION_PATH} PARENT_SCOPE )
2015-10-21 16:31:19 +00:00
set( ECCODES_INSTALL_EXTRA_TOOLS ${ECCODES_INSTALL_EXTRA_TOOLS} PARENT_SCOPE )
2013-03-25 12:04:10 +00:00
endif()
2015-01-29 13:07:39 +00:00
# pkg-config
ecbuild_pkgconfig(
NAME eccodes
URL "https://software.ecmwf.int/wiki/display/ECC/"
2015-01-29 13:07:39 +00:00
DESCRIPTION "The ecCodes library"
2015-02-13 18:04:42 +00:00
LIBRARIES eccodes
VARIABLES HAVE_JPG HAVE_LIBJASPER HAVE_ECCODES_THREADS HAVE_NETCDF
HAVE_PYTHON HAVE_FORTRAN HAVE_PNG HAVE_AEC
2015-01-29 13:07:39 +00:00
)
if( EC_HAVE_FORTRAN )
ecbuild_pkgconfig(
NAME eccodes_f90
URL "https://software.ecmwf.int/wiki/display/ECC/"
2015-02-13 18:04:42 +00:00
LIBRARIES eccodes_f90 eccodes
DESCRIPTION "The ecCodes library for Fortran 90"
IGNORE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/fortran ${PROJECT_BINARY_DIR}/fortran
VARIABLES HAVE_JPG HAVE_LIBJASPER HAVE_ECCODES_THREADS HAVE_NETCDF
HAVE_PYTHON HAVE_PNG HAVE_AEC
)
2015-01-29 13:07:39 +00:00
endif()
2013-03-25 12:04:10 +00:00
############################################################################################
# finalize
2014-03-31 12:57:06 +00:00
ecbuild_install_project( NAME ${CMAKE_PROJECT_NAME} )
2013-03-25 12:04:10 +00:00
ecbuild_print_summary()
2016-01-27 10:14:25 +00:00
message(STATUS "")
message(STATUS " +---------------------------+")
2016-03-01 10:27:54 +00:00
message(STATUS " | ecCodes version ${ECCODES_VERSION} |")
2016-01-27 10:14:25 +00:00
message(STATUS " | Configuration completed |")
message(STATUS " +---------------------------+")
message(STATUS "")
message(STATUS " You can now do 'make' to compile the package, 'ctest' to test it and 'make install' to install it afterwards.")
message(STATUS "")
message(STATUS "")