microsoft / microsoft/vcpkg

[fmt] Add a way to disable FMT_UNICODE when building fmt

Open
#41,879 20 comments 0 reactions 1 assignee View on GitHub

@LilyWangLL is already working on this.

Since Oct 31, 2024.

category:question
Dominant language
CMake
Stars
27.5k
Forks
7.7k
Avg merge
2d 19h
Merged PRs (30d)
321

Description

Is your feature request related to a problem? Please describe.

Hi, I have a small test project built on Windows with MSVC, with fmt 11.0.2#1 installed through vcpkg.

My test project uses the /source-charset:windows-1252 compile option for its own sources:

cmake_minimum_required(VERSION 3.29.0 FATAL_ERROR)

set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE PATH "")

project(Test CXX)

find_package(fmt CONFIG REQUIRED)

add_executable(main
    main.cpp
)

target_compile_options(main PRIVATE
    /source-charset:windows-1252
)

target_link_libraries(main PRIVATE
    fmt::fmt
)

However, when try to build it I get the following error:

C:\PROGRA~1\MIB055~1\2022\PROFES~1\VC\Tools\MSVC\1441~1.341\bin\Hostx64\x64\cl.exe  /nologo /TP -DFMT_SHARED -external:IC:\Users\martin\fmt_test\build\vcpkg_installed\x64-windows\include -external:W0 /DWIN32 /D_WINDOWS /EHsc /Ob0 /Od /RTC1 -MDd -Zi /source-charset:windows-1252 /utf-8 /showIncludes /FoCMakeFiles\main.dir\main.cpp.obj /FdCMakeFiles\main.dir\ /FS -c C:\Users\martin\fmt_test\main.cpp
cl : Command line error D8016 : '/source-charset:windows-1252' and '/utf-8' command-line options are incompatible

I believe the reason for this is the /utf-8 option being set as PUBLIC for the fmt target, here:

https://github.com/fmtlib/fmt/blob/0c9fce2ffefecfdce794e1859584e25877b7b592/CMakeLists.txt#L362

which results on the following code being generated by vcpkg's CMake machinery (on fmt-targets.cmake):

set_target_properties(fmt::fmt PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "FMT_SHARED"
  INTERFACE_COMPILE_FEATURES "cxx_std_11"
  INTERFACE_COMPILE_OPTIONS "\$<\$<AND:\$<COMPILE_LANGUAGE:CXX>,\$<CXX_COMPILER_ID:MSVC>>:/utf-8>"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
)

I believe this ends up propagating the /utf-8 option to my own sources, and thus breaking the build.

Proposed solution

I reported this to fmt (see https://github.com/fmtlib/fmt/issues/4221) and the maintainer indicated that /utf-8 can be disabled through FMT_UNICODE, and it's an issue on the vcpkg side. Perhaps there could be done with a port feature?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.