project('stela', 'c', version: '0.01', meson_version: '>=0.63.0', default_options: ['warning_level=2', 'c_std=c99'], license: 'GPL-3.0-only') compiler = meson.get_compiler('c') cmake = import('cmake') is_debug = get_option('debug') is_minsize = get_option('optimization') == 's' is_linux = host_machine.system() == 'linux' is_windows = host_machine.system() == 'windows' is_macos = host_machine.system() == 'darwin' is_android = host_machine.system() == 'android' if get_option('window') == 'null' error('No window type selected.') endif if get_option('window') in ['x11', 'wayland'] if not (is_linux and not is_android) error('Wayland is only supported on linux desktop.') endif endif if get_option('window') == 'glfm' and not is_android error('GLFM only supported on android.') endif alabaster = subproject('libalabaster').get_variable('alabaster') naunet = subproject('libnaunet', default_options: ['event-loop=disabled']).get_variable('naunet') stela_src = ['src/window.c'] stela_inc = [include_directories('include')] stela_deps = [alabaster, naunet] stela_args = [] if get_option('window') in ['x11', 'wayland'] stela_src += ['src/poll_common.c'] endif if get_option('poll') == 'inline' stela_args += ['-DSTELA_POLL_INLINE'] elif get_option('poll') == 'fd' stela_args += ['-DSTELA_POLL_FD'] endif if get_option('event-buffer') stela_args += ['-DSTELA_EVENT_BUFFER'] endif if get_option('pause') stela_args += ['-DSTELA_PAUSE'] endif if get_option('api') == 'null' stela_args += ['-DSTELA_API_NULL'] elif get_option('api') in ['gl', 'gles'] use_glad = false use_gles = get_option('api') == 'gles' if is_linux or is_android stela_args += ['-DSTELA_USE_EGL'] endif if get_option('window') in ['wayland', 'x11', 'kms'] if get_option('egl-brcm') # Raspberry Pi (legacy proprietary driver) #brcmEGL = dependency('brcmegl') #brcmGLESv2 = dependency('brcmglesv2') #stela_deps += [brcmEGL, brcmGLESv2] #use_gles = true # Try to use Mesa VC4 instead. endif egl = dependency('egl') stela_deps += [egl] stela_src += ['src/egl_common.c'] endif if use_glad glad_opts = use_gles ? 'use_gles=true' : 'use_gles=false' stela_deps += [subproject('glad', default_options: glad_opts).get_variable('glad')] stela_args += ['-DSTELA_USE_GLAD'] elif is_windows stela_deps += [compiler.find_library('opengl32')] elif not is_android stela_deps += [dependency('gl')] endif if use_gles stela_args += ['-DSTELA_USE_GLES'] else if compiler.has_header('GL/glext.h') stela_args += ['-DSTELA_HAS_GLEXT'] endif endif stela_src += ['src/gl_common.c'] stela_args += ['-DSTELA_API_OPENGL'] elif get_option('api') == 'vulkan' if not compiler.has_header('vulkan/vulkan.h') error('Vulkan headers not found.') endif vulkan = dependency('vulkan') vulkan_headers = vulkan.partial_dependency(includes: true, compile_args: true, link_args: true) stela_src += ['src/vk_common.c'] stela_deps += [vulkan_headers] stela_args += ['-DSTELA_API_VULKAN'] elif get_option('api') == 'dx11' stela_args += ['-DSTELA_API_DX11'] endif if get_option('window') == 'x11' x11 = dependency('x11') xext = dependency('xext') xrandr = dependency('xrandr') xfixes = dependency('xfixes') xcursor = dependency('xcursor') xkb = dependency('xkbcommon') stela_src += ['src/window_x11.c'] stela_deps += [x11, xext, xrandr, xfixes, xcursor, xkb] stela_args += ['-DSTELA_WINDOW_X11'] elif get_option('window') == 'wayland' wl_client = dependency('wayland-client', default_options: [ 'libraries=true', 'scanner=false', 'tests=false', 'documentation=false', 'dtd_validation=false' ], required: false, allow_fallback: false) wl_cursor = dependency('wayland-cursor', allow_fallback: false) wl_egl = dependency('wayland-egl', allow_fallback: false) wl_protocols = dependency('wayland-protocols', version: '>=1.32', required: false, allow_fallback: false) if not wl_protocols.found() wl_protocols_datadir = subproject('wayland-protocols', default_options: [ 'tests=false' ]).get_variable('wayland_protocols_srcdir') else wl_protocols_datadir = wl_protocols.get_variable(pkgconfig: 'pkgdatadir') endif wlr_protocols = dependency('wlr-protocols', required: false, allow_fallback: false) if not wlr_protocols.found() wlr_protocols_datadir = subproject('wlr-protocols').get_variable('wlr_protocols_srcdir') else wlr_protocols_datadir = wlr_protocols.get_variable(pkgconfig: 'pkgdatadir') endif scanner = find_program('wayland-scanner', native: true) scanner_private_code = generator(scanner, output: '@BASENAME@-protocol.c', arguments: ['private-code','@INPUT@', '@OUTPUT@']) scanner_client_header = generator(scanner, output: '@BASENAME@-client-protocol.h', arguments: ['client-header', '@INPUT@','@OUTPUT@']) protocols_src = [ scanner_private_code.process( wl_protocols_datadir + '/stable/xdg-shell/xdg-shell.xml'), scanner_private_code.process( wl_protocols_datadir + '/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'), scanner_private_code.process( wl_protocols_datadir + '/unstable/tablet/tablet-unstable-v2.xml'), scanner_private_code.process( wl_protocols_datadir + '/staging/cursor-shape/cursor-shape-v1.xml'), scanner_private_code.process( wl_protocols_datadir + '/staging/xdg-toplevel-icon/xdg-toplevel-icon-v1.xml'), #scanner_private_code.process( # wl_protocols_datadir + '/unstable/xdg-output/xdg-output-unstable-v1.xml'), scanner_private_code.process( wl_protocols_datadir + '/stable/presentation-time/presentation-time.xml'), scanner_private_code.process( wlr_protocols_datadir + '/unstable/wlr-layer-shell-unstable-v1.xml'), #scanner_private_code.process( # wlr_protocols_datadir + '/unstable/wlr-foreign-toplevel-management-unstable-v1.xml') ] protocols_headers = [ scanner_client_header.process( wl_protocols_datadir + '/stable/xdg-shell/xdg-shell.xml'), scanner_client_header.process( wl_protocols_datadir + '/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'), scanner_client_header.process( wl_protocols_datadir + '/unstable/tablet/tablet-unstable-v2.xml'), scanner_client_header.process( wl_protocols_datadir + '/staging/cursor-shape/cursor-shape-v1.xml'), scanner_client_header.process( wl_protocols_datadir + '/staging/xdg-toplevel-icon/xdg-toplevel-icon-v1.xml'), #scanner_client_header.process( # wl_protocols_datadir + '/unstable/xdg-output/xdg-output-unstable-v1.xml'), scanner_client_header.process( wl_protocols_datadir + '/stable/presentation-time/presentation-time.xml'), scanner_client_header.process( wlr_protocols_datadir + '/unstable/wlr-layer-shell-unstable-v1.xml'), #scanner_client_header.process( # wlr_protocols_datadir + '/unstable/wlr-foreign-toplevel-management-unstable-v1.xml') ] lib_protocols = static_library( 'protocols', protocols_src + protocols_headers, dependencies: [wl_client, wl_cursor]) protocols = declare_dependency(link_with: lib_protocols, sources: protocols_headers) stela_src += ['src/window_wayland.c'] stela_deps += [wl_egl, protocols] stela_args += ['-DSTELA_WINDOW_WAYLAND'] elif get_option('window') == 'win32' stela_src += ['src/window_win32.c'] if not get_option('win32-compat') stela_deps += [compiler.find_library('dwmapi')] endif stela_args += ['-DSTELA_WINDOW_WIN32'] elif get_option('window') == 'glfw' glfw3 = dependency('glfw3', required: false, allow_fallback: false) if not glfw3.found() glfw_opts = cmake.subproject_options() reltype = is_minsize ? 'MinSizeRel' : 'Release' glfw_opts.add_cmake_defines({ 'CMAKE_BUILD_TYPE': is_debug ? 'Debug' : reltype }) glfw_opts.add_cmake_defines({ 'GLFW_INSTALL': false }) glfw_opts.add_cmake_defines({ 'GLFW_BUILD_EXAMPLES': false }) glfw_opts.add_cmake_defines({ 'GLFW_BUILD_TESTS': false }) glfw_opts.add_cmake_defines({ 'GLFW_BUILD_DOCS': false }) glfw_opts.add_cmake_defines({ 'GLFW_BUILD_WAYLAND': is_linux }) glfw_opts.add_cmake_defines({ 'GLFW_BUILD_X11': is_linux }) glfw_opts.add_cmake_defines({ 'GLFW_BUILD_WIN32': is_windows }) glfw_opts.add_cmake_defines({ 'GLFW_BUILD_COCAO': is_macos }) glfw3 = cmake.subproject('glfw3', options: glfw_opts).dependency('glfw') endif stela_src += ['src/window_glfw.c'] stela_deps += [glfw3] stela_args += ['-DSTELA_WINDOW_GLFW'] elif get_option('window') == 'glfm' glfm = dependency('glfm', required: false, allow_fallback: false) if not glfm.found() glfm_opts = cmake.subproject_options() reltype = is_minsize ? 'MinSizeRel' : 'Release' glfm_opts.add_cmake_defines({ 'CMAKE_BUILD_TYPE': is_debug ? 'Debug' : reltype }) glfm_opts.add_cmake_defines({ 'CMAKE_POSITION_INDEPENDENT_CODE': true }) glfm = cmake.subproject('glfm', options: glfm_opts).dependency('glfm') endif stela_src += ['src/window_glfm.c'] stela_deps += [glfm] stela_args += ['-DSTELA_WINDOW_GLFM'] endif stela = declare_dependency(include_directories: stela_inc, dependencies: stela_deps, sources: stela_src, compile_args: stela_args) if not meson.is_subproject() stela_lib = shared_library('stela', dependencies: stela, install: false) endif if get_option('tests').allowed() and not meson.is_subproject() subdir('tests') endif