2026-01-05 23:12:38 -07:00
project ( 'zoitechat' , 'c' ,
2026-02-16 14:34:23 -07:00
version : '2.18.0-pre1' ,
2026-02-05 11:54:10 -07:00
meson_version : '>= 0.55.0' ,
2016-12-13 16:12:03 -05:00
default_options : [
2026-01-26 18:08:01 -07:00
'c_std=c17' ,
2016-12-13 16:12:03 -05:00
'buildtype=debugoptimized' ,
'warning_level=1' ,
]
)
i18n = import ( 'i18n' )
gnome = import ( 'gnome' )
2026-02-19 12:14:21 -07:00
fs = import ( 'fs' )
2016-12-13 16:12:03 -05:00
cc = meson . get_compiler ( 'c' )
2026-02-05 12:01:49 -07:00
libgio_dep = dependency ( 'gio-2.0' , version : '>= 2.36.0' )
2016-12-13 16:12:03 -05:00
libgmodule_dep = dependency ( 'gmodule-2.0' )
2021-07-13 11:12:22 -05:00
libcanberra_dep = dependency ( 'libcanberra' , version : '>= 0.22' ,
required : get_option ( 'libcanberra' ) )
2026-02-18 11:53:12 -07:00
dbus_required = get_option ( 'dbus' )
2026-02-18 12:24:55 -07:00
if host_machine . system ( ) == 'darwin'
if dbus_required . enabled ( )
warning ( 'dbus-glib is not available on macOS; disabling DBus support' )
endif
2026-02-18 11:53:12 -07:00
dbus_required = false
endif
dbus_glib_dep = dependency ( 'dbus-glib-1' , required : dbus_required )
2021-07-13 11:12:22 -05:00
2018-03-05 19:25:08 -05:00
global_deps = [ ]
2016-12-13 16:12:03 -05:00
if cc . get_id ( ) == 'msvc'
2021-10-01 12:15:26 -05:00
libssl_dep = cc . find_library ( 'libssl' )
2016-12-13 16:12:03 -05:00
else
libssl_dep = dependency ( 'openssl' , version : '>= 0.9.8' ,
2021-07-13 11:12:22 -05:00
required : get_option ( 'tls' ) )
2016-12-13 16:12:03 -05:00
endif
2026-02-19 11:54:54 -07:00
darwin_arch_sanity_check = get_option ( 'darwin-arch-sanity-check' )
if host_machine . system ( ) == 'darwin' and darwin_arch_sanity_check
darwin_arch_sanity_check_env = run_command ( 'sh' , '-c' , 'printf %s "$ZOITECHAT_DARWIN_ARCH_SANITY_CHECK"' , check : false ) . stdout ( ) . strip ( ) . to_lower ( )
if [ '0' , 'false' , 'no' , 'off' ] . contains ( darwin_arch_sanity_check_env )
darwin_arch_sanity_check = false
endif
endif
if host_machine . system ( ) == 'darwin' and darwin_arch_sanity_check
2026-02-19 11:36:36 -07:00
cflags_env = run_command ( 'sh' , '-c' , 'printf %s "$CFLAGS"' , check : false ) . stdout ( ) . strip ( )
ldflags_env = run_command ( 'sh' , '-c' , 'printf %s "$LDFLAGS"' , check : false ) . stdout ( ) . strip ( )
2026-02-19 12:29:21 -07:00
c_args_opt = ' ' + ' ' . join ( get_option ( 'c_args' ) ) + ' '
c_link_args_opt = ' ' + ' ' . join ( get_option ( 'c_link_args' ) ) + ' '
all_cflags = cflags_env + ' ' + c_args_opt
all_ldflags = ldflags_env + ' ' + c_link_args_opt
2026-02-19 11:42:39 -07:00
pkgconfig_glib = run_command ( 'pkg-config' , '--libs-only-L' , 'glib-2.0' , check : false )
2026-02-19 11:36:36 -07:00
2026-02-19 12:29:21 -07:00
targeting_x86_64 = all_cflags . contains ( '-arch x86_64' ) or all_ldflags . contains ( '-arch x86_64' )
targeting_arm64 = all_cflags . contains ( '-arch arm64' ) or all_ldflags . contains ( '-arch arm64' )
2026-02-19 12:03:27 -07:00
targeting_universal = targeting_x86_64 and targeting_arm64
2026-02-19 11:42:39 -07:00
using_arm_homebrew = pkgconfig_glib . returncode ( ) == 0 and pkgconfig_glib . stdout ( ) . contains ( '/opt/homebrew/' )
2026-02-19 11:36:36 -07:00
2026-02-19 12:03:27 -07:00
if targeting_x86_64 and not targeting_universal and using_arm_homebrew
2026-02-19 11:36:36 -07:00
error ( 'Detected x86_64 build flags (-arch x86_64) while pkg-config resolves glib from /opt/homebrew (arm64). ' +
2026-02-19 12:03:27 -07:00
'Use arm64 build flags with /opt/homebrew, use a universal build (-arch arm64 -arch x86_64) with universal dependencies, or run an x86_64/Rosetta environment with an x86_64 dependency stack (typically /usr/local). ' +
2026-02-19 11:54:54 -07:00
'To bypass this safety check, configure with -Ddarwin-arch-sanity-check=false or set ZOITECHAT_DARWIN_ARCH_SANITY_CHECK=0.' )
2026-02-19 11:36:36 -07:00
endif
2026-02-19 12:14:21 -07:00
if targeting_x86_64
# When building x86_64-only or universal binaries on Apple Silicon,
# pkg-config can still resolve arm64-only Homebrew libraries.
# Detect this at configure time and fail fast with a clear message.
macos_link_deps = [
[ 'gio-2.0' , 'libgio-2.0.dylib' ] ,
[ 'gobject-2.0' , 'libgobject-2.0.dylib' ] ,
[ 'glib-2.0' , 'libglib-2.0.dylib' ] ,
[ 'gmodule-2.0' , 'libgmodule-2.0.dylib' ] ,
[ 'openssl' , 'libssl.dylib' ] ,
[ 'openssl' , 'libcrypto.dylib' ] ,
[ 'libintl' , 'libintl.dylib' ] ,
]
foreach dep_spec : macos_link_deps
dep_pkg = dep_spec [ 0 ]
dep_lib = dep_spec [ 1 ]
dep_libdir_cmd = run_command ( 'pkg-config' , '--libs-only-L' , dep_pkg , check : false )
if dep_libdir_cmd . returncode ( ) != 0
continue
endif
foreach dep_libdir_arg : dep_libdir_cmd . stdout ( ) . strip ( ) . split ( )
if not dep_libdir_arg . startswith ( '-L' )
continue
endif
dep_lib_path = join_paths ( dep_libdir_arg . substring ( 2 ) , dep_lib )
if not fs . exists ( dep_lib_path )
continue
endif
dep_archs = run_command ( 'lipo' , '-archs' , dep_lib_path , check : false )
if dep_archs . returncode ( ) != 0
continue
endif
if not dep_archs . stdout ( ) . contains ( 'x86_64' )
error ( 'Detected x86_64 build flags, but dependency ' + dep_lib_path +
' does not contain x86_64 architecture (archs: ' + dep_archs . stdout ( ) . strip ( ) + '). ' +
'Use dependencies that include x86_64 (or universal) slices, or build only arm64. ' +
'To bypass this safety check, configure with -Ddarwin-arch-sanity-check=false or set ZOITECHAT_DARWIN_ARCH_SANITY_CHECK=0.' )
endif
endforeach
endforeach
endif
2026-02-19 11:36:36 -07:00
endif
2016-12-13 16:12:03 -05:00
config_h = configuration_data ( )
config_h . set_quoted ( 'PACKAGE_VERSION' , meson . project_version ( ) )
config_h . set_quoted ( 'PACKAGE_NAME' , meson . project_name ( ) )
2026-01-05 23:12:38 -07:00
config_h . set_quoted ( 'GETTEXT_PACKAGE' , 'zoitechat' )
2016-12-13 16:12:03 -05:00
config_h . set_quoted ( 'LOCALEDIR' , join_paths ( get_option ( 'prefix' ) ,
get_option ( 'datadir' ) , 'locale' ) )
2026-01-05 23:12:38 -07:00
config_h . set_quoted ( 'G_LOG_DOMAIN' , 'zoitechat' )
2016-12-13 16:12:03 -05:00
config_h . set10 ( 'ENABLE_NLS' , true )
# Optional features
2021-07-13 11:12:22 -05:00
config_h . set ( 'USE_OPENSSL' , libssl_dep . found ( ) )
config_h . set ( 'USE_LIBCANBERRA' , libcanberra_dep . found ( ) )
config_h . set ( 'USE_DBUS' , dbus_glib_dep . found ( ) )
config_h . set ( 'USE_PLUGIN' , get_option ( 'plugin' ) )
2016-12-13 16:12:03 -05:00
config_h . set ( 'G_DISABLE_SINGLE_INCLUDES' , true )
config_h . set ( 'GTK_DISABLE_DEPRECATED' , true )
config_h . set ( 'GTK_DISABLE_SINGLE_INCLUDES' , true )
config_h . set ( 'GDK_PIXBUF_DISABLE_SINGLE_INCLUDES' , true )
2026-02-05 12:01:49 -07:00
config_h . set ( 'GLIB_VERSION_MAX_ALLOWED' , 'GLIB_VERSION_2_36' )
config_h . set ( 'GLIB_VERSION_MIN_REQUIRED' , 'GLIB_VERSION_2_36' )
2016-12-13 16:12:03 -05:00
# Detected features
config_h . set ( 'HAVE_MEMRCHR' , cc . has_function ( 'memrchr' ) )
config_h . set ( 'HAVE_STRINGS_H' , cc . has_header ( 'strings.h' ) )
2026-01-25 16:13:47 -07:00
config_h . set_quoted ( 'ZOITECHATLIBDIR' ,
2026-01-05 23:12:38 -07:00
join_paths ( get_option ( 'prefix' ) , get_option ( 'libdir' ) , 'zoitechat/plugins' )
2017-09-02 17:52:25 -04:00
)
2016-12-13 16:12:03 -05:00
if libssl_dep . found ( )
config_h . set ( 'HAVE_X509_GET_SIGNATURE_NID' ,
cc . has_function ( 'X509_get_signature_nid' , dependencies : libssl_dep )
)
config_h . set ( 'HAVE_SSL_CTX_GET_SSL_METHOD' ,
cc . has_function ( 'SSL_CTX_get_ssl_method' , dependencies : libssl_dep )
)
config_h . set ( 'HAVE_DH_SET0_PQG' ,
cc . has_function ( 'DH_set0_pqg' , dependencies : libssl_dep )
)
config_h . set ( 'HAVE_DH_GET0_KEY' ,
cc . has_function ( 'DH_get0_key' , dependencies : libssl_dep )
)
config_h . set ( 'HAVE_DH_SET0_KEY' ,
cc . has_function ( 'DH_set0_key' , dependencies : libssl_dep )
)
2017-06-15 00:26:43 -04:00
config_h . set ( 'HAVE_ERR_REMOVE_THREAD_STATE' ,
cc . has_function ( 'ERR_remove_thread_state' , dependencies : libssl_dep )
)
config_h . set ( 'HAVE_ASN1_STRING_GET0_DATA' ,
cc . has_function ( 'ASN1_STRING_get0_data' , dependencies : libssl_dep )
)
2016-12-13 16:12:03 -05:00
endif
configure_file ( output : 'config.h' , configuration : config_h )
config_h_include = include_directories ( '.' )
if host_machine . system ( ) == 'windows'
2018-03-05 19:25:08 -05:00
add_project_arguments (
'-DWIN32' ,
'-DNTDDI_VERSION=NTDDI_WIN7' ,
'-D_WIN32_WINNT=_WIN32_WINNT_WIN7' ,
language : 'c' )
2016-12-13 16:12:03 -05:00
endif
global_cflags = [ ]
test_cflags = [
'-funsigned-char' ,
'-Wno-conversion' ,
'-Wno-pointer-sign' ,
'-Wno-padded' ,
'-Wno-unused-parameter' ,
'-Wno-missing-prototypes' ,
'-Winline' ,
'-Wstrict-prototypes' ,
'-Werror=implicit-function-declaration' ,
'-Werror=pointer-arith' ,
'-Werror=init-self' ,
[ '-Werror=format-security' , '-Werror=format=1' ] ,
'-Werror=missing-include-dirs' ,
'-Werror=date-time' ,
]
foreach cflag : test_cflags
if cc . has_multi_arguments ( cflag )
global_cflags + = cflag
endif
endforeach
2017-06-26 16:38:03 -04:00
if get_option ( 'buildtype' ) != 'plain'
if cc . has_argument ( '-fstack-protector-strong' ) and cc . links ( '' '
int main ( void ) {
char buffer [ 16 ] ;
strcpy ( buffer , " foo " ) ;
return 0 ;
}
'' ', args: ' - fstack - protector - all ' )
global_cflags + = '-fstack-protector-strong'
2018-03-05 19:25:08 -05:00
if host_machine . system ( ) == 'windows'
global_deps + = cc . find_library ( 'ssp' )
endif
2017-06-26 16:38:03 -04:00
endif
endif
2016-12-13 16:12:03 -05:00
add_project_arguments ( global_cflags , language : 'c' )
2017-06-26 16:38:03 -04:00
global_ldflags = [ ]
test_ldflags = [
'-Wl,-z,relro' ,
'-Wl,-z,now' ,
2018-03-05 19:25:08 -05:00
# mingw
'-Wl,--nxcompat' ,
2017-06-26 16:38:03 -04:00
]
2020-04-19 23:59:26 +02:00
if not ( host_machine . system ( ) == 'windows' and get_option ( 'debug' ) )
test_ldflags + = '-Wl,--dynamicbase'
endif
2017-06-26 16:38:03 -04:00
foreach ldflag : test_ldflags
2026-02-05 12:01:49 -07:00
if meson . version ( ) . version_compare ( '>= 0.55.0' )
2018-09-01 16:49:40 -04:00
has_arg = cc . has_link_argument ( ldflag )
else
has_arg = cc . has_argument ( ldflag )
endif
if has_arg and cc . links ( 'int main (void) { return 0; }' , args : ldflag )
2017-06-26 16:38:03 -04:00
global_ldflags + = ldflag
endif
endforeach
add_project_link_arguments ( global_ldflags , language : 'c' )
2016-12-13 16:12:03 -05:00
subdir ( 'src' )
2021-07-13 11:12:22 -05:00
if get_option ( 'plugin' )
2016-12-13 16:12:03 -05:00
subdir ( 'plugins' )
endif
if cc . get_id ( ) != 'msvc'
subdir ( 'data' )
subdir ( 'po' ) # FIXME: build xgettext
2026-01-16 17:54:40 -07:00
meson . add_install_script ( 'meson_post_install.py' )
2016-12-13 16:12:03 -05:00
endif
2021-07-13 11:12:22 -05:00
2026-02-05 11:54:10 -07:00
if meson . version ( ) . version_compare ( '>= 0.55.0' )
2021-07-13 11:12:22 -05:00
summary ( {
'prefix' : get_option ( 'prefix' ) ,
'bindir' : get_option ( 'bindir' ) ,
'libdir' : get_option ( 'libdir' ) ,
'datadir' : get_option ( 'datadir' ) ,
} , section : 'Directories' )
summary ( {
'TLS (openssl)' : libssl_dep . found ( ) ,
'Plugin Support' : get_option ( 'plugin' ) ,
'DBus Support' : dbus_glib_dep . found ( ) ,
'libcanberra' : libcanberra_dep . found ( ) ,
} , section : 'Features' )
summary ( {
'Lua' : get_option ( 'with-lua' ) ,
'Python' : get_option ( 'with-python' ) ,
'Perl' : get_option ( 'with-perl' ) ,
'Perl Legacy API' : get_option ( 'with-perl-legacy-api' ) ,
'FiSH' : get_option ( 'with-fishlim' ) ,
'Sysinfo' : get_option ( 'with-sysinfo' ) ,
'DCC Checksum' : get_option ( 'with-checksum' ) ,
} , section : 'Plugins' )
endif