mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.64k stars 1.64k forks source link

Need built-in option for source character set specifier #5411

Open seungha-yang opened 5 years ago

seungha-yang commented 5 years ago

Unlike gcc, msvc might assume the source file encoding is current user code page.

https://docs.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=vs-2019

When /utf-8 wasn't passed to argument, somebody might have detected some weird compile error for example

../subprojects/libnice/tests/test-send-recv.c(903): warning C4819: The file contains a character that cannot be represented in the current code page (949). Save the file in Unicode format to prevent data loss
../subprojects/libnice/tests/test-send-recv.c(1262): error C2001: newline in constant
../subprojects/libnice/tests/test-send-recv.c(1266): error C2146: syntax error: missing ')' before identifier 'reliable'
../subprojects/libnice/tests/test-send-recv.c(1266): error C2059: syntax error: ')'
../subprojects/libnice/tests/test-send-recv.c(1320): error C2001: newline in constant
../subprojects/libnice/tests/test-send-recv.c(1326): error C2146: syntax error: missing ')' before identifier 'reliable'
../subprojects/libnice/tests/test-send-recv.c(1326): error C2059: syntax error: ')'

The solution is passing /utf-8 via add_project_arguments() until now. I feel this should be a built-in meson option for user to set and also to allow propagating that option over subprojects.

ocrete commented 5 years ago

I feel like this shouldn't be in subprojects as it's really related to the source code itself...

jpakkane commented 5 years ago

The current "best" solution is to add it to c_args at al during the initial setup. Or if you have a known master project you can add it with add_global_arguments instead of add_project_arguments.

tp-m commented 5 years ago

Why should this be a user option, isn't it more like a project option? I mean, the (sub)project author will know what the source code should be encoded as, no?

seungha-yang commented 5 years ago

Why should this be a user option, isn't it more like a project option? I mean, the (sub)project author will know what the source code should be encoded as, no?

That's because a project author most likely missing that argument if it doesn't cause any issue? So that user can fix that issue by an user option without meson.build modification.

The current "best" solution is to add it to c_args at al during the initial setup. Or if you have a known master project you can add it with add_global_arguments instead of add_project_arguments.

I didn't noticed that c_args can make it work. I just thought that a built-in option (e.g., -Dsource-character-set=utf-8, and default=utf-8) can make people happy ... Just c_args seems to fine.