-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
117 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
enable_language(CXX) | ||
|
||
option(XOJ_USE_FMTLIB "Use fmtlib" OFF) | ||
include(xoj_check_cxx_definition) | ||
xoj_check_cxx_definition("__cpp_lib_format >= 202110L" "format" _XOJ_HAS_INCLUDE_FORMAT) | ||
|
||
if(_XOJ_HAS_INCLUDE_FORMAT AND NOT XOJ_USE_FMTLIB) | ||
message(STATUS "Found <format>") | ||
set(FORMAT_LIB "std::format") | ||
else() | ||
message(STATUS "Could not find <format>, fetch {fmt}") | ||
include(get_cpm) | ||
CPMAddPackage("gh:fmtlib/fmt#7.1.3") | ||
set(FORMAT_LIB "{fmt}") | ||
endif() | ||
set(format_FOUND TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors | ||
|
||
set(CPM_DOWNLOAD_VERSION 0.39.0) | ||
set(CPM_HASH_SUM "66639bcac9dd2907b2918de466783554c1334446b9874e90d38e3778d404c2ef") | ||
|
||
if(CPM_SOURCE_CACHE) | ||
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") | ||
elseif(DEFINED ENV{CPM_SOURCE_CACHE}) | ||
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") | ||
else() | ||
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") | ||
endif() | ||
|
||
# Expand relative path. This is important if the provided path contains a tilde (~) | ||
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) | ||
|
||
file(DOWNLOAD | ||
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake | ||
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} | ||
) | ||
|
||
include(${CPM_DOWNLOAD_LOCATION}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Define the function | ||
function(xoj_check_cxx_definition definition header variable) | ||
set(BINARY_DIR ${CMAKE_BINARY_DIR}/xoj_check_cxx_definition) | ||
set(SOURCE_FILE ${CMAKE_BINARY_DIR}/xoj_check_cxx_definition/${variable}.cpp) | ||
file(WRITE ${SOURCE_FILE} "#include <${header}> \n#if !(${definition}) \n#error \n#endif\nint main(){}") | ||
try_compile(${variable} | ||
${BINARY_DIR} | ||
${SOURCE_FILE} | ||
CXX_STANDARD 20 | ||
CXX_STANDARD_REQUIRED TRUE | ||
OUTPUT_VARIABLE _OUT_ERROR | ||
) | ||
if(${variable}) | ||
message(STATUS "${header} defines ${definition}") | ||
else() | ||
message(STATUS "${header} does not define ${definition}") | ||
message(STATUS "${_OUT_ERROR}") | ||
endif() | ||
file(REMOVE ${SOURCE_FILE}) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
// define XOJ_USE_STD_FORMAT if std::format should be forced | ||
|
||
#if !defined(XOJ_USE_STD_FORMAT) && __has_include(<format>) | ||
#include <format> // IWYU pragma: export | ||
#if defined(__cpp_lib_format) && __cpp_lib_format >= 202110L | ||
#define XOJ_USE_STD_FORMAT = 1 | ||
#endif | ||
#endif | ||
|
||
#if !defined(XOJ_USE_STD_FORMAT) | ||
#include <fmt/format.h> // IWYU pragma: export | ||
#else // Include all the symbols from std::format into the fmt namespace | ||
namespace fmt { | ||
using std::basic_format_arg; | ||
using std::basic_format_args; | ||
using std::basic_format_context; | ||
using std::basic_format_parse_context; | ||
using std::basic_format_string; | ||
using std::format; | ||
using std::format_args; | ||
using std::format_context; | ||
using std::format_error; | ||
using std::format_parse_context; | ||
using std::format_string; | ||
using std::format_to; | ||
using std::format_to_n; | ||
using std::formatted_size; | ||
using std::formatter; | ||
using std::make_format_args; | ||
using std::make_wformat_args; | ||
using std::vformat; | ||
using std::vformat_to; | ||
using std::visit_format_arg; | ||
using std::wformat_args; | ||
using std::wformat_context; | ||
using std::wformat_parse_context; | ||
using std::wformat_string; | ||
} // namespace fmt | ||
#endif |