project('i3-guile', 'c', version: '4.18')

cc = meson.get_compiler('c')

sources = [
  'src/assignments.c',
  'src/bindings.c',
  'src/click.c',
  'src/commands.c',
  'src/commands_parser.c',
  'src/con.c',
  'src/config.c',
  'src/config_directives.c',
  'src/config_parser.c',
  'src/display_version.c',
  'src/drag.c',
  'src/ewmh.c',
  'src/fake_outputs.c',
  'src/floating.c',
  'src/handlers.c',
  'src/guile.c',
  'src/ipc.c',
  'src/key_press.c',
  'src/load_layout.c',
  'src/log.c',
  'src/main.c',
  'src/manage.c',
  'src/match.c',
  'src/move.c',
  'src/output.c',
  'src/randr.c',
  'src/regex.c',
  'src/render.c',
  'src/resize.c',
  'src/restore_layout.c',
  'src/scratchpad.c',
  'src/sd-daemon.c',
  'src/sighandler.c',
  'src/startup.c',
  'src/sync.c',
  'src/tree.c',
  'src/util.c',
  'src/version.c',
  'src/window.c',
  'src/workspace.c',
  'src/x.c',
  'src/xcb.c',
  'src/xcursor.c',
  'src/xinerama.c'
]

libm_dep = cc.find_library('m', required : true)

guile_dep = dependency('guile-3.0')
yajl_dep = dependency('yajl')

pango_dep = dependency('pango')
cairo_dep = dependency('cairo')
pangocairo_dep = dependency('pangocairo')


pcre_dep = dependency('libpcre')
sn_dep = dependency('libstartup-notification-1.0')
thread_dep = dependency('threads')
x11xcb_dep = dependency('x11-xcb')
glib_dep = dependency('glib-2.0')
glibobject_dep = dependency('gobject-2.0')

xcb_dep = dependency('xcb')
xkbcommon_dep = dependency('xkbcommon')
xkbx11_dep = dependency('xkbcommon-x11')
xcbutil_dep = dependency('xcb-util')
xcbcursor_dep = dependency('xcb-cursor')
xcbshape_dep = dependency('xcb-shape')
xcbkeysyms_dep = dependency('xcb-keysyms')

xcbrandr_dep = dependency('xcb-randr')
xcbxkb_dep = dependency('xcb-xkb')
# xcbstate_dep = dependency('xcb-state')
xcb_xinerama_dep = dependency('xcb-xinerama')
xcb_xrm_dep = dependency('xcb-xrm')
xcb_icccm_dep = dependency('xcb-icccm')

libi3_sources = [
  'libi3/dpi.c',
  'libi3/draw_util.c',
  'libi3/fake_configure_notify.c',
  'libi3/font.c',
  'libi3/format_placeholders.c',
  'libi3/get_colorpixel.c',
  'libi3/get_config_path.c',
  'libi3/get_exe_path.c',
  'libi3/get_mod_mask.c',
  'libi3/get_process_filename.c',
  'libi3/get_visualtype.c',
  'libi3/g_utf8_make_valid.c',
  'libi3/ipc_connect.c',
  'libi3/ipc_recv_message.c',
  'libi3/ipc_send_message.c',
  'libi3/is_debug_build.c',
  'libi3/mkdirp.c',
  'libi3/resolve_tilde.c',
  'libi3/root_atom_contents.c',
  'libi3/safewrappers.c',
  'libi3/string.c',
  'libi3/strndup.c',
  'libi3/ucs2_conversion.c',
]

gri3lib = static_library('i3', libi3_sources,
		       include_directories: include_directories('include'),
		       dependencies: [
			 libm_dep,
			 guile_dep,
			 yajl_dep,
			 pango_dep,
			 cairo_dep,
			 pangocairo_dep,
			 pcre_dep,
			 sn_dep,
			 thread_dep,
			 glib_dep,
			 glibobject_dep,
			 xkbcommon_dep,
			 xcb_dep,
			 xcbcursor_dep,
			 x11xcb_dep,
			 xcbutil_dep,
			 xcbkeysyms_dep,
			 xcbrandr_dep,
			 xcbxkb_dep,
			 xcb_xinerama_dep,
			 xcb_xrm_dep,
			 xcb_icccm_dep,
		       ])

executable('gri3', sources,
	   include_directories :
	     [
	       include_directories('include'),
	       include_directories('generated'),
	     ],
	   dependencies: [
	     libm_dep,
	     guile_dep,
	     yajl_dep,
	     pango_dep,
	     cairo_dep,
	     pangocairo_dep,
	     pcre_dep,
	     sn_dep,
	     thread_dep,
	     glib_dep,
	     glibobject_dep,
	     xkbcommon_dep,
	     xkbx11_dep,
	     xcb_dep,
	     xcbcursor_dep,
	     xcbshape_dep,
	     x11xcb_dep,
	     xcbutil_dep,
	     xcbkeysyms_dep,
	     xcbrandr_dep,
	     xcbxkb_dep,
	     xcb_xinerama_dep,
	     xcb_xrm_dep,
	     xcb_icccm_dep,
	   ],
	   link_with: gri3lib,
	   install: true,
	   link_args: ['-lrt', '-lev'])

executable('gri3-nagbar', './i3-nagbar/main.c',
	   include_directories: include_directories('include'),
	   dependencies: [ pango_dep, sn_dep ],
	   install: true,
	   link_with: gri3lib)

executable('i3bar',
	   [
	     'i3bar/src/child.c',
	    'i3bar/src/config.c',
	    'i3bar/src/ipc.c',
	    'i3bar/src/main.c',
	    'i3bar/src/mode.c',
	    'i3bar/src/outputs.c',
	    'i3bar/src/parse_json_header.c',
	    'i3bar/src/workspaces.c',
	    'i3bar/src/xcb.c',
	   ],
	   include_directories:
	     [include_directories('i3bar/include'),
	      include_directories('include'),
	     ],
	   dependencies: [ pango_dep, sn_dep ],
	   link_args: ['-lrt', '-lev'],
	   link_with: gri3lib,
	   install: true)

executable('gri3-msg', 'i3-msg/main.c', 
	   include_directories: include_directories('include'),
	   dependencies: pango_dep, link_with: gri3lib,
	   install: true)

install_data(sources : [ 'etc/config.scm', 'etc/hooks.scm' ], install_dir : 'etc/gri3/')
install_data(sources : [ 'etc/config.scm', 'etc/hooks.scm' ], install_dir : 'etc/gri3/')
install_headers('include/ipc.h', subdir : 'gri3')
install_subdir('share/applications', install_dir : 'share')
install_subdir('share/xsessions', install_dir : 'share')
# Guile library
install_subdir('share/guile', install_dir : 'share')
