Skip to content

liliolett/cmake-spirv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

CMake SPIR-V integration

This small module provides a convenience function for integrating shader compilation with glslc into the CMake build process.

Example usage / Quick start

# Automatically download cmake-spirv with FetchContent
include(FetchContent)

FetchContent_Declare(cmake-spirv
		GIT_REPOSITORY https://github.com/liliolett/cmake-spirv.git
		GIT_TAG        origin/v1
		)
FetchContent_MakeAvailable(cmake-spirv)

# Add cmake-spirv to module path
list(APPEND CMAKE_MODULE_PATH ${cmake-spirv_SOURCE_DIR}/include)

# Include required modules
include(AddSpirvModules)

# Create shader target
add_spirv_modules(shaders
                  SOURCE_DIR res/shaders
                  BINARY_DIR res/shaders
                  SOURCES    my_shader.vert my_shader.frag)

# Make sure shaders are compiled by specifying dependencies
add_dependencies(my_executable shaders)

Requirements

This module requires CMake version 3.19 or above.

Versioning

cmake-spirv uses a single version number that will be incremented with breaking API changes. Versions are defined by git branches.

The latest version is v1.

Documentation

add_spirv_modules(<target_name> [<option>...])

Adds custom commands to compile a number of shader source files to SPIR-V using glslc and bundles them into a custom target called <target_name>.
The commands are defined with the flags VERBATIM and COMMAND_EXPAND_LISTS enabled.

Options
SOURCE_DIR <dir>

All source files will be looked up relative to this path. If the given value is not an absolute path it will be prefixed with ${CMAKE_CURRENT_SOURCE_DIR}.
Default value: ${CMAKE_CURRENT_SOURCE_DIR}

BINARY_DIR <dir>

All output files will be generated relative to this path. If the given value is not an absolute path it will be prefixed with ${CMAKE_CURRENT_BINARY_DIR}.
Default value: ${CMAKE_CURRENT_BINARY_DIR}

SOURCES <fname1> [<fname2>...]

The shader modules to be compiled, relative to SOURCE_DIR. For each SOURCE in this list, the resulting SPIR-V file will be generated at ${BINARY_DIR}/${SOURCE}.spv

OPTIONS <option1> [<option2>...]

Additional command line options for glslc, passed on verbatim.

See also

License

This module is licensed under the BSD 3-clause license.

About

Small CMake module for glslc integration

Topics

Resources

License

Stars

Watchers

Forks

Languages