Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-35746 - cmake(libfmt): use find_package to find libfmt #3786

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions cmake/libfmt.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
INCLUDE (CheckCXXSourceRuns)
INCLUDE (ExternalProject)
FIND_PACKAGE(fmt QUIET)

SET(WITH_LIBFMT "auto" CACHE STRING
"Which libfmt to use (possible values are 'bundled', 'system', or 'auto')")
Expand All @@ -24,23 +25,33 @@ MACRO(BUNDLE_LIBFMT)
)
ENDMACRO()

MACRO (CHECK_LIBFMT)
IF(WITH_LIBFMT STREQUAL "system" OR WITH_LIBFMT STREQUAL "auto")
SET(CMAKE_REQUIRED_INCLUDES ${LIBFMT_INCLUDE_DIR})
CHECK_CXX_SOURCE_RUNS(
"#define FMT_STATIC_THOUSANDS_SEPARATOR ','
#define FMT_HEADER_ONLY 1
#include <fmt/args.h>
int main() {
using ArgStore= fmt::dynamic_format_arg_store<fmt::format_context>;
ArgStore arg_store;
int answer= 4321;
arg_store.push_back(answer);
return fmt::vformat(\"{:L}\", arg_store).compare(\"4,321\");
}" HAVE_SYSTEM_LIBFMT)
SET(CMAKE_REQUIRED_INCLUDES)
MACRO(CHECK_LIBFMT)
IF (WITH_LIBFMT STREQUAL "system" OR WITH_LIBFMT STREQUAL "auto")
IF (fmt_FOUND)
MESSAGE(STATUS "Found system libfmt: ${fmt_VERSION}")
SET(HAVE_SYSTEM_LIBFMT 1)
ELSE()
MESSAGE(STATUS "Could NOT find system libfmt via config; trying compile test.")

SET(CMAKE_REQUIRED_INCLUDES "${LIBFMT_INCLUDE_DIR}")
CHECK_CXX_SOURCE_RUNS(
"#define FMT_STATIC_THOUSANDS_SEPARATOR ','
#define FMT_HEADER_ONLY 1
#include <fmt/args.h>
int main() {
using ArgStore= fmt::dynamic_format_arg_store<fmt::format_context>;
ArgStore arg_store;
int answer= 4321;
arg_store.push_back(answer);
return fmt::vformat(\"{:L}\", arg_store).compare(\"4,321\");
}"
HAVE_SYSTEM_LIBFMT
)
SET(CMAKE_REQUIRED_INCLUDES)
ENDIF()
ENDIF()
IF(NOT HAVE_SYSTEM_LIBFMT OR WITH_LIBFMT STREQUAL "bundled")

IF (NOT HAVE_SYSTEM_LIBFMT OR WITH_LIBFMT STREQUAL "bundled")
IF (WITH_LIBFMT STREQUAL "system")
MESSAGE(FATAL_ERROR "system libfmt library is not found or unusable")
ENDIF()
Expand Down