Skip to content

Commit

Permalink
Prevent build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausKlein committed Dec 27, 2024
1 parent 5ec55c2 commit ba232da
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 117 deletions.
42 changes: 22 additions & 20 deletions .cmakefiles.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
./CMakeLists.txt
./CMakePresets.json
./cmake/AddUninstallTarget.cmake
./cmake/CPM.cmake
./cmake/coverage.cmake
./cmake/dev-mode.cmake
./cmake/docs-ci.cmake
./cmake/docs.cmake
./cmake/folders.cmake
./cmake/install-config.cmake
./cmake/install-rules.cmake
./cmake/lint-targets.cmake
./cmake/lint.cmake
./cmake/prelude.cmake
./cmake/spell-targets.cmake
./cmake/spell.cmake
./cmake/variables.cmake
./cmake/windows-set-path.cmake
./module/tests/CMakeLists.txt
./tests/CMakeLists.txt
.CMakeUserPresets.json
.github/workflows/cmake.yml
CMakeLists.txt
CMakePresets.json
cmake/AddUninstallTarget.cmake
cmake/CPM.cmake
cmake/coverage.cmake
cmake/dev-mode.cmake
cmake/docs-ci.cmake
cmake/docs.cmake
cmake/folders.cmake
cmake/install-config.cmake
cmake/install-rules.cmake
cmake/lint-targets.cmake
cmake/lint.cmake
cmake/prelude.cmake
cmake/spell-targets.cmake
cmake/spell.cmake
cmake/variables.cmake
cmake/windows-set-path.cmake
module/tests/CMakeLists.txt
tests/CMakeLists.txt
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ CMakeUserPresets.json
tags
*.swp
*.bak
module/format.cc
module/os.cc
18 changes: 10 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ project(fmt

include(cmake/variables.cmake)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_DEBUG_POSTFIX D)
set(CPPdefinitions)

option(FMT_SEPARATE_COMPILATION "build fmt lib too" ${PROJECT_IS_TOP_LEVEL})
option(FMT_USE_MODULES "Export a CXX_MODULE fmt if possible" ${PROJECT_IS_TOP_LEVEL})
option(FMT_IMPORT_STD "Import the all std header needed" NO)

if(FMT_IMPORT_STD)
if(FMT_IMPORT_STD AND NOT FMT_USE_MODULES)
list(APPEND CPPdefinitions FMT_IMPORT_STD)
endif()

if(FMT_USE_MODULES)
list(APPEND CPPdefinitions FMT_MODULE)
# XXX NO! list(APPEND CPPdefinitions FMT_ATTACH_TO_GLOBAL_MODULE)
# FIXME: add_compile_options(-Wno-reserved-module-identifier -Wno-include-angled-in-module-purview)
# TODO: add_compile_options(-Wno-reserved-module-identifier -Wno-include-angled-in-module-purview)

if(FMT_IMPORT_STD) # FIXME: clang++ only! AND $ENV{LLVM_ROOT})
if(UNIX)
Expand Down Expand Up @@ -61,12 +63,12 @@ cpmaddpackage(
# ---- Declare library ----

# TODO: only if needed (compare) and possible!
if(EXISTS ${fmt_SOURCE_DIR}/src/fmt.cc AND NOT EXISTS ${PROJECT_SOURCE_DIR}/module/fmt.cppm)
configure_file(${fmt_SOURCE_DIR}/src/fmt.cc ${PROJECT_SOURCE_DIR}/module/fmt.cppm COPYONLY)
if(EXISTS ${fmt_SOURCE_DIR}/src/fmt.cc AND NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/module/fmt.cppm)
configure_file(${fmt_SOURCE_DIR}/src/fmt.cc ${CMAKE_CURRENT_SOURCE_DIR}/module/fmt.cppm COPYONLY)
endif()

configure_file(${fmt_SOURCE_DIR}/src/format.cc ${PROJECT_SOURCE_DIR}/module/format.cc COPYONLY)
configure_file(${fmt_SOURCE_DIR}/src/os.cc ${PROJECT_SOURCE_DIR}/module/os.cc COPYONLY)
configure_file(${fmt_SOURCE_DIR}/src/format.cc ${CMAKE_CURRENT_SOURCE_DIR}/module/format.cc COPYONLY)
configure_file(${fmt_SOURCE_DIR}/src/os.cc ${CMAKE_CURRENT_SOURCE_DIR}/module/os.cc COPYONLY)
file(GLOB_RECURSE _fmt_all_sources "module/*.cc")

# fmt interface library
Expand Down Expand Up @@ -109,9 +111,9 @@ if(FMT_SEPARATE_COMPILATION)
FILE_SET public_modules
TYPE CXX_MODULES
BASE_DIRS
${PROJECT_SOURCE_DIR}/module
${CMAKE_CURRENT_SOURCE_DIR}/module
FILES
${PROJECT_SOURCE_DIR}/module/fmt.cppm
${CMAKE_CURRENT_SOURCE_DIR}/module/fmt.cppm
)
# cmake-format: on
else()
Expand Down
7 changes: 4 additions & 3 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.40.2)
set(CPM_HASH_SUM "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d")
set(CPM_DOWNLOAD_VERSION 0.40.4)
set(CPM_HASH_SUM "67dcc1deb6e12a2f0705647ccc5f7023e3d15746b944e14352b82373e09b8a0a")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
Expand All @@ -16,7 +16,8 @@ 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
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}
)

Expand Down
162 changes: 76 additions & 86 deletions module/fmt.cppm
Original file line number Diff line number Diff line change
@@ -1,105 +1,97 @@
#ifdef FMT_MODULE
module;
#endif

#ifdef _MSVC_LANG
# define FMT_CPLUSPLUS _MSVC_LANG
#else
# define FMT_CPLUSPLUS __cplusplus
#endif

#ifndef FMT_IMPORT_STD_MODULE

// Put all implementation-provided headers into the global module fragment
// to prevent attachment to this module.
# ifndef FMT_IMPORT_STD
# include <algorithm>
# include <bitset>
# include <chrono>
# include <cmath>
# include <complex>
# include <cstddef>
# include <cstdint>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <ctime>
# include <exception>
# if FMT_CPLUSPLUS > 202002L
# include <expected>
# endif
# include <filesystem>
# include <fstream>
# include <functional>
# include <iterator>
# include <limits>
# include <locale>
# include <memory>
# include <optional>
# include <ostream>
# include <source_location>
# include <stdexcept>
# include <string>
# include <string_view>
# include <system_error>
# include <thread>
# include <type_traits>
# include <typeinfo>
# include <utility>
# include <variant>
# include <vector>
# else
# include <limits.h>
# include <stdint.h>
# include <stdio.h>
# include <time.h>
# endif // FMT_IMPORT_STD

# include <cerrno>
# include <climits>
# include <version>

# if __has_include(<cxxabi.h>)
# include <cxxabi.h>
# endif
# if defined(_MSC_VER) || defined(__MINGW32__)
# include <intrin.h>
#ifndef FMT_IMPORT_STD
# include <algorithm>
# include <bitset>
# include <chrono>
# include <cmath>
# include <complex>
# include <cstddef>
# include <cstdint>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <ctime>
# include <exception>
# if FMT_CPLUSPLUS > 202002L
# include <expected>
# endif
# if defined __APPLE__ || defined(__FreeBSD__)
# include <xlocale.h>
# endif
# if __has_include(<winapifamily.h>)
# include <winapifamily.h>
# endif
# if (__has_include(<fcntl.h>) || defined(__APPLE__) || \
# include <filesystem>
# include <fstream>
# include <functional>
# include <iterator>
# include <limits>
# include <locale>
# include <memory>
# include <optional>
# include <ostream>
# include <source_location>
# include <stdexcept>
# include <string>
# include <string_view>
# include <system_error>
# include <thread>
# include <type_traits>
# include <typeinfo>
# include <utility>
# include <variant>
# include <vector>
#else
# include <limits.h>
# include <stdint.h>
# include <stdio.h>
# include <time.h>
#endif
#include <cerrno>
#include <climits>
#include <version>

#if __has_include(<cxxabi.h>)
# include <cxxabi.h>
#endif
#if defined(_MSC_VER) || defined(__MINGW32__)
# include <intrin.h>
#endif
#if defined __APPLE__ || defined(__FreeBSD__)
# include <xlocale.h>
#endif
#if __has_include(<winapifamily.h>)
# include <winapifamily.h>
#endif
#if (__has_include(<fcntl.h>) || defined(__APPLE__) || \
defined(__linux__)) && \
(!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
# include <fcntl.h>
# include <sys/stat.h>
# include <sys/types.h>
# ifndef _WIN32
# include <unistd.h>
# else
# include <io.h>
# endif
# include <fcntl.h>
# include <sys/stat.h>
# include <sys/types.h>
# ifndef _WIN32
# include <unistd.h>
# else
# include <io.h>
# endif
# ifdef _WIN32
# if defined(__GLIBCXX__)
# include <ext/stdio_filebuf.h>
# include <ext/stdio_sync_filebuf.h>
# endif
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
#ifdef _WIN32
# if defined(__GLIBCXX__)
# include <ext/stdio_filebuf.h>
# include <ext/stdio_sync_filebuf.h>
# endif
#endif // FMT_IMPORT_STD_MODULE
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif

#ifdef FMT_MODULE
export module fmt;

# ifdef FMT_IMPORT_STD_MODULE
#ifdef FMT_IMPORT_STD
import std;
# endif
#endif // FMT_MODULE
#endif

#define FMT_EXPORT export
#define FMT_BEGIN_EXPORT export {
Expand Down Expand Up @@ -138,11 +130,9 @@ extern "C++" {
}
#endif

#ifdef FMT_MODULE
// gcc doesn't yet implement private module fragments
# if !FMT_GCC_VERSION
#if !FMT_GCC_VERSION
module :private;
# endif
#endif

#ifdef FMT_ATTACH_TO_GLOBAL_MODULE
Expand Down

0 comments on commit ba232da

Please sign in to comment.