Skip to content

Commit dcf91b3

Browse files
committed
remove std + fmt
1 parent 2bfd2ca commit dcf91b3

6 files changed

Lines changed: 14 additions & 12 deletions

File tree

.github/workflows/install.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
repository: fmtlib/fmt
6868
path: fmt-src
6969

70-
- name: Install toolchain
70+
- name: Install toolchain and fmt
7171
run: |
7272
brew install gcc ninja
7373
python3 -m pip install cmake==4.4.0 --break-system-packages
@@ -76,6 +76,7 @@ jobs:
7676
-DCMAKE_CXX_COMPILER="${CXX}" \
7777
-DCMAKE_CXX_STANDARD=20 \
7878
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
79+
-DCMAKE_CXX_SCAN_FOR_MODULES=OFF \
7980
-DCMAKE_INSTALL_PREFIX="${RUNNER_TEMP}/fmt" \
8081
-DBUILD_SHARED_LIBS=OFF \
8182
-DFMT_DOC=OFF \

.github/workflows/ubuntu.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,9 @@ jobs:
117117
if: ${{ matrix.compiler.import_std == 'TRUE' }}
118118
run: |
119119
cxx_standard=23
120-
fmt_integration=OFF
121120
stdlib_options=(-DCMAKE_CXX_FLAGS:STRING=-stdlib=libc++)
122121
if [[ "${{ matrix.compiler.cc }}" == gcc-* ]]; then
123122
cxx_standard=26
124-
fmt_integration=ON
125123
stdlib_options=(-DCMAKE_CXX_STDLIB_MODULES_JSON="$("${CXX}" -print-file-name=libstdc++.modules.json)")
126124
fi
127125
@@ -133,7 +131,7 @@ jobs:
133131
-DCMAKE_CXX_EXTENSIONS=OFF \
134132
-DMAGIC_ENUM_USE_MODULES:BOOL=TRUE \
135133
-DMAGIC_ENUM_MODULE_IMPORT_STD:BOOL=TRUE \
136-
-DMAGIC_ENUM_MODULE_WITH_FMT:BOOL="${fmt_integration}" \
134+
-DMAGIC_ENUM_MODULE_WITH_FMT:BOOL=FALSE \
137135
-GNinja \
138136
"${stdlib_options[@]}"
139137

CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@ unset(MAGIC_ENUM_VERIFY_INTERFACE_HEADER_SETS_DEFAULT)
3939
option(MAGIC_ENUM_USE_MODULES "Build the magic_enum C++20 module target" OFF)
4040
option(MAGIC_ENUM_MODULE_IMPORT_STD "Build the module target with import std" OFF)
4141
set(MAGIC_ENUM_MODULE_WITH_FMT_DEFAULT OFF)
42-
if(MAGIC_ENUM_USE_MODULES AND (TARGET fmt::fmt-module OR TARGET fmt::fmt))
42+
if(MAGIC_ENUM_USE_MODULES AND NOT MAGIC_ENUM_MODULE_IMPORT_STD AND (TARGET fmt::fmt-module OR TARGET fmt::fmt))
4343
set(MAGIC_ENUM_MODULE_WITH_FMT_DEFAULT ON)
4444
endif()
4545
option(MAGIC_ENUM_MODULE_WITH_FMT "Build the module target with fmt integration" ${MAGIC_ENUM_MODULE_WITH_FMT_DEFAULT})
4646
unset(MAGIC_ENUM_MODULE_WITH_FMT_DEFAULT)
4747
option(MAGIC_ENUM_OPT_INSTALL_PACKAGE_XML "Include package.xml when installing" ${MAGIC_ENUM_OPT_INSTALL})
4848

49+
if(MAGIC_ENUM_MODULE_IMPORT_STD AND MAGIC_ENUM_MODULE_WITH_FMT)
50+
message(FATAL_ERROR "MAGIC_ENUM_MODULE_IMPORT_STD and MAGIC_ENUM_MODULE_WITH_FMT cannot be enabled together; use std::format with import std")
51+
endif()
4952
if(MAGIC_ENUM_MODULE_IMPORT_STD AND NOT MAGIC_ENUM_USE_MODULES)
5053
message(FATAL_ERROR "MAGIC_ENUM_MODULE_IMPORT_STD requires MAGIC_ENUM_USE_MODULES=ON")
5154
endif()
@@ -159,17 +162,18 @@ function(magic_enum_make_module_library name)
159162
)
160163
target_link_libraries(${name} PUBLIC ${PROJECT_NAME})
161164
target_compile_features(${name} PUBLIC cxx_std_${MAGIC_ENUM_MODULE_CXX_STANDARD})
162-
if(ARGN)
165+
if(ARGC GREATER 1)
163166
# Optional private definitions build test variants with custom magic_enum configurations.
164167
target_compile_definitions(${name} PRIVATE ${ARGN})
165168
endif()
166169

167170
# Module-only definitions stay private; CMake exports them for installed module sources without propagating them to importers.
168171
if(MAGIC_ENUM_MODULE_FMT_TARGET)
169172
target_link_libraries(${name} PUBLIC ${MAGIC_ENUM_MODULE_FMT_TARGET})
170-
target_compile_definitions(${name} PRIVATE MAGIC_ENUM_MODULE_WITH_FMT)
171173
if(MAGIC_ENUM_MODULE_USES_FMT_MODULE)
172174
target_compile_definitions(${name} PRIVATE MAGIC_ENUM_USE_FMT_MODULE)
175+
else()
176+
target_compile_definitions(${name} PRIVATE MAGIC_ENUM_USE_FMT_HEADER)
173177
endif()
174178
endif()
175179

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ Header-only C++17 library provides static reflection for enums, work with any en
362362
Do not use `#include <magic_enum/...>` and `import magic_enum;` in the same program. Use the same compiler, standard library, and C++ standard when building and consuming an installed module. The pkg-config package supports only the header-only target.
363363
364364
Optional settings:
365-
- `{fmt}` support is enabled automatically when `fmt::fmt-module` or `fmt::fmt` already exists. The module target is preferred when it uses the same C++ standard. Set `MAGIC_ENUM_MODULE_WITH_FMT=ON` to require `{fmt}`, or `OFF` to disable it.
366-
- Set `MAGIC_ENUM_MODULE_IMPORT_STD=ON` to enable experimental `import std` support. This requires a compatible CMake toolchain.
365+
- `{fmt}` support is enabled automatically when `fmt::fmt-module` or `fmt::fmt` already exists and `import std` is disabled. The module target is preferred when it uses the same C++ standard. Set `MAGIC_ENUM_MODULE_WITH_FMT=ON` to require `{fmt}`, or `OFF` to disable it.
366+
- Set `MAGIC_ENUM_MODULE_IMPORT_STD=ON` to enable experimental `import std` support. Use `std::format` in this mode. `{fmt}` integration cannot be enabled. This requires a compatible CMake toolchain.
367367
368368
## Header-only compiler compatibility
369369

module/magic_enum.cppm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module;
22

33
#include <version>
4-
#if defined(MAGIC_ENUM_MODULE_WITH_FMT) && !defined(MAGIC_ENUM_USE_FMT_MODULE)
4+
#ifdef MAGIC_ENUM_USE_FMT_HEADER
55
# include <fmt/format.h>
66
#endif
77

@@ -203,7 +203,7 @@ namespace detail {
203203
#endif
204204
}
205205

206-
#if defined(MAGIC_ENUM_MODULE_WITH_FMT) && !defined(MAGIC_ENUM_USE_FMT_MODULE)
206+
#ifdef MAGIC_ENUM_USE_FMT_HEADER
207207
export namespace fmt {
208208
using fmt::formatter;
209209
}

test/installed_module/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include <version>
55

6-
// Include fmt before import std to avoid duplicate standard-library declarations with GCC modules.
76
#if defined(MAGIC_ENUM_TEST_FMT) && !defined(MAGIC_ENUM_TEST_FMT_MODULE)
87
# include <fmt/format.h>
98
#endif

0 commit comments

Comments
 (0)