Don't include fmt/os.h in the module if it is disabled via FMT_OS

This commit is contained in:
Victor Zverovich 2024-01-01 12:14:14 -08:00
parent 583729493c
commit 398ddb8fec
2 changed files with 8 additions and 5 deletions

View File

@ -150,7 +150,7 @@ option(FMT_INSTALL "Generate the install target." ON)
option(FMT_TEST "Generate the test target." ${FMT_MASTER_PROJECT}) option(FMT_TEST "Generate the test target." ${FMT_MASTER_PROJECT})
option(FMT_FUZZ "Generate the fuzz target." OFF) option(FMT_FUZZ "Generate the fuzz target." OFF)
option(FMT_CUDA_TEST "Generate the cuda-test 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_MODULE "Build a module instead of a traditional library." OFF)
option(FMT_SYSTEM_HEADERS "Expose headers with marking them as system." 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 format-inl.h os.h ostream.h printf.h ranges.h std.h
xchar.h) xchar.h)
set(FMT_SOURCES src/format.cc) 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 add_module_library(fmt src/fmt.cc FALLBACK
${FMT_SOURCES} ${FMT_HEADERS} README.md ChangeLog.md ${FMT_SOURCES} ${FMT_HEADERS} README.md ChangeLog.md
@ -289,6 +286,10 @@ add_library(fmt::fmt ALIAS fmt)
if (FMT_MODULE) if (FMT_MODULE)
enable_module(fmt) enable_module(fmt)
endif () endif ()
if (FMT_OS)
target_sources(fmt PRIVATE src/os.cc)
target_compile_definitions(fmt PRIVATE FMT_OS=0)
endif ()
if (FMT_WERROR) if (FMT_WERROR)
target_compile_options(fmt PRIVATE ${WERROR_FLAG}) target_compile_options(fmt PRIVATE ${WERROR_FLAG})

View File

@ -90,7 +90,9 @@ extern "C++" {
#include "fmt/color.h" #include "fmt/color.h"
#include "fmt/compile.h" #include "fmt/compile.h"
#include "fmt/format.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/printf.h"
#include "fmt/std.h" #include "fmt/std.h"
#include "fmt/xchar.h" #include "fmt/xchar.h"