From 1839f2da342de35de4803f546c60d4bc6047d6fa Mon Sep 17 00:00:00 2001 From: Magnus Bjerke Vik Date: Mon, 7 Nov 2016 10:46:18 +0100 Subject: [PATCH 1/2] Check for locale support in CMake --- src/lib_json/CMakeLists.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index acd804b..6e701c7 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -9,6 +9,34 @@ if( CMAKE_COMPILER_IS_GNUCXX ) endif() endif( CMAKE_COMPILER_IS_GNUCXX ) +include(CheckIncludeFileCXX) +include(CheckTypeSize) +include(CheckStructHasMember) +include(CheckCXXSymbolExists) + +check_include_file_cxx(clocale HAVE_CLOCALE) +check_cxx_symbol_exists(localeconv clocale HAVE_LOCALECONV) + +if(CMAKE_VERSION VERSION_LESS 3.0.0) + # The "LANGUAGE CXX" parameter is not supported in CMake versions below 3, + # so the C compiler and header has to be used. + check_include_file(locale.h HAVE_LOCALE_H) + set(CMAKE_EXTRA_INCLUDE_FILES locale.h) + check_type_size("struct lconv" LCONV_SIZE) + unset(CMAKE_EXTRA_INCLUDE_FILES) + check_struct_has_member("struct lconv" decimal_point locale.h HAVE_DECIMAL_POINT) +else() + set(CMAKE_EXTRA_INCLUDE_FILES clocale) + check_type_size(lconv LCONV_SIZE LANGUAGE CXX) + unset(CMAKE_EXTRA_INCLUDE_FILES) + check_struct_has_member(lconv decimal_point clocale HAVE_DECIMAL_POINT LANGUAGE CXX) +endif() + +if(NOT (HAVE_CLOCALE AND HAVE_LCONV_SIZE AND HAVE_DECIMAL_POINT AND HAVE_LOCALECONV)) + message(WARNING "Locale functionality is not supported") + add_definitions(-DNO_LOCALE_SUPPORT) +endif() + SET( JSONCPP_INCLUDE_DIR ../../include ) SET( PUBLIC_HEADERS From 5a821310331d48900dced317a6f45fcf881dce12 Mon Sep 17 00:00:00 2001 From: Magnus Bjerke Vik Date: Tue, 8 Nov 2016 09:46:34 +0100 Subject: [PATCH 2/2] Rename NO_LOCALE_SUPPORT to JSONCPP_NO_LOCALE_SUPPORT --- src/lib_json/CMakeLists.txt | 2 +- src/lib_json/json_tool.h | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 6e701c7..f1a9ec9 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -34,7 +34,7 @@ endif() if(NOT (HAVE_CLOCALE AND HAVE_LCONV_SIZE AND HAVE_DECIMAL_POINT AND HAVE_LOCALECONV)) message(WARNING "Locale functionality is not supported") - add_definitions(-DNO_LOCALE_SUPPORT) + add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT) endif() SET( JSONCPP_INCLUDE_DIR ../../include ) diff --git a/src/lib_json/json_tool.h b/src/lib_json/json_tool.h index 0e729e6..41d0f49 100644 --- a/src/lib_json/json_tool.h +++ b/src/lib_json/json_tool.h @@ -6,7 +6,13 @@ #ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED #define LIB_JSONCPP_JSON_TOOL_H_INCLUDED -#ifndef NO_LOCALE_SUPPORT + +// Also support old flag NO_LOCALE_SUPPORT +#ifdef NO_LOCALE_SUPPORT +#define JSONCPP_NO_LOCALE_SUPPORT +#endif + +#ifndef JSONCPP_NO_LOCALE_SUPPORT #include #endif @@ -18,7 +24,7 @@ namespace Json { static char getDecimalPoint() { -#ifdef NO_LOCALE_SUPPORT +#ifdef JSONCPP_NO_LOCALE_SUPPORT return '\0'; #else struct lconv* lc = localeconv();