Skip to content

Commit d5d5865

Browse files
committed
Move strtod_l check to CMake since it's very system-specific
1 parent 29ef7d3 commit d5d5865

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,18 @@ if (MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio")
127127
${CMAKE_MAKE_PROGRAM} -p:FrameworkPathOverride=\"${netfxpath}\" %*")
128128
endif ()
129129

130+
set(strtod_l_headers stdlib.h)
131+
if (APPLE)
132+
set(strtod_l_headers ${strtod_l_headers} xlocale.h)
133+
endif ()
134+
130135
include(CheckSymbolExists)
131136
if (WIN32)
132137
check_symbol_exists(open io.h HAVE_OPEN)
138+
check_symbol_exists(_strtod_l "${strtod_l_headers}" HAVE_STRTOD_L)
133139
else ()
134140
check_symbol_exists(open fcntl.h HAVE_OPEN)
141+
check_symbol_exists(strtod_l "${strtod_l_headers}" HAVE_STRTOD_L)
135142
endif ()
136143

137144
function(add_headers VAR)
@@ -154,6 +161,10 @@ endif ()
154161
add_library(fmt ${FMT_SOURCES} ${FMT_HEADERS} README.rst ChangeLog.rst)
155162
add_library(fmt::fmt ALIAS fmt)
156163

164+
if (HAVE_STRTOD_L)
165+
target_compile_definitions(fmt PUBLIC FMT_LOCALE)
166+
endif ()
167+
157168
if (FMT_WERROR)
158169
target_compile_options(fmt PRIVATE ${WERROR_FLAG})
159170
endif ()

include/fmt/posix.h

-6
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,6 @@ class file {
261261
// Returns the memory page size.
262262
long getpagesize();
263263

264-
#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && \
265-
!defined(__ANDROID__) && !defined(__CYGWIN__) && !defined(__OpenBSD__) && \
266-
!defined(__NEWLIB_H__)
267-
# define FMT_LOCALE
268-
#endif
269-
270264
#ifdef FMT_LOCALE
271265
// A "C" numeric locale.
272266
class Locale {

test/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ if (HAVE_OPEN)
118118
if (FMT_PEDANTIC)
119119
target_compile_options(posix-mock-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
120120
endif ()
121+
if (HAVE_STRTOD_L)
122+
target_compile_definitions(posix-mock-test PRIVATE FMT_LOCALE)
123+
endif ()
121124
add_test(NAME posix-mock-test COMMAND posix-mock-test)
122125
add_fmt_test(posix-test)
123126
endif ()

0 commit comments

Comments
 (0)