Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
prism/cmake/BuildShaders.cmake
Joshua Goins ca2c2c9d3d Move all engine-specific models, materials etc. to a new base directory
This is a huge change, and basically breaks everything (as per usual!)

First of, this includes stuff like shaders so anything involving those
are broken and then fixed. A new BuildAssets cmake file is added to
aid in running AssetCompiler, and it seems to work fine on the engine
base assets.

The File API will eventually be revamped to handle this new way of
organizing the files and domains will eventually be gotten rid of all
together since I probably will replace it with game directory
priorities. As it stands right now, there isn't a way to easily
replace say - render_options.cfg with your own game-specific version.

Apple builds are probably broken by this commit (since I'm moving
around content and shader directories) to be fixed later.
2022-05-21 18:28:48 -04:00

64 lines
2.4 KiB
CMake
Executable file

# add custom command to output compiled shader
function(add_shader_command)
cmake_parse_arguments(ARGS "" "FILENAME;OUT;LANG" "" ${ARGN})
cmake_path(REMOVE_EXTENSION ARGS_FILENAME LAST_ONLY OUTPUT_VARIABLE FILENAME_WITHOUT_EXT)
set(SRC_FILENAME ${CMAKE_CURRENT_SOURCE_DIR}/${ARGS_FILENAME})
set(OUTPUT_FILENAME ${CMAKE_BINARY_DIR}/${FILENAME_WITHOUT_EXT}.${ARGS_LANG})
message(${SRC_FILENAME})
message("new output filename " .. ${OUTPUT_FILENAME})
if(NEEDS_HOSTED_SHADER_COMPILER)
set(SHADER_COMPILER_COMMAND ${SHADER_COMPILER_LOCATION})
else()
set(SHADER_COMPILER_COMMAND $<TARGET_FILE:ShaderCompilerTool>)
endif()
add_custom_command(
OUTPUT ${OUTPUT_FILENAME}
COMMAND ${SHADER_COMPILER_COMMAND} ${SRC_FILENAME} ${OUTPUT_FILENAME} ${ARGS_LANG} ${EXTRA_PLATFORM_ARG}
DEPENDS ${SRC_FILENAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/shaders)
# return the actual filename
set(${ARGS_OUT} ${OUTPUT_FILENAME} PARENT_SCOPE)
endfunction()
# add shaders to target
function(add_shaders)
cmake_parse_arguments(ARGS "" "TARGET" "SHADERS" ${ARGN})
foreach(SHADER_LANG ${SHADER_LANGUAGES})
message(${SHADER_LANG})
foreach(SHADER_FILENAME ${ARGS_SHADERS})
cmake_path(REMOVE_EXTENSION SHADER_FILENAME LAST_ONLY OUTPUT_VARIABLE FILENAME_WITHOUT_EXT)
# we want to remove the .nocompile extension just like the tool does, if it exists
cmake_path(GET FILENAME_WITHOUT_EXT EXTENSION LAST_ONLY LAST_EXT)
set(NEW_SHADER_LANG ${SHADER_LANG})
if(LAST_EXT STREQUAL ".nocompile")
set(NEW_SHADER_LANG glsl)
cmake_path(REPLACE_EXTENSION FILENAME_WITHOUT_EXT LAST_ONLY glsl)
endif()
add_shader_command(FILENAME ${SHADER_FILENAME} OUT DST_FILENAME LANG ${NEW_SHADER_LANG})
list(APPEND SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${SHADER_FILENAME})
list(APPEND DST_FILES ${DST_FILENAME})
endforeach()
endforeach()
if(NOT NEEDS_HOSTED_SHADER_COMPILER)
add_custom_target(BuildShaders DEPENDS ShaderCompilerTool ${DST_FILES})
else()
add_custom_target(BuildShaders DEPENDS ${DST_FILES})
endif()
add_dependencies(${ARGS_TARGET} BuildShaders)
endfunction()
# make the shader directory if it doesnt exist already
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/shaders)