Skip to content

Commit 9feaa6b

Browse files
Sergei Krivonosohhmm
authored andcommitted
Improve LibFMT detection
Signed-off-by: Sergei Krivonos <sergei.krivonos@mariadb.com>
1 parent 467c7b2 commit 9feaa6b

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ storage/perfschema/pfs_config.h
238238
storage/rocksdb/ldb
239239
storage/rocksdb/myrocks_hotbackup
240240
storage/rocksdb/mysql_ldb
241-
storage/rocksdb/myrocks_hotbackup
242241
storage/rocksdb/rdb_source_revision.h
243242
storage/rocksdb/sst_dump
244243
strings/conf_to_src
@@ -619,3 +618,4 @@ tests/mariadb-client-test
619618
versioninfo_dll.rc
620619
versioninfo_exe.rc
621620
win/packaging/ca/symlinks.cc
621+
/_Deparsed_XSubs.pm

cmake/libfmt.cmake

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
INCLUDE (CheckCXXSourceCompiles)
2-
INCLUDE (ExternalProject)
31

42
SET(WITH_LIBFMT "auto" CACHE STRING
53
"Which libfmt to use (possible values are 'bundled', 'system', or 'auto')")
@@ -12,6 +10,7 @@ MACRO(BUNDLE_LIBFMT)
1210
SET(fmt_byproducts BUILD_BYPRODUCTS ${LIBFMT_INCLUDE_DIR}/fmt/format-inl.h)
1311
ENDIF()
1412

13+
INCLUDE (ExternalProject)
1514
ExternalProject_Add(
1615
libfmt
1716
PREFIX "${dir}"
@@ -26,17 +25,42 @@ ENDMACRO()
2625

2726
MACRO (CHECK_LIBFMT)
2827
IF(WITH_LIBFMT STREQUAL "system" OR WITH_LIBFMT STREQUAL "auto")
28+
FIND_PACKAGE(fmt)
29+
IF(fmt_FOUND)
30+
set(HAVE_SYSTEM_LIBFMT ${fmt_FOUND})
31+
ENDIF()
32+
33+
FIND_LIBRARY(FMT_LIB_FOUND fmt)
34+
IF(FMT_LIB_FOUND)
35+
set(FMT_LIBRARIES fmt CACHE STRING "LibFormat libraries" FORCE)
36+
ADD_DEFINITIONS(-DLINK_SYSTEM_LIBFMT)
37+
ELSE(FMT_LIB_FOUND)
38+
set(FMT_HEADER_ONLY "#define FMT_HEADER_ONLY 1")
39+
set(FMT_LIBRARIES "" CACHE STRING "LibFormat libraries" FORCE)
40+
ENDIF(FMT_LIB_FOUND)
41+
42+
INCLUDE (CheckCXXSourceCompiles)
2943
CHECK_CXX_SOURCE_COMPILES(
3044
"#define FMT_STATIC_THOUSANDS_SEPARATOR ','
31-
#define FMT_HEADER_ONLY 1
45+
${FMT_HEADER_ONLY}
3246
#include <fmt/format-inl.h>
3347
#include <iostream>
48+
#include <string>
49+
#if FMT_VERSION < 70000
50+
using namespace ::fmt::internal;
51+
#else
52+
using namespace ::fmt::detail;
53+
#endif
3454
int main() {
3555
fmt::format_args::format_arg arg=
3656
fmt::detail::make_arg<fmt::format_context>(42);
3757
std::cout << fmt::vformat(\"The answer is {}.\",
3858
fmt::format_args(&arg, 1));
59+
return 0;
3960
}" HAVE_SYSTEM_LIBFMT)
61+
IF (HAVE_SYSTEM_LIBFMT)
62+
ADD_DEFINITIONS(-DHAVE_SYSTEM_LIBFMT)
63+
ENDIF()
4064
ENDIF()
4165
IF(NOT HAVE_SYSTEM_LIBFMT OR WITH_LIBFMT STREQUAL "bundled")
4266
IF (WITH_LIBFMT STREQUAL "system")

sql/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ MAYBE_DISABLE_IPO(sql)
208208
DTRACE_INSTRUMENT(sql)
209209
TARGET_LINK_LIBRARIES(sql
210210
mysys mysys_ssl dbug strings vio pcre2-8
211+
${FMT_LIBRARIES}
211212
tpool
212213
${LIBWRAP} ${LIBCRYPT} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}
213214
${SSL_LIBRARIES}
@@ -277,7 +278,7 @@ IF(MSVC OR CMAKE_SYSTEM_NAME MATCHES AIX)
277278
ENDIF()
278279

279280
ADD_LIBRARY(sql_builtins STATIC ${CMAKE_CURRENT_BINARY_DIR}/sql_builtin.cc)
280-
TARGET_LINK_LIBRARIES(sql_builtins ${MYSQLD_STATIC_PLUGIN_LIBS})
281+
TARGET_LINK_LIBRARIES(sql_builtins PUBLIC ${MYSQLD_STATIC_PLUGIN_LIBS})
281282

282283
MYSQL_ADD_EXECUTABLE(mariadbd ${MYSQLD_SOURCE} DESTINATION ${INSTALL_SBINDIR} COMPONENT Server)
283284

sql/item_strfunc.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,18 @@ C_MODE_END
5757

5858
/* fmtlib include (https://fmt.dev/). */
5959
#define FMT_STATIC_THOUSANDS_SEPARATOR ','
60+
#if !defined(HAVE_SYSTEM_LIBFMT) && !defined(LINK_SYSTEM_LIBFMT)
6061
#define FMT_HEADER_ONLY 1
61-
#include "fmt/format-inl.h"
62+
#endif
63+
64+
#include <fmt/format-inl.h>
65+
66+
#if FMT_VERSION < 70000
67+
using namespace ::fmt::internal;
68+
#else
69+
using namespace ::fmt::detail;
70+
#endif
71+
6272

6373
size_t username_char_length= USERNAME_CHAR_LENGTH;
6474

@@ -1393,22 +1403,22 @@ String *Item_func_sformat::val_str(String *res)
13931403
switch (args[carg]->result_type())
13941404
{
13951405
case INT_RESULT:
1396-
vargs[carg-1]= fmt::detail::make_arg<ctx>(args[carg]->val_int());
1406+
vargs[carg-1]= make_arg<ctx>(args[carg]->val_int());
13971407
break;
13981408
case DECIMAL_RESULT: // TODO
13991409
case REAL_RESULT:
14001410
if (args[carg]->field_type() == MYSQL_TYPE_FLOAT)
1401-
vargs[carg-1]= fmt::detail::make_arg<ctx>((float)args[carg]->val_real());
1411+
vargs[carg-1]= make_arg<ctx>((float)args[carg]->val_real());
14021412
else
1403-
vargs[carg-1]= fmt::detail::make_arg<ctx>(args[carg]->val_real());
1413+
vargs[carg-1]= make_arg<ctx>(args[carg]->val_real());
14041414
break;
14051415
case STRING_RESULT:
14061416
if (!(parg= args[carg]->val_str(&val_arg[carg-1])))
14071417
{
14081418
delete [] vargs;
14091419
return NULL;
14101420
}
1411-
vargs[carg-1]= fmt::detail::make_arg<ctx>(*parg);
1421+
vargs[carg-1]= make_arg<ctx>(*parg);
14121422
break;
14131423
case TIME_RESULT: // TODO
14141424
case ROW_RESULT: // TODO

0 commit comments

Comments
 (0)