diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 70260dd9..75f17a71 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -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}} \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 8426ab85..682bfc7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}" diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 00000000..2657ce53 --- /dev/null +++ b/GNUmakefile @@ -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 $(@) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cd7ba177..28d143d4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 () diff --git a/test/add-subdirectory-test/CMakeLists.txt b/test/add-subdirectory-test/CMakeLists.txt index 362b0494..a3a5ab14 100644 --- a/test/add-subdirectory-test/CMakeLists.txt +++ b/test/add-subdirectory-test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8...3.25) +cmake_minimum_required(VERSION 3.8...4.4) project(fmt-test CXX) diff --git a/test/compile-error-test/CMakeLists.txt b/test/compile-error-test/CMakeLists.txt index 5b57a2cf..24160dc3 100644 --- a/test/compile-error-test/CMakeLists.txt +++ b/test/compile-error-test/CMakeLists.txt @@ -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} diff --git a/test/find-package-test/CMakeLists.txt b/test/find-package-test/CMakeLists.txt index eb2ea25f..27171c72 100644 --- a/test/find-package-test/CMakeLists.txt +++ b/test/find-package-test/CMakeLists.txt @@ -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 () diff --git a/test/find-package-test/main.cc b/test/find-package-test/main.cc index 911e0e8d..c9e35f91 100644 --- a/test/find-package-test/main.cc +++ b/test/find-package-test/main.cc @@ -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]); diff --git a/test/module-test.cc b/test/module-test.cc index a7b67a4a..ffa24bd2 100644 --- a/test/module-test.cc +++ b/test/module-test.cc @@ -5,16 +5,22 @@ // // For the license information refer to format.h. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +// TODO(CK): not usable here! +#ifdef FMT_IMPORT_STD_ENABLED +import std; +#else +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + #include #if (__has_include() || 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", diff --git a/test/static-export-test/CMakeLists.txt b/test/static-export-test/CMakeLists.txt index 492194f9..ed12ab2a 100644 --- a/test/static-export-test/CMakeLists.txt +++ b/test/static-export-test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8...3.25) +cmake_minimum_required(VERSION 3.8...4.4) project(fmt-link CXX)