From 07a03be7dfde2348e04de8aec74e9fcf9a6be63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Sat, 12 Apr 2025 16:40:50 -0400 Subject: [PATCH] Use libiconv instead of the system iconv in libretro builds --- src/meson.build | 32 +++++++----- subprojects/libiconv.wrap | 6 +++ subprojects/packagefiles/libiconv/meson.build | 50 +++++++++++++++++++ .../packagefiles/libiconv/meson_options.txt | 2 + 4 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 subprojects/libiconv.wrap create mode 100644 subprojects/packagefiles/libiconv/meson.build create mode 100644 subprojects/packagefiles/libiconv/meson_options.txt diff --git a/src/meson.build b/src/meson.build index 0a4f6355..706dafe1 100755 --- a/src/meson.build +++ b/src/meson.build @@ -8,10 +8,27 @@ if is_libretro global_args += '-DMPG123_NO_LARGENAME' global_args += '-DGL_GLES_PROTOTYPES=0' - global_dependencies += dependency('iconv', static: core_is_static or host_system == 'windows') - global_dependencies += subproject('libretro-common').get_variable('libretro_common') + uchardet_options = cmake.subproject_options() + uchardet_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args + global_cpp_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'BUILD_BINARY': false, + 'BUILD_SHARED_LIBS': false, + }) + global_dependencies += cmake.subproject('uchardet', options: uchardet_options).dependency('libuchardet') + + libiconv_options = [ + 'cflags=@0@'.format(','.join(global_args)), + 'cppflags=@0@'.format(','.join(global_args)), + 'default_library=static', + 'b_staticpic=@0@'.format(use_pic), + ] + global_dependencies += subproject('libiconv', default_options: libiconv_options).get_variable('libiconv') + boost_options = cmake.subproject_options() boost_options.add_cmake_defines({ 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', @@ -262,17 +279,6 @@ if is_libretro 'zlib=disabled', ] global_dependencies += subproject('freetype', default_options: freetype_options).get_variable('freetype_dep') - - uchardet_options = cmake.subproject_options() - uchardet_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(global_args), - 'CMAKE_CXX_FLAGS': ' '.join(global_args + global_cpp_args), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'BUILD_BINARY': false, - 'BUILD_SHARED_LIBS': false, - }) - global_dependencies += cmake.subproject('uchardet', options: uchardet_options).dependency('libuchardet') else physfs = dependency('physfs', version: '>=2.1', static: build_static) openal = dependency('openal', static: build_static, method: 'pkg-config') diff --git a/subprojects/libiconv.wrap b/subprojects/libiconv.wrap new file mode 100644 index 00000000..2e269def --- /dev/null +++ b/subprojects/libiconv.wrap @@ -0,0 +1,6 @@ +[wrap-file] +source_url = https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.18.tar.gz +source_filename = libiconv.tar.gz +source_hash = 3b08f5f4f9b4eb82f151a7040bfd6fe6c6fb922efe4b1659c66ea933276965e8 +directory = libiconv-1.18 +patch_directory = libiconv diff --git a/subprojects/packagefiles/libiconv/meson.build b/subprojects/packagefiles/libiconv/meson.build new file mode 100644 index 00000000..b9224b3f --- /dev/null +++ b/subprojects/packagefiles/libiconv/meson.build @@ -0,0 +1,50 @@ +project('libiconv', 'c', meson_version: '>=1.3.0') + +configuration = { + 'BROKEN_WCHAR_H': 0, + 'DLL_VARIABLE': '', + 'EILSEQ': '', + 'HAVE_VISIBILITY': meson.get_compiler('c').compiles('__attribute__((__visibility__("default"))) void f(void) {}', name: 'GNU visibility attribute support check') ? 1 : 0, + 'ICONV_CONST': '', + 'USE_MBSTATE_T': 0, +} + +libiconv = declare_dependency( + include_directories: '.', + link_with: library( + 'iconv', + link_with: static_library( + 'localcharset', + c_args: get_option('cflags').split(',') + ['-DBUILDING_LIBCHARSET'], + include_directories: 'libcharset/include', + sources: [ + configure_file( + input: 'libcharset/config.h.in', + output: 'config.h', + copy: true, + ), + 'libcharset/lib/localcharset.c', + ], + pic: get_option('b_staticpic'), + gnu_symbol_visibility: 'hidden', + install: false, + ), + c_args: get_option('cflags').split(',') + ['-DBUILDING_LIBICONV', '-DBUILDING_LIBCHARSET', '-DICONV_CONST=' + configuration['ICONV_CONST'], '-DENABLE_EXTRA'], + include_directories: 'include', + sources: [ + configure_file( + input: 'libcharset/include/localcharset.h.build.in', + output: 'localcharset.h', + configuration: configuration, + ), + configure_file( + input: 'include/iconv.h.build.in', + output: 'iconv.h', + configuration: configuration, + ), + 'lib/iconv.c', + ], + pic: get_option('b_staticpic'), + gnu_symbol_visibility: 'hidden', + ), +) diff --git a/subprojects/packagefiles/libiconv/meson_options.txt b/subprojects/packagefiles/libiconv/meson_options.txt new file mode 100644 index 00000000..d98fbd33 --- /dev/null +++ b/subprojects/packagefiles/libiconv/meson_options.txt @@ -0,0 +1,2 @@ +option('cflags', type: 'string') +option('cppflags', type: 'string')