Cmake changes

This commit is contained in:
Shahram Najm 2013-04-03 11:45:13 +01:00
parent 00fa9992fc
commit 7f5d1faca2
14 changed files with 229 additions and 42 deletions

2
.gitignore vendored
View File

@ -27,7 +27,7 @@ python/gribapi_swig.pyc
# IFS samples # IFS samples
ifs_samples/ ifs_samples/*/*.tmpl
# compiled source # # compiled source #
################### ###################

View File

@ -5,13 +5,11 @@
# -DCMAKE_INSTALL_PREFIX=/path/to/install # -DCMAKE_INSTALL_PREFIX=/path/to/install
# #
# -DCMAKE_MODULE_PATH=/path/to/ecbuild/cmake # -DCMAKE_MODULE_PATH=/path/to/ecbuild/cmake
#
# -DCMAKE_C_COMPILER=gcc # TODO:
# -DCMAKE_C_COMPILER=g++ # * support for jpg and png
# # * build fortran bindings
# -DCMAKE_PREFIX_PATH=/path/to/jasper:/path/to/any/package/out/of/place # * build python bindings
#
# -DGRIB_API_PATH=/path/to/grib
cmake_minimum_required( VERSION 2.8.4 FATAL_ERROR ) cmake_minimum_required( VERSION 2.8.4 FATAL_ERROR )
@ -29,35 +27,103 @@ ecbuild_declare_project()
############################################################################### ###############################################################################
# some variables/options of this 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 # macro processing
find_package( CMath ) find_package( CMath )
find_package( SZip )
set( HAVE_LIBSZIP ${SZIP_FOUND} )
find_package( SWIG ) find_package( SWIG )
if( SWIG_FOUND ) if( SWIG_FOUND )
include( ${SWIG_USE_FILE} ) include( ${SWIG_USE_FILE} )
endif() 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 # 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 ) if( NOT DEFINED GRIB_API_DEFINITION_PATH )
set( GRIB_API_DEFINITION_PATH ${CMAKE_INSTALL_PREFIX}/share/grib_api/definitions ) set( GRIB_API_DEFINITION_PATH ${CMAKE_INSTALL_PREFIX}/share/grib_api/definitions )
endif() endif()
@ -65,12 +131,18 @@ if( NOT DEFINED GRIB_API_SAMPLES_PATH )
set( GRIB_API_SAMPLES_PATH ${CMAKE_INSTALL_PREFIX}/share/grib_api/samples ) set( GRIB_API_SAMPLES_PATH ${CMAKE_INSTALL_PREFIX}/share/grib_api/samples )
endif() endif()
if( IEEE_BE ) ### config header
add_definitions( -DIEEE_BE )
endif() configure_file( grib_api_config.h.in grib_api_config.h )
if( IEEE_LE )
add_definitions( -DIEEE_LE ) install( FILES ${CMAKE_BINARY_DIR}/grib_api_config.h DESTINATION include/${PROJECT_NAME} )
endif()
### 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( src )
add_subdirectory( tools ) add_subdirectory( tools )
@ -87,11 +159,12 @@ add_subdirectory( ifs_samples ) # must come after samples
# ecbuild_dont_pack( DIRS samples DONT_PACK_REGEX "*.grib" ) # ecbuild_dont_pack( DIRS samples DONT_PACK_REGEX "*.grib" )
############################################################################################ ############################################################################################
# installation # export to other projects
if( NOT ${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME} ) 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_DEFINITIONS ${GRIB_API_PNG_DEFINITIONS} PARENT_SCOPE )
set( GRIB_API_LIBRARIES grib_api ${CMATH_LIBRARIES} 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 ) set( GRIB_API_FOUND TRUE PARENT_SCOPE )
endif() endif()

View File

@ -1,5 +1,7 @@
if( GRB_API_FORTRAN ) if( GRB_API_FORTRAN )
message( WARNING "GRIB_API Fortran bindings still not supported with CMake builds" )
ecbuild_enable_fortran( REQUIRED ) ecbuild_enable_fortran( REQUIRED )
# add here the building of fortran bindings # add here the building of fortran bindings

View File

@ -12,6 +12,16 @@
#define GRIB_DEFINITION_PATH "@GRIB_API_DEFINITION_PATH@" #define GRIB_DEFINITION_PATH "@GRIB_API_DEFINITION_PATH@"
#define GRIB_SAMPLES_PATH "@GRIB_API_SAMPLES_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_LIBSZIP
#cmakedefine HAVE_NETCDF
#endif //grib_api_config_h #endif //grib_api_config_h

View File

@ -0,0 +1,8 @@
add_subdirectory( grib1 )
add_subdirectory( grib1_mlgrib2 )
# add_subdirectory( grib1_mlgrib2_ieee32 )
add_subdirectory( grib1_mlgrib2_ieee64 )

View File

@ -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 )

View File

@ -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 )

View File

@ -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 )

View File

@ -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 )

View File

@ -1,9 +1,29 @@
if( SWIG_FOUND ) if( SWIG_FOUND )
message( STATUS " SWIG command : [${SWIG_EXECUTABLE}]" ) message( STATUS " SWIG command : [${SWIG_EXECUTABLE}]" )
endif() endif()
if(CMATH_FOUND) 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() endif()

View File

@ -1,3 +1,5 @@
### WARNING - support for Python with CMake still not ready
# check for Numpy # check for Numpy
if(PYTHON_EXECUTABLE) if(PYTHON_EXECUTABLE)
@ -28,6 +30,8 @@ endif()
if( GRIB_API_PYTHON AND SWIG_FOUND AND PYTHONLIBS_FOUND ) 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 # preparing for generating setup.py
if( PYTHON_NUMPY_FOUND ) if( PYTHON_NUMPY_FOUND )

12
samples/CMakeLists.txt Normal file
View File

@ -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 )

View File

@ -310,9 +310,21 @@ ecbuild_generate_yy( YYPREFIX grib_yy
DEPENDANT action.c ) DEPENDANT action.c )
ecbuild_add_library( TARGET grib_api ecbuild_add_library( TARGET grib_api
SOURCES griby.c gribl.c ${grib_api_extra_srcs} ${grib_api_srcs} SOURCES
INCLUDES ${SZIP_INCLUDE_DIRS} griby.c gribl.c
LIBS ${SZIP_LIBRARY} ${CMATH_LIBRARIES} ) ${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 # TODO: add support for jpg and png

View File

@ -8,9 +8,7 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/ */
#ifdef HAVE_CONFIG_H #include "grib_api_internal.h"
#include "config.h"
#endif
#ifdef HAVE_NETCDF #ifdef HAVE_NETCDF