From 398ddb8fec18eb4dfd1d0c8b1b8222afdb8b6307 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 1 Jan 2024 12:14:14 -0800 Subject: [PATCH] Don't include fmt/os.h in the module if it is disabled via FMT_OS --- CMakeLists.txt | 9 +++++---- src/fmt.cc | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b928ae3..43a00e68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,7 +150,7 @@ option(FMT_INSTALL "Generate the install target." ON) option(FMT_TEST "Generate the test target." ${FMT_MASTER_PROJECT}) option(FMT_FUZZ "Generate the fuzz target." OFF) option(FMT_CUDA_TEST "Generate the cuda-test target." OFF) -option(FMT_OS "Include core requiring OS (Windows/Posix) " ON) +option(FMT_OS "Include OS-specific APIs." ON) option(FMT_MODULE "Build a module instead of a traditional library." OFF) option(FMT_SYSTEM_HEADERS "Expose headers with marking them as system." OFF) @@ -278,9 +278,6 @@ add_headers(FMT_HEADERS args.h chrono.h color.h compile.h core.h format.h format-inl.h os.h ostream.h printf.h ranges.h std.h xchar.h) set(FMT_SOURCES src/format.cc) -if (FMT_OS) - set(FMT_SOURCES ${FMT_SOURCES} src/os.cc) -endif () add_module_library(fmt src/fmt.cc FALLBACK ${FMT_SOURCES} ${FMT_HEADERS} README.md ChangeLog.md @@ -289,6 +286,10 @@ add_library(fmt::fmt ALIAS fmt) if (FMT_MODULE) enable_module(fmt) endif () +if (FMT_OS) + target_sources(fmt PRIVATE src/os.cc) + target_compile_definitions(fmt PRIVATE FMT_OS=0) +endif () if (FMT_WERROR) target_compile_options(fmt PRIVATE ${WERROR_FLAG}) diff --git a/src/fmt.cc b/src/fmt.cc index 5330463a..aa971103 100644 --- a/src/fmt.cc +++ b/src/fmt.cc @@ -90,7 +90,9 @@ extern "C++" { #include "fmt/color.h" #include "fmt/compile.h" #include "fmt/format.h" -#include "fmt/os.h" +#if !defined(FMT_OS) || FMT_OS +# include "fmt/os.h" +#endif #include "fmt/printf.h" #include "fmt/std.h" #include "fmt/xchar.h"