From 7f5d1faca2d3cbfdd243452aca9db167f39e9d42 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 3 Apr 2013 11:45:13 +0100 Subject: [PATCH] Cmake changes --- .gitignore | 2 +- CMakeLists.txt | 137 ++++++++++++++---- fortran/CMakeLists.txt | 2 + grib_api_config.h.in | 10 ++ ifs_samples/CMakeLists.txt | 8 + ifs_samples/grib1/CMakeLists.txt | 12 ++ ifs_samples/grib1_mlgrib2/CMakeLists.txt | 12 ++ .../grib1_mlgrib2_ieee32/CMakeLists.txt | 12 ++ .../grib1_mlgrib2_ieee64/CMakeLists.txt | 12 ++ project_summary.cmake | 24 ++- python/CMakeLists.txt | 4 + samples/CMakeLists.txt | 12 ++ src/CMakeLists.txt | 20 ++- tools/grib_to_netcdf.c | 4 +- 14 files changed, 229 insertions(+), 42 deletions(-) create mode 100644 ifs_samples/CMakeLists.txt create mode 100644 ifs_samples/grib1/CMakeLists.txt create mode 100644 ifs_samples/grib1_mlgrib2/CMakeLists.txt create mode 100644 ifs_samples/grib1_mlgrib2_ieee32/CMakeLists.txt create mode 100644 ifs_samples/grib1_mlgrib2_ieee64/CMakeLists.txt create mode 100644 samples/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 4ec41ea04..ae9e8e9c7 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,7 @@ python/gribapi_swig.pyc # IFS samples -ifs_samples/ +ifs_samples/*/*.tmpl # compiled source # ################### diff --git a/CMakeLists.txt b/CMakeLists.txt index 087d0848b..1e813e463 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,13 +5,11 @@ # -DCMAKE_INSTALL_PREFIX=/path/to/install # # -DCMAKE_MODULE_PATH=/path/to/ecbuild/cmake -# -# -DCMAKE_C_COMPILER=gcc -# -DCMAKE_C_COMPILER=g++ -# -# -DCMAKE_PREFIX_PATH=/path/to/jasper:/path/to/any/package/out/of/place -# -# -DGRIB_API_PATH=/path/to/grib + +# TODO: +# * support for jpg and png +# * build fortran bindings +# * build python bindings cmake_minimum_required( VERSION 2.8.4 FATAL_ERROR ) @@ -29,35 +27,103 @@ ecbuild_declare_project() ############################################################################### # some variables/options of this project -option( GRIB_API_PYTHON "whether or not to build the GRIB_API python interface" ON ) +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( SZip ) -set( HAVE_LIBSZIP ${SZIP_FOUND} ) - 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 -### config header - -configure_file( grib_api_config.h.in grib_api_config.h ) - -### 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 ) - if( NOT DEFINED GRIB_API_DEFINITION_PATH ) set( GRIB_API_DEFINITION_PATH ${CMAKE_INSTALL_PREFIX}/share/grib_api/definitions ) endif() @@ -65,12 +131,18 @@ if( NOT DEFINED GRIB_API_SAMPLES_PATH ) set( GRIB_API_SAMPLES_PATH ${CMAKE_INSTALL_PREFIX}/share/grib_api/samples ) endif() -if( IEEE_BE ) - add_definitions( -DIEEE_BE ) -endif() -if( IEEE_LE ) - add_definitions( -DIEEE_LE ) -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 ) @@ -87,11 +159,12 @@ add_subdirectory( ifs_samples ) # must come after samples # ecbuild_dont_pack( DIRS samples DONT_PACK_REGEX "*.grib" ) ############################################################################################ -# installation +# export to other projects -if( NOT ${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME} ) - set( GRIB_API_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src PARENT_SCOPE ) - set( GRIB_API_LIBRARIES grib_api ${CMATH_LIBRARIES} PARENT_SCOPE ) +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() diff --git a/fortran/CMakeLists.txt b/fortran/CMakeLists.txt index 225fc4b9d..18ebae00a 100644 --- a/fortran/CMakeLists.txt +++ b/fortran/CMakeLists.txt @@ -1,5 +1,7 @@ if( GRB_API_FORTRAN ) + message( WARNING "GRIB_API Fortran bindings still not supported with CMake builds" ) + ecbuild_enable_fortran( REQUIRED ) # add here the building of fortran bindings diff --git a/grib_api_config.h.in b/grib_api_config.h.in index 1cee5c154..71bf4b6b4 100644 --- a/grib_api_config.h.in +++ b/grib_api_config.h.in @@ -12,6 +12,16 @@ #define GRIB_DEFINITION_PATH "@GRIB_API_DEFINITION_PATH@" #define GRIB_SAMPLES_PATH "@GRIB_API_SAMPLES_PATH@" +#define IEEE_BE @IEEE_BE@ +#define IEEE_LE @IEEE_LE@ + +#define HAVE_JPEG @HAVE_JPEG@ +#define HAVE_LIBJASPER @HAVE_LIBJASPER@ +#define HAVE_LIBOPENJPEG @HAVE_LIBOPENJPEG@ + +#define HAVE_LIBPNG @HAVE_LIBPNG@ + #cmakedefine HAVE_LIBSZIP +#cmakedefine HAVE_NETCDF #endif //grib_api_config_h diff --git a/ifs_samples/CMakeLists.txt b/ifs_samples/CMakeLists.txt new file mode 100644 index 000000000..7a4975007 --- /dev/null +++ b/ifs_samples/CMakeLists.txt @@ -0,0 +1,8 @@ +add_subdirectory( grib1 ) + +add_subdirectory( grib1_mlgrib2 ) + +# add_subdirectory( grib1_mlgrib2_ieee32 ) + +add_subdirectory( grib1_mlgrib2_ieee64 ) + diff --git a/ifs_samples/grib1/CMakeLists.txt b/ifs_samples/grib1/CMakeLists.txt new file mode 100644 index 000000000..052162bd7 --- /dev/null +++ b/ifs_samples/grib1/CMakeLists.txt @@ -0,0 +1,12 @@ +set( _basedir grib1 ) + +list( APPEND ifs_samples_${_basedir} + gg_ml.tmpl + gg_sfc.tmpl + sh_ml.tmpl + sh_sfc.tmpl +) + +install( FILES ${GRIB_API_SAMPLES_FILES} ${ifs_samples_${_basedir}} + DESTINATION share/${PROJECT_NAME}/ifs_samples/${_basedir} + PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ ) diff --git a/ifs_samples/grib1_mlgrib2/CMakeLists.txt b/ifs_samples/grib1_mlgrib2/CMakeLists.txt new file mode 100644 index 000000000..86f6cefc8 --- /dev/null +++ b/ifs_samples/grib1_mlgrib2/CMakeLists.txt @@ -0,0 +1,12 @@ +set( _basedir grib1_mlgrib2 ) + +list( APPEND ifs_samples_${_basedir} + gg_ml.tmpl + gg_sfc.tmpl + sh_ml.tmpl + sh_sfc.tmpl +) + +install( FILES ${GRIB_API_SAMPLES_FILES} ${ifs_samples_${_basedir}} + DESTINATION share/${PROJECT_NAME}/ifs_samples/${_basedir} + PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ ) diff --git a/ifs_samples/grib1_mlgrib2_ieee32/CMakeLists.txt b/ifs_samples/grib1_mlgrib2_ieee32/CMakeLists.txt new file mode 100644 index 000000000..ee10cc492 --- /dev/null +++ b/ifs_samples/grib1_mlgrib2_ieee32/CMakeLists.txt @@ -0,0 +1,12 @@ +set( _basedir grib1_mlgrib2_ieee32 ) + +list( APPEND ifs_samples_${_basedir} + gg_ml.tmpl + gg_sfc.tmpl + sh_ml.tmpl + sh_sfc.tmpl +) + +install( FILES ${GRIB_API_SAMPLES_FILES} ${ifs_samples_${_basedir}} + DESTINATION share/${PROJECT_NAME}/ifs_samples/${_basedir} + PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ ) diff --git a/ifs_samples/grib1_mlgrib2_ieee64/CMakeLists.txt b/ifs_samples/grib1_mlgrib2_ieee64/CMakeLists.txt new file mode 100644 index 000000000..975f5d5dd --- /dev/null +++ b/ifs_samples/grib1_mlgrib2_ieee64/CMakeLists.txt @@ -0,0 +1,12 @@ +set( _basedir grib1_mlgrib2_ieee64 ) + +list( APPEND ifs_samples_${_basedir} + gg_ml.tmpl + gg_sfc.tmpl + sh_ml.tmpl + sh_sfc.tmpl +) + +install( FILES ${GRIB_API_SAMPLES_FILES} ${ifs_samples_${_basedir}} + DESTINATION share/${PROJECT_NAME}/ifs_samples/${_basedir} + PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ ) diff --git a/project_summary.cmake b/project_summary.cmake index 36fcb7c20..0f24d7c59 100644 --- a/project_summary.cmake +++ b/project_summary.cmake @@ -1,9 +1,29 @@ if( SWIG_FOUND ) - message( STATUS " SWIG command : [${SWIG_EXECUTABLE}]" ) + message( STATUS " SWIG command : [${SWIG_EXECUTABLE}]" ) endif() if(CMATH_FOUND) - message( STATUS " CMath libs : [${CMATH_LIBRARIES}]" ) + message( STATUS " CMath libs : [${CMATH_LIBRARIES}]" ) +endif() + +if( PNG_FOUND ) + message( STATUS " PNG libs : [${PNG_LIBRARIES}]" ) + message( STATUS " includes : [${PNG_INCLUDE_DIR}]" ) +endif() + +if( JASPER_FOUND ) + message( STATUS " Jasper libs : [${JASPER_LIBRARIES}]" ) + message( STATUS " includes : [${JASPER_INCLUDE_DIR}]" ) +endif() + +if( OpenJPEG_FOUND ) + message( STATUS " OpenJPEG libs : [${OPENJPEG_LIBRARIES}]" ) + message( STATUS " includes : [${OPENJPEG_INCLUDE_DIR}]" ) +endif() + +if( NETCDF_FOUND ) + message( STATUS " NetCDF libs : [${NETCDF_LIBRARIES}]" ) + message( STATUS " includes : [${NETCDF_INCLUDE_DIR}]" ) endif() diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index ad26abd7a..a9dce9e08 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,3 +1,5 @@ +### WARNING - support for Python with CMake still not ready + # check for Numpy if(PYTHON_EXECUTABLE) @@ -28,6 +30,8 @@ endif() if( GRIB_API_PYTHON AND SWIG_FOUND AND PYTHONLIBS_FOUND ) + message( WARNING "Support for Python with CMake still not ready" ) + # preparing for generating setup.py if( PYTHON_NUMPY_FOUND ) diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt new file mode 100644 index 000000000..af617a435 --- /dev/null +++ b/samples/CMakeLists.txt @@ -0,0 +1,12 @@ +file( GLOB samples_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.tmpl" ) + +install( FILES ${samples_files} + DESTINATION share/${PROJECT_NAME}/samples + PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ ) + +foreach( tmpl ${samples_files} ) + list( APPEND GRIB_API_SAMPLES_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${tmpl} ) +endforeach() + +set( GRIB_API_SAMPLES_DIR ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE ) +set( GRIB_API_SAMPLES_FILES ${GRIB_API_SAMPLES_FILES} PARENT_SCOPE ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fab42ea75..c8c076bc6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -310,11 +310,23 @@ ecbuild_generate_yy( YYPREFIX grib_yy DEPENDANT action.c ) ecbuild_add_library( TARGET grib_api - SOURCES griby.c gribl.c ${grib_api_extra_srcs} ${grib_api_srcs} - INCLUDES ${SZIP_INCLUDE_DIRS} - LIBS ${SZIP_LIBRARY} ${CMATH_LIBRARIES} ) + SOURCES + griby.c gribl.c + ${grib_api_extra_srcs} + ${grib_api_srcs} + INCLUDES + ${SZIP_INCLUDE_DIRS} + ${GRIB_API_NETCDF_LIBRARIES} + ${GRIB_API_JPG_INCLUDE_DIRS} + ${GRIB_API_PNG_INCLUDE_DIRS} + LIBS + ${SZIP_LIBRARY} + ${GRIB_API_NETCDF_LIBRARIES} + ${GRIB_API_JPG_LIBRARIES} + ${GRIB_API_PNG_LIBRARIES} + ${CMATH_LIBRARIES} ) # TODO: add support for jpg and png -install( FILES grib_api.h DESTINATION include/${PROJECT_NAME} ) \ No newline at end of file +install( FILES grib_api.h DESTINATION include/${PROJECT_NAME} ) diff --git a/tools/grib_to_netcdf.c b/tools/grib_to_netcdf.c index fe4e2fa7d..783481f68 100644 --- a/tools/grib_to_netcdf.c +++ b/tools/grib_to_netcdf.c @@ -8,9 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include "grib_api_internal.h" #ifdef HAVE_NETCDF