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

Windows: force UTF-8 code page for app and samples #2951

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
set(APP_SOURCES
exiv2.cpp
exiv2app.hpp
actions.cpp
actions.hpp
getopt.cpp
getopt.hpp
app_utils.cpp
app_utils.hpp
)

add_executable(exiv2 ${APP_SOURCES})

# Make app use UTF-8 code page in Windows
if(WIN32)
if(MSVC)
target_sources(exiv2 PRIVATE utf8.manifest)
else()
# Must wrap manifest in .rc w/ other toolchains
target_sources(exiv2 PRIVATE utf8.rc)
endif()
endif()

target_include_directories(exiv2 PRIVATE ${PROJECT_SOURCE_DIR}/src) # To find i18n.hpp

set_target_properties(exiv2 PROPERTIES COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS} XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS[variant=Debug] "YES")
Expand All @@ -27,24 +33,6 @@ endif()

target_link_libraries(exiv2 PRIVATE std::filesystem)

if(MSVC OR MINGW)
# Trick to get properly UTF-8 encoded argv.

# More info at: https://github.com/huangqinjin/wmain
add_library(wmain STATIC wmain.cpp)
target_link_libraries(exiv2 PRIVATE wmain)
endif()

if(MSVC)
target_link_options(wmain INTERFACE /WHOLEARCHIVE:$<TARGET_FILE:wmain>)
target_link_options(exiv2 PRIVATE "/ENTRY:wWinMainCRTStartup")
endif()

if(MINGW)
target_compile_options(exiv2 PRIVATE -municode)
target_link_options(exiv2 PRIVATE -municode)
endif()

if(USING_CONAN
AND WIN32
AND EXISTS ${PROJECT_BINARY_DIR}/conanDlls
Expand Down
2 changes: 0 additions & 2 deletions app/exiv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ std::string parseEscapes(const std::string& input);
// *****************************************************************************
// Main
int main(int argc, char* const argv[]) {
setlocale(LC_CTYPE, ".utf8");

Exiv2::XmpParser::initialize();
::atexit(Exiv2::XmpParser::terminate);

Expand Down
8 changes: 8 additions & 0 deletions app/utf8.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<application>
<windowsSettings>
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
</windowsSettings>
</application>
</assembly>
3 changes: 3 additions & 0 deletions app/utf8.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <winuser.rh>

CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "utf8.manifest"
40 changes: 0 additions & 40 deletions app/wmain.cpp

This file was deleted.

8 changes: 8 additions & 0 deletions cmake/mainSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

include(GNUInstallDirs)
include(CheckFunctionExists)
include(CheckCXXSymbolExists)
include(GenerateExportHeader)
include(CMakeDependentOption)
include(cmake/JoinPaths.cmake)
Expand Down Expand Up @@ -31,6 +32,13 @@ if (UNIX)
endif()
endif()

if(MINGW)
check_cxx_symbol_exists(_UCRT "ctime" USES_UCRT)
if(NOT USES_UCRT)
message(FATAL_ERROR "Non UCRT MinGW is unsupported. Please update toolchain")
endif()
endif()

# Prevent conflicts when exiv2 is consumed in multiple-subdirectory projects.
if (NOT TARGET uninstall)
configure_file(cmake/exiv2_uninstall.cmake ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake COPYONLY)
Expand Down
6 changes: 5 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ exiv2_sources = files(
'app/app_utils.cpp',
'app/exiv2.cpp',
'app/getopt.cpp',
host_machine.system() == 'windows' ? 'app/wmain.cpp' : [],
)

if host_machine.system() == 'windows'
windows = import('windows')
exiv2_sources += windows.compile_resources('app/utf8.rc', depend_files: 'app/utf8.manifest')
endif

exiv2inc = include_directories('src', 'include/exiv2')
executable(
'exiv2',
Expand Down
18 changes: 9 additions & 9 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@ list(APPEND APPLICATIONS remotetest)

# ******************************************************************************
foreach(application ${APPLICATIONS})
target_link_libraries(${application} PRIVATE exiv2lib std::filesystem)
if(MSVC)
target_link_libraries(${application} PRIVATE wmain)
target_link_options(${application} PRIVATE "/ENTRY:wWinMainCRTStartup")
endif()
if(MINGW)
target_link_libraries(${application} PRIVATE wmain)
target_compile_options(${application} PRIVATE -municode)
target_link_options(${application} PRIVATE -municode)
# Make app use UTF-8 code page in Windows
if(WIN32)
if(MSVC)
target_sources(${application} PRIVATE ${PROJECT_SOURCE_DIR}/app/utf8.manifest)
else()
# Must wrap manifest in .rc w/ other toolchains
target_sources(${application} PRIVATE ${PROJECT_SOURCE_DIR}/app/utf8.rc)
endif()
endif()
target_link_libraries(${application} PRIVATE exiv2lib std::filesystem)
if(EXIV2_ENABLE_PNG)
target_link_libraries(${application} PRIVATE ${ZLIB_LIBRARIES})
if(MSVC)
Expand Down
1 change: 0 additions & 1 deletion samples/exifprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ static const Exiv2::TagInfo* findTag(const Exiv2::TagInfo* pList, uint16_t tag)

int main(int argc, char* const argv[]) {
try {
setlocale(LC_CTYPE, ".utf8");
Exiv2::XmpParser::initialize();
::atexit(Exiv2::XmpParser::terminate);

Expand Down
Loading