fix: [build]Fix build issue without format support
add C++20 <format> support checks in Unix libraries and update logging format usage. Log: Fix build issue without format support.
This commit is contained in:
parent
2016ce887b
commit
8226c4162b
3 changed files with 38 additions and 4 deletions
|
|
@ -89,6 +89,7 @@ macro(configure_unix_libs)
|
|||
include(CheckIncludeFileCXX)
|
||||
include(CheckSymbolExists)
|
||||
include(CheckCSourceCompiles)
|
||||
include(CheckCXXSourceCompiles)
|
||||
|
||||
check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
|
||||
if (NOT HAVE_SYS_SOCKET_H)
|
||||
|
|
@ -136,6 +137,23 @@ macro(configure_unix_libs)
|
|||
message(FATAL_ERROR "Missing library: pthread")
|
||||
endif()
|
||||
|
||||
# Check if <format> header is available
|
||||
check_cxx_source_compiles("
|
||||
#include <format>
|
||||
int main() {
|
||||
char buffer[100];
|
||||
std::format_to_n(buffer, 100, \"test {}\", 42);
|
||||
return 0;
|
||||
}
|
||||
" HAS_FORMAT)
|
||||
|
||||
# Display format support status
|
||||
if(HAS_FORMAT)
|
||||
message(STATUS "C++ <format> library support: YES")
|
||||
else()
|
||||
message(STATUS "C++ <format> library support: NO")
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
set(CMAKE_CXX_FLAGS "--sysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS} -DGTEST_USE_OWN_TR1_TUPLE=1")
|
||||
find_library(lib_ScreenSaver ScreenSaver)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#ifndef __APPLE__
|
||||
#if HAS_FORMAT
|
||||
#include <format>
|
||||
#endif
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ void makeTimeString(std::vector<char> &buffer)
|
|||
localtime_r(&t, &tm);
|
||||
#endif
|
||||
|
||||
#ifndef __APPLE__
|
||||
#if HAS_FORMAT
|
||||
std::format_to_n(
|
||||
buffer.data(), buffer.size(), "{:04}-{:02}-{:02}T{:02}:{:02}:{:02}", tm.tm_year + yearOffset,
|
||||
tm.tm_mon + monthOffset, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec
|
||||
|
|
@ -117,7 +117,7 @@ std::vector<char> makeMessage(const char *filename, int lineNumber, const char *
|
|||
bufferSize += filenameLength + lineNumberLength;
|
||||
|
||||
std::vector<char> buffer(bufferSize);
|
||||
#ifndef __APPLE__
|
||||
#if HAS_FORMAT
|
||||
std::format_to_n(
|
||||
buffer.data(), bufferSize, "[{}] {}: {}\n\t{}:{}", timeBuffer.data(), sectionName, message, filename, lineNumber
|
||||
);
|
||||
|
|
@ -129,7 +129,7 @@ std::vector<char> makeMessage(const char *filename, int lineNumber, const char *
|
|||
return buffer;
|
||||
} else {
|
||||
std::vector<char> buffer(bufferSize);
|
||||
#ifndef __APPLE__
|
||||
#if HAS_FORMAT
|
||||
std::format_to_n(buffer.data(), bufferSize, "[{}] {}: {}", timeBuffer.data(), sectionName, message);
|
||||
#else
|
||||
snprintf(buffer.data(), bufferSize, "[%s] %s: %s", timeBuffer.data(), sectionName, message);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,11 @@
|
|||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#if HAS_FORMAT
|
||||
#include <format>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
//
|
||||
|
|
@ -637,7 +641,11 @@ void XWindowsClipboard::motifFillCache()
|
|||
// get the Motif item property from the root window
|
||||
static const int buffer_size = 18 + 20;
|
||||
char name[buffer_size];
|
||||
#if HAS_FORMAT
|
||||
std::format_to_n(name, buffer_size, "_MOTIF_CLIP_ITEM_{}", header.m_item);
|
||||
#else
|
||||
snprintf(name, buffer_size, "_MOTIF_CLIP_ITEM_%d", header.m_item);
|
||||
#endif
|
||||
Atom atomItem = XInternAtom(m_display, name, False);
|
||||
data = "";
|
||||
if (!XWindowsUtil::getWindowProperty(m_display, root, atomItem, &data, &target, &format, False)) {
|
||||
|
|
@ -662,7 +670,11 @@ void XWindowsClipboard::motifFillCache()
|
|||
MotifFormatMap motifFormats;
|
||||
for (int32_t i = 0; i < numFormats; ++i) {
|
||||
// get Motif format property from the root window
|
||||
#if HAS_FORMAT
|
||||
std::format_to_n(name, buffer_size, "_MOTIF_CLIP_ITEM_{}", formats[i]);
|
||||
#else
|
||||
snprintf(name, buffer_size, "_MOTIF_CLIP_ITEM_%d", formats[i]);
|
||||
#endif
|
||||
Atom atomFormat = XInternAtom(m_display, name, False);
|
||||
std::string data;
|
||||
if (!XWindowsUtil::getWindowProperty(m_display, root, atomFormat, &data, &target, &format, False)) {
|
||||
|
|
@ -737,7 +749,11 @@ bool XWindowsClipboard::motifGetSelection(const MotifClipFormat *format, Atom *a
|
|||
// part that i don't know.
|
||||
static const int buffer_size = 18 + 20;
|
||||
char name[buffer_size];
|
||||
#if HAS_FORMAT
|
||||
std::format_to_n(name, buffer_size, "_MOTIF_CLIP_ITEM_{}", format->m_data);
|
||||
#else
|
||||
snprintf(name, buffer_size, "_MOTIF_CLIP_ITEM_%d", format->m_data);
|
||||
#endif
|
||||
Atom target = XInternAtom(m_display, name, False);
|
||||
Window root = RootWindow(m_display, DefaultScreen(m_display));
|
||||
return XWindowsUtil::getWindowProperty(m_display, root, target, data, actualTarget, nullptr, False);
|
||||
|
|
|
|||
Loading…
Reference in a new issue