Using vulkan and glslang with meson

I’m currently trying to work with the vulkan c++ bindings tutorials using the meson build system. Linking vulkan is easy in meson, using glslang not so much.

Thanks to the answer in this closed topic:

the following works for a trivial call to glslang::InitializeProcess() and glslang::FinalizeProcess() when using meson on a machine where glslang is available:

cpp = meson.get_compiler('cpp')
dep_glsl = cpp.find_library('glslang', has_headers : ['glslang/SPIRV/GlslangToSpv.h'])
dep_machine_independent = cpp.find_library('MachineIndependent')
dep_os_dependent = cpp.find_library('OSDependent')
dep_generic_code_gen = cpp.find_library('GenericCodeGen')
dep_ogl_compiler = cpp.find_library('OGLCompiler')

executable(
...
    , dependencies: [dep_glsl, dep_machine_independent, dep_os_dependent, dep_generic_code_gen, dep_ogl_compiler]
...
)

Headers from the local glslang installation that follow the same folder structure as the github repo can then be included:

#include "glslang/SPIRV/GlslangToSpv.h"

Thank you very much zeplaz for being a great help.
Hope this snippet is helpful to someone else in the future.

1 Like

To create a vk::ShaderModule without using the vk::su:: namespace of the official samples(github. com/KhronosGroup/Vulkan-Hpp/tree/master/samples/11_InitShaders), which is not part of the core vulkan c++ headers, there are two more bits missing:

  • the SPIRV library as meson dependency:
    dep_spirv = meson.get_compiler('cpp').find_library('SPIRV')
  • the symbol DefaultTBuiltInResource used in sample “11_InitShaders” which is user defined and can be copied from other sources like the ffmpeg documentation(ffmpeg. org/doxygen/trunk/glslang_8cpp_source.html#l00045)

Then the new, preferred C++ glslang interface(github. com/KhronosGroup/glslang/tree/bffcf209cb67f718bd8faafd43d0379f943c116f#c-class-interface-new-preferred) can be used as shown in the samples and a call to glslang::GlslangToSpv will succeed without unresolved references, yielding the code needed for a call to vk::Device::createShaderModule