Prepare use of import std;

The fmt project use CXX and CC
This commit is contained in:
ClausKlein 2026-07-13 20:05:42 +02:00
parent a79df4504c
commit 09d5278d77
10 changed files with 111 additions and 23 deletions

View File

@ -177,7 +177,9 @@ jobs:
- name: Configure
working-directory: ${{runner.workspace}}/build
env:
CXX: ${{matrix.cxx}}
CXX: ${{ matrix.cxx }}
CC: ${{ startsWith(matrix.cxx, 'g++') && replace(matrix.cxx, 'g++', 'gcc') ||
replace(matrix.cxx, 'clang++', 'clang') }}
CXXFLAGS: ${{matrix.cxxflags}} ${{matrix.cxxflags_extra}}
run: |
cmake ${{matrix.gen && '-G' || ''}} ${{matrix.gen}} \

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8...3.28)
cmake_minimum_required(VERSION 3.8...4.4)
include_guard(GLOBAL)
# Fallback for using newer policies on CMake <3.12.
@ -48,7 +48,7 @@ if (FMT_MASTER_PROJECT AND NOT CMAKE_BUILD_TYPE)
"CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
endif ()
project(FMT CXX)
project(FMT LANGUAGES C CXX)
# Determine support for the C++ module scanning and CXX_MODULE File_Sets
# Requires C++20, CMake >= 3.28 and
@ -353,6 +353,12 @@ function (add_module_library name)
endif ()
endif ()
if (FMT_IMPORT_STD)
target_compile_features(${name} PUBLIC cxx_std_23)
target_compile_definitions(${name} PUBLIC FMT_IMPORT_STD)
set_target_properties(${name} PROPERTIES CXX_MODULE_STD 1)
endif ()
if (${AML_USE_CMAKE_MODULES})
target_sources(${name} PUBLIC FILE_SET fmt TYPE CXX_MODULES FILES
${sources})
@ -520,7 +526,8 @@ if (FMT_INSTALL)
EXPORT ${targets_export_name}
DESTINATION ${FMT_CMAKE_DIR}
NAMESPACE fmt::
COMPONENT fmt_core)
COMPONENT fmt_core
CXX_MODULES_DIRECTORY .)
install(
FILES "${pkgconfig}"

50
GNUmakefile Normal file
View File

@ -0,0 +1,50 @@
# Standard stuff
.SUFFIXES:
MAKEFLAGS+= --no-builtin-rules # Disable the built-in implicit rules.
MAKEFLAGS+= --warn-undefined-variables # Warn when an undefined variable is referenced.
export CC:=gcc-16
export CXX:=g++-16
export CXXFLAGS:=-stdlib=libstdc++
.PHONY: all test check clean format find-package-test
all: build
ninja -C build all # TODO: all_verify_interface_header_sets
build: GNUmakefile CMakeLists.txt
cmake --version # NOTE: v4.4 expected! CK
cmake -G Ninja -S . -B build --fresh \
-D CMAKE_SKIP_TEST_ALL_DEPENDENCY=NO \
-D FMT_MODULE=1 -D FMT_IMPORT_STD=1 -D CMAKE_CXX_STANDARD=23 \
-D CMAKE_EXPERIMENTAL_CXX_IMPORT_STD=f35a9ac6-8463-4d38-8eec-5d6008153e7d
ln -fs build/compile_commands.json .
find-package-test: install
cmake -G Ninja -S test/find-package-test -B build/find-package-build --fresh \
-D FMT_MODULE=1 -D FMT_IMPORT_STD=1 -D CMAKE_CXX_STANDARD=23 \
-D CMAKE_EXPERIMENTAL_CXX_IMPORT_STD=f35a9ac6-8463-4d38-8eec-5d6008153e7d
ninja -C build/find-package-build -v
ninja -C build/find-package-build -t deps CMakeFiles/module-test.dir/main.cc.o
./build/find-package-build/module-test build/find-package-build/*-test
clean:
rm -rf build .cache compile_commands.json
find . -name .DS_Store -delete
find . -name '*~' -delete
format:
git ls-files ::*CMakeLists.txt ::*.cmake | xargs cmake-format -i
check: build
run-clang-tidy src
test: build
ninja -C build $(@)
# Anything we don't know how to build will use this rule.
% ::
ninja -C build $(@)

View File

@ -26,6 +26,13 @@ function (add_fmt_test name)
add_executable(${name} ${sources})
target_link_libraries(${name} ${libs})
if (ADD_FMT_TEST_MODULE)
if (FMT_IMPORT_STD)
target_compile_features(${name} PRIVATE cxx_std_23)
set_target_properties(${name} PROPERTIES CXX_MODULE_STD 1)
endif ()
endif ()
if (ADD_FMT_TEST_HEADER_ONLY AND NOT FMT_UNICODE)
target_compile_definitions(${name} PUBLIC FMT_UNICODE=0)
endif ()

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8...3.25)
cmake_minimum_required(VERSION 3.8...4.4)
project(fmt-test CXX)

View File

@ -1,6 +1,6 @@
# Test if compile errors are produced where necessary.
cmake_minimum_required(VERSION 3.8...3.25)
cmake_minimum_required(VERSION 3.8...4.4)
project(compile-error-test CXX)
set(fmt_headers
@ -77,7 +77,7 @@ function (run_tests)
file(
WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/CMakeLists.txt"
"
cmake_minimum_required(VERSION 3.8...3.25)
cmake_minimum_required(VERSION 3.8...4.4)
project(tests CXX)
add_subdirectory(${FMT_DIR} fmt)
${cmake_targets}

View File

@ -1,9 +1,11 @@
cmake_minimum_required(VERSION 3.8...3.25)
cmake_minimum_required(VERSION 3.8...4.4)
project(fmt-test)
find_package(FMT REQUIRED)
set(PEDANTIC_COMPILE_FLAGS)
add_executable(library-test main.cc)
target_link_libraries(library-test fmt::fmt)
target_compile_options(library-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
@ -15,3 +17,14 @@ if (TARGET fmt::fmt-header-only)
target_compile_options(header-only-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
target_include_directories(header-only-test PUBLIC SYSTEM .)
endif ()
if (TARGET fmt::fmt-module)
add_executable(module-test main.cc)
target_link_libraries(module-test fmt::fmt-module)
target_compile_options(module-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
if (FMT_IMPORT_STD)
target_compile_features(module-test PRIVATE cxx_std_23)
set_target_properties(module-test PROPERTIES CXX_MODULE_STD 1)
endif ()
target_include_directories(module-test PUBLIC SYSTEM .)
endif ()

View File

@ -1,4 +1,9 @@
#include "fmt/format.h"
#ifdef FMT_IMPORT_STD
import std;
import fmt;
#else
# include "fmt/format.h"
#endif
int main(int argc, char** argv) {
for (int i = 0; i < argc; ++i) fmt::print("{}: {}\n", i, argv[i]);

View File

@ -5,16 +5,22 @@
//
// For the license information refer to format.h.
#include <bit>
#include <chrono>
#include <exception>
#include <iterator>
#include <locale>
#include <memory>
#include <ostream>
#include <string>
#include <string_view>
#include <system_error>
// TODO(CK): not usable here!
#ifdef FMT_IMPORT_STD_ENABLED
import std;
#else
# include <bit>
# include <chrono>
# include <exception>
# include <iterator>
# include <locale>
# include <memory>
# include <ostream>
# include <string>
# include <string_view>
# include <system_error>
#endif
#include <gmock/gmock.h>
#if (__has_include(<fcntl.h>) || defined(__APPLE__) || \
@ -312,9 +318,7 @@ TEST(module_test, fprintf) {
EXPECT_WRITE(stderr, fmt::fprintf(stderr, "%d", 42), "42");
}
TEST(module_test, sprintf) {
EXPECT_EQ("42", fmt::sprintf("%d", 42));
}
TEST(module_test, sprintf) { EXPECT_EQ("42", fmt::sprintf("%d", 42)); }
TEST(module_test, color) {
EXPECT_EQ("\x1B[30m42\x1B[0m",

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8...3.25)
cmake_minimum_required(VERSION 3.8...4.4)
project(fmt-link CXX)