mirror of
https://github.com/fmtlib/fmt.git
synced 2026-09-13 14:22:26 +08:00
Stop enabling C++26 reflection by default
Don't inject -freflection when building the module, so it isn't forced onto the module or its importers. Build enum-test unconditionally (it is a no-op without reflection) and drop the now-unneeded reflection detection. Enable reflection explicitly in the g++-16 C++26 CI job.
This commit is contained in:
parent
9375eb3792
commit
bb1bcede25
1
.github/workflows/linux.yml
vendored
1
.github/workflows/linux.yml
vendored
@ -50,6 +50,7 @@ jobs:
|
|||||||
build_type: Debug
|
build_type: Debug
|
||||||
std: 26
|
std: 26
|
||||||
os: ubuntu-24.04
|
os: ubuntu-24.04
|
||||||
|
cxxflags: -freflection
|
||||||
install: sudo apt install g++-16
|
install: sudo apt install g++-16
|
||||||
- cxx: clang++-3.6
|
- cxx: clang++-3.6
|
||||||
- cxx: clang++-11
|
- cxx: clang++-11
|
||||||
|
|||||||
@ -409,41 +409,9 @@ function (add_module_library name)
|
|||||||
target_sources(${name} PRIVATE ${sources})
|
target_sources(${name} PRIVATE ${sources})
|
||||||
endfunction ()
|
endfunction ()
|
||||||
|
|
||||||
# Code that compiles only if C++26 reflection, required by fmt/enum.h, is
|
|
||||||
# available. Also used by test/CMakeLists.txt.
|
|
||||||
set(FMT_REFLECTION_TEST_CODE
|
|
||||||
"
|
|
||||||
#include <fmt/enum.h>
|
|
||||||
enum class [[=fmt::as_identifiers]] color { red };
|
|
||||||
static_assert(fmt::is_formattable<color>::value, \"\");
|
|
||||||
int main() {}
|
|
||||||
")
|
|
||||||
|
|
||||||
if (FMT_MODULE)
|
if (FMT_MODULE)
|
||||||
# Unlike with headers, whether fmt/enum.h provides anything is decided when
|
|
||||||
# the module is compiled, so detect reflection with the configured standard
|
|
||||||
# and enable it if possible. Reflection needs C++26 and, in some compilers
|
|
||||||
# such as GCC, an extra flag.
|
|
||||||
if (NOT MSVC AND CMAKE_CXX_STANDARD GREATER_EQUAL 26)
|
|
||||||
include(CheckCXXSourceCompiles)
|
|
||||||
set(CMAKE_REQUIRED_INCLUDES ${PROJECT_SOURCE_DIR}/include)
|
|
||||||
check_cxx_source_compiles("${FMT_REFLECTION_TEST_CODE}"
|
|
||||||
FMT_MODULE_HAVE_REFLECTION)
|
|
||||||
if (NOT FMT_MODULE_HAVE_REFLECTION)
|
|
||||||
set(CMAKE_REQUIRED_FLAGS -freflection)
|
|
||||||
check_cxx_source_compiles("${FMT_REFLECTION_TEST_CODE}"
|
|
||||||
FMT_MODULE_HAVE_REFLECTION_FLAG)
|
|
||||||
unset(CMAKE_REQUIRED_FLAGS)
|
|
||||||
endif ()
|
|
||||||
unset(CMAKE_REQUIRED_INCLUDES)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
add_module_library(fmt-module src/fmt.cc USE_CMAKE_MODULES
|
add_module_library(fmt-module src/fmt.cc USE_CMAKE_MODULES
|
||||||
${FMT_USE_CMAKE_MODULES})
|
${FMT_USE_CMAKE_MODULES})
|
||||||
if (FMT_MODULE_HAVE_REFLECTION_FLAG)
|
|
||||||
# PUBLIC because importers need the flag to use annotations.
|
|
||||||
target_compile_options(fmt-module PUBLIC -freflection)
|
|
||||||
endif ()
|
|
||||||
setup_target(fmt-module PUBLIC)
|
setup_target(fmt-module PUBLIC)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
|||||||
@ -45,6 +45,7 @@ add_fmt_test(base-test)
|
|||||||
add_fmt_test(assert-test)
|
add_fmt_test(assert-test)
|
||||||
add_fmt_test(chrono-test)
|
add_fmt_test(chrono-test)
|
||||||
add_fmt_test(color-test)
|
add_fmt_test(color-test)
|
||||||
|
add_fmt_test(enum-test)
|
||||||
add_fmt_test(gtest-extra-test)
|
add_fmt_test(gtest-extra-test)
|
||||||
add_fmt_test(format-test mock-allocator.h)
|
add_fmt_test(format-test mock-allocator.h)
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
@ -77,36 +78,6 @@ add_fmt_test(enforce-checks-test)
|
|||||||
target_compile_definitions(enforce-checks-test
|
target_compile_definitions(enforce-checks-test
|
||||||
PRIVATE -DFMT_ENFORCE_COMPILE_STRING)
|
PRIVATE -DFMT_ENFORCE_COMPILE_STRING)
|
||||||
|
|
||||||
# Enum formatting requires C++26 reflection, which needs compiler support and,
|
|
||||||
# in some compilers such as GCC, an extra flag to enable it.
|
|
||||||
if (NOT MSVC)
|
|
||||||
include(CheckCXXSourceCompiles)
|
|
||||||
set(CMAKE_REQUIRED_INCLUDES ${PROJECT_SOURCE_DIR}/include)
|
|
||||||
set(CMAKE_REQUIRED_FLAGS "-std=c++26")
|
|
||||||
check_cxx_source_compiles("${FMT_REFLECTION_TEST_CODE}" FMT_HAVE_REFLECTION)
|
|
||||||
if (NOT FMT_HAVE_REFLECTION)
|
|
||||||
set(CMAKE_REQUIRED_FLAGS "-std=c++26 -freflection")
|
|
||||||
check_cxx_source_compiles("${FMT_REFLECTION_TEST_CODE}"
|
|
||||||
FMT_HAVE_REFLECTION_FLAG)
|
|
||||||
endif ()
|
|
||||||
unset(CMAKE_REQUIRED_FLAGS)
|
|
||||||
unset(CMAKE_REQUIRED_INCLUDES)
|
|
||||||
|
|
||||||
if (FMT_HAVE_REFLECTION OR FMT_HAVE_REFLECTION_FLAG)
|
|
||||||
add_fmt_test(enum-test)
|
|
||||||
set_target_properties(
|
|
||||||
enum-test
|
|
||||||
PROPERTIES CXX_STANDARD 26
|
|
||||||
CXX_STANDARD_REQUIRED ON
|
|
||||||
CXX_EXTENSIONS OFF)
|
|
||||||
if (FMT_HAVE_REFLECTION_FLAG)
|
|
||||||
target_compile_options(enum-test PRIVATE -freflection)
|
|
||||||
endif ()
|
|
||||||
else ()
|
|
||||||
message(STATUS "Reflection is not supported, skipping enum-test.")
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
add_executable(perf-sanity perf-sanity.cc)
|
add_executable(perf-sanity perf-sanity.cc)
|
||||||
target_link_libraries(perf-sanity fmt::fmt)
|
target_link_libraries(perf-sanity fmt::fmt)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user