Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
martingalvan-volue opened this issue Oct 31, 2024 · 1 comment
Open

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

martingalvan-volue opened this issue Oct 31, 2024 · 1 comment
Assignees
Labels
category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist

Comments

@martingalvan-volue
Copy link
Contributor

martingalvan-volue commented Oct 31, 2024

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 fmtlib/fmt#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?

@martingalvan-volue martingalvan-volue added the category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist label Oct 31, 2024
@Osyotr
Copy link
Contributor

Osyotr commented Oct 31, 2024

Create a custom triplet and add something like that:

if("${PORT}" STREQUAL "fmt")
    list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS "-DFMT_UNICODE=OFF")
endif()

https://learn.microsoft.com/en-us/vcpkg/users/triplets#vcpkg_cmake_configure_options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist
Projects
None yet
Development

No branches or pull requests

3 participants