ECC-1393: CMake: Add option to build ecCodes with C++

This commit is contained in:
Shahram Najm 2022-05-21 14:37:23 +01:00
parent 7eae7f474b
commit 76bac8da71
5 changed files with 38 additions and 2 deletions

View File

@ -65,6 +65,13 @@ ecbuild_info("Operating system=${CMAKE_SYSTEM} (${EC_OS_BITS} bits)")
###############################################################################
# some variables/options of this project
ecbuild_add_option( FEATURE EXPERIMENTAL_BUILD_WITH_CXX
DESCRIPTION "Build ecCodes with a C++ compiler (Experimental)"
DEFAULT OFF )
if( HAVE_EXPERIMENTAL_BUILD_WITH_CXX )
enable_language( CXX )
endif()
ecbuild_add_option( FEATURE PRODUCT_GRIB
DESCRIPTION "Support for the product GRIB"
DEFAULT ON )
@ -515,3 +522,9 @@ ecbuild_info(" | bindings from PyPI with: |")
ecbuild_info(" | $ pip3 install eccodes |")
ecbuild_info(" +--------------------------------------+")
ecbuild_info("")
if( HAVE_EXPERIMENTAL_BUILD_WITH_CXX )
ecbuild_warn("Please note:\n"
"The option of building with C++ is currently experimental."
"Do not use in operations.")
endif()

View File

@ -427,6 +427,14 @@ if( HAVE_MEMFS )
list(APPEND ECCODES_EXTRA_LIBRARIES eccodes_memfs)
endif()
if( HAVE_EXPERIMENTAL_BUILD_WITH_CXX )
foreach( _src ${eccodes_src_files} )
get_filename_component( _ext ${_src} EXT )
if( _ext STREQUAL ".c" )
set_source_files_properties( ${_src} PROPERTIES LANGUAGE CXX )
endif()
endforeach()
endif()
ecbuild_add_library( TARGET eccodes
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/grib_api_version.c

View File

@ -18,6 +18,10 @@ if( EC_OS_NAME MATCHES "windows" )
list( APPEND ecc_tools_sources wingetopt.c )
endif()
if( HAVE_EXPERIMENTAL_BUILD_WITH_CXX )
set_source_files_properties(${ecc_tools_sources} PROPERTIES LANGUAGE CXX)
endif()
# tools library
ecbuild_add_library( TARGET ecc_tools
TYPE STATIC
@ -48,6 +52,9 @@ list( APPEND ecc_tools_binaries_extra
# Install generic tools
foreach( tool ${ecc_tools_binaries} )
# here we use the fact that each tool has only one C file that matches its name
if( HAVE_EXPERIMENTAL_BUILD_WITH_CXX )
set_source_files_properties(${tool}.c PROPERTIES LANGUAGE CXX)
endif()
ecbuild_add_executable( TARGET ${tool}
SOURCES ${tool}.c
LIBS ecc_tools )

View File

@ -84,7 +84,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
char* format_values = NULL;
char format_latlons[32] = {0,};
char* default_format_values = "%.10e";
char* default_format_latlons = "%9.3f%9.3f";
const char* default_format_latlons = "%9.3f%9.3f";
int print_keys = grib_options_on("p:");
long numberOfPoints = 0;
long bitmapPresent = 0;
@ -305,7 +305,7 @@ static grib_values* get_key_values(grib_runtime_options* options, grib_handle* h
int i = 0;
int ret = 0;
char value[MAX_STRING_LEN] = {0,};
char* notfound = "not found";
const char* notfound = "not found";
for (i = 0; i < options->print_keys_count; i++) {
size_t len = MAX_STRING_LEN;

View File

@ -45,6 +45,10 @@
#define MODE_TAF 5
#define MODE_ANY 6
#ifdef __cplusplus
extern "C" {
#endif
typedef union grib_typed_value
{
long* long_value;
@ -208,4 +212,8 @@ int grib_tool_new_filename_action(grib_runtime_options* options, const char* fil
int grib_no_handle_action(grib_runtime_options* options, int err);
int exit_if_input_is_directory(const char* toolname, const char* filename);
#ifdef __cplusplus
}
#endif
#endif /* GRIB_TOOLS_H */