Skip to content

Commit f880a94

Browse files
authored
Merge pull request open-source-parsers#551 from suttungdigital/detect_locale_support
Check for locale support in CMake
2 parents 0e24e3c + 5a82131 commit f880a94

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/lib_json/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@ if( CMAKE_COMPILER_IS_GNUCXX )
99
endif()
1010
endif( CMAKE_COMPILER_IS_GNUCXX )
1111

12+
include(CheckIncludeFileCXX)
13+
include(CheckTypeSize)
14+
include(CheckStructHasMember)
15+
include(CheckCXXSymbolExists)
16+
17+
check_include_file_cxx(clocale HAVE_CLOCALE)
18+
check_cxx_symbol_exists(localeconv clocale HAVE_LOCALECONV)
19+
20+
if(CMAKE_VERSION VERSION_LESS 3.0.0)
21+
# The "LANGUAGE CXX" parameter is not supported in CMake versions below 3,
22+
# so the C compiler and header has to be used.
23+
check_include_file(locale.h HAVE_LOCALE_H)
24+
set(CMAKE_EXTRA_INCLUDE_FILES locale.h)
25+
check_type_size("struct lconv" LCONV_SIZE)
26+
unset(CMAKE_EXTRA_INCLUDE_FILES)
27+
check_struct_has_member("struct lconv" decimal_point locale.h HAVE_DECIMAL_POINT)
28+
else()
29+
set(CMAKE_EXTRA_INCLUDE_FILES clocale)
30+
check_type_size(lconv LCONV_SIZE LANGUAGE CXX)
31+
unset(CMAKE_EXTRA_INCLUDE_FILES)
32+
check_struct_has_member(lconv decimal_point clocale HAVE_DECIMAL_POINT LANGUAGE CXX)
33+
endif()
34+
35+
if(NOT (HAVE_CLOCALE AND HAVE_LCONV_SIZE AND HAVE_DECIMAL_POINT AND HAVE_LOCALECONV))
36+
message(WARNING "Locale functionality is not supported")
37+
add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT)
38+
endif()
39+
1240
SET( JSONCPP_INCLUDE_DIR ../../include )
1341

1442
SET( PUBLIC_HEADERS

src/lib_json/json_tool.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
#ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED
77
#define LIB_JSONCPP_JSON_TOOL_H_INCLUDED
88

9-
#ifndef NO_LOCALE_SUPPORT
9+
10+
// Also support old flag NO_LOCALE_SUPPORT
11+
#ifdef NO_LOCALE_SUPPORT
12+
#define JSONCPP_NO_LOCALE_SUPPORT
13+
#endif
14+
15+
#ifndef JSONCPP_NO_LOCALE_SUPPORT
1016
#include <clocale>
1117
#endif
1218

@@ -18,7 +24,7 @@
1824

1925
namespace Json {
2026
static char getDecimalPoint() {
21-
#ifdef NO_LOCALE_SUPPORT
27+
#ifdef JSONCPP_NO_LOCALE_SUPPORT
2228
return '\0';
2329
#else
2430
struct lconv* lc = localeconv();

0 commit comments

Comments
 (0)