-
Notifications
You must be signed in to change notification settings - Fork 207
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
Add -municode for MINGW #1802
Add -municode for MINGW #1802
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I suggest a change.
CMakeLists.txt
Outdated
@@ -299,7 +299,10 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang") | |||
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU") | |||
message(STATUS "libavif: Enabling warnings for GCC") | |||
add_compile_options(-Wall -Wextra) | |||
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC") | |||
elseif(MINGW) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test this. I remember MINGW is GCC, so I am worried that it will match the GCC check at line 299 instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, let me add a MINGW workflow from https://github.com/msys2/setup-msys2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If MINGW is identified as GCC, we will need to handle it as follows:
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU")
message(STATUS "libavif: Enabling warnings for GCC")
add_compile_options(-Wall -Wextra)
if(MINGW)
add_compile_options(-municode)
endif()
elseif(MSVC)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Web I found at least two pages that say -municode
can be used as a linker option. Here is a patch file to do that:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 12e0a10..6b05fb7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -802,11 +802,17 @@ if(AVIF_BUILD_APPS)
if(AVIF_USE_CXX)
set_target_properties(avifenc PROPERTIES LINKER_LANGUAGE "CXX")
endif()
+ if(MINGW)
+ target_link_options(avifenc PRIVATE -municode)
+ endif()
target_link_libraries(avifenc avif_apps)
add_executable(avifdec apps/avifdec.c)
if(AVIF_USE_CXX)
set_target_properties(avifdec PROPERTIES LINKER_LANGUAGE "CXX")
endif()
+ if(MINGW)
+ target_link_options(avifdec PRIVATE -municode)
+ endif()
target_link_libraries(avifdec avif_apps)
if(NOT SKIP_INSTALL_APPS AND NOT SKIP_INSTALL_ALL)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index d174e05..b8d4b10 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -223,6 +223,9 @@ if(AVIF_BUILD_APPS)
# When building apps, test the avifenc/avifdec.
# 'are_images_equal' is used to make sure inputs/outputs are unchanged.
add_executable(are_images_equal gtest/are_images_equal.cc)
+ if(MINGW)
+ target_link_options(are_images_equal PRIVATE -municode)
+ endif()
target_link_libraries(are_images_equal aviftest_helpers)
add_test(NAME test_cmd COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test_cmd.sh ${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some webpages also say if wmain()
is defined in a C++ file, it needs to be declared as extern "C"
for the g++ in MinGW. In my testing I don't need to make that change to are_images_equal.cc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, MINGW is defined for both GCC and Clang. See
https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/Platform/Windows-GNU.cmake
https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/Platform/Windows-Clang.cmake
In the CI, you can/should test both UCRT64 and CLANG64 environments.
Btw, don't you want all those (or some) CMAKE_C_COMPILER_ID MATCHES "GNU"
checks to apply to Clang as well?
CMakeLists.txt
Outdated
@@ -299,7 +299,10 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang") | |||
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU") | |||
message(STATUS "libavif: Enabling warnings for GCC") | |||
add_compile_options(-Wall -Wextra) | |||
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC") | |||
elseif(MINGW) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If MINGW is identified as GCC, we will need to handle it as follows:
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU")
message(STATUS "libavif: Enabling warnings for GCC")
add_compile_options(-Wall -Wextra)
if(MINGW)
add_compile_options(-municode)
endif()
elseif(MSVC)
79ea151
to
30aad11
Compare
.github/workflows/ci-mingw.yml
Outdated
- name: Build GoogleTest | ||
if: steps.cache-ext.outputs.cache-hit != 'true' | ||
working-directory: ./ext | ||
run: bash -e googletest.cmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just in case you want to make the CI faster, MSYS2 ships googletest already...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but I thought (just like on Ubuntu), that it was better to compile gtest from source to make sure the same compile flags are passed?
332ae77
to
c4e34e1
Compare
Ok, I added a working CI. |
@vrabaud It seems to not fail in UCRT64 and CLANG64 environments (as they use the modern UCRT), but obviously fail in the legacy MINGW32/64 ones as they use MSVCRT where .utf8 locales are non-existent. In MINGW32/64 (i.e. MSVCRT), there's no way around not using wstring/wchar_t and W APIs for i18n. In order to just avoid the error, you can wrap the I guess what you need to decide/say is - libavif is dropping support for MSVCRT (MINGW32/64 and anything before Windows 10 1903 and VS 2015), and will have only UCRT builds (and CI) w/ UTF-8, so default on VS 2015 and later, and UCRT64+CLANG64 (and possibly CLANG32 if you really want to cover x86). |
Thx @kmilos for the explanation. How about:
This way, MINGW32/64 is supported, not just UTF8 |
These are defined for all MinGW environments (and it's redundant to check for Good idea for the other two points! Although, not sure how to tell the difference between e.g. MINGW64 vs UCRT64 from within CMake!? Some small test code? |
Indeed, the only thing I found so far (from https://discourse.cmake.org/t/how-to-check-that-the-current-compiler-is-gcc-msys-when-using-ninja-generator/6698/5) is to run |
Again, not the same thing. There's no problem telling if you're building for Btw, So something like |
Thx, @kmilos, that works ! Still I had to disable mingw32: some errors appeared that seem unrelated: https://github.com/vrabaud/libavif/actions/runs/6985029492/job/19008737494#step:3:79 |
Vincent: I assume this pull request has stabilized. I will review it tomorrow (Thursday). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you very much for all your work on this.
@@ -431,7 +431,7 @@ endif() | |||
# /usr/local/include. | |||
set(CMAKE_FIND_FRAMEWORK LAST) | |||
|
|||
if(UNIX) | |||
if(UNIX OR MINGW) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: This seems like an unrelated bug fix. Would be good to move it to a separate pull request. Or at least describe this bug fix in the commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit message.
Also add CI for MinGW
- add cmp and convert utilities. - use m with gcc and pthreads with clang
Fixes #1755