From 17360e2c12fca7c2da25586751350512419d30f4 Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 29 Jan 2020 22:02:31 -0800 Subject: Improved shader conversion custom CMake commands to properly detect changes and not run every build --- Graphics/GraphicsEngineD3DBase/CMakeLists.txt | 37 +++++++++++-------------- Graphics/GraphicsEngineVulkan/CMakeLists.txt | 39 ++++++++++----------------- Graphics/HLSL2GLSLConverterLib/CMakeLists.txt | 37 +++++++++++-------------- 3 files changed, 45 insertions(+), 68 deletions(-) (limited to 'Graphics') diff --git a/Graphics/GraphicsEngineD3DBase/CMakeLists.txt b/Graphics/GraphicsEngineD3DBase/CMakeLists.txt index 0f208b6d..f0b306b5 100644 --- a/Graphics/GraphicsEngineD3DBase/CMakeLists.txt +++ b/Graphics/GraphicsEngineD3DBase/CMakeLists.txt @@ -27,33 +27,29 @@ set(SOURCE src/ShaderResources.cpp ) -add_library(Diligent-GraphicsEngineD3DBase STATIC - ${SOURCE} ${INCLUDE} ${INTERFACE} include/HLSLDefinitions_inc.fxh -) +set(HLSL_DEFINITIONS include/HLSLDefinitions.fxh) -set_source_files_properties( - ${CMAKE_CURRENT_SOURCE_DIR}/include/HLSLDefinitions_inc.fxh - PROPERTIES GENERATED TRUE -) +# We must use the full path, otherwise the build system will not be able to properly detect +# changes and shader conversion custom command will run every time +set(HLSL_DEFINITIONS_INC ${CMAKE_CURRENT_SOURCE_DIR}/include/HLSLDefinitions_inc.fxh) +set_source_files_properties(${HLSL_DEFINITIONS_INC} PROPERTIES GENERATED TRUE) -# Create custom target to convert HLSLDefinitions.fxh to HLSLDefinitions_inc.fxh -add_custom_target(Diligent-ProcessHLSLDefinitions -SOURCES - include/HLSLDefinitions.fxh +add_library(Diligent-GraphicsEngineD3DBase STATIC + ${SOURCE} ${INCLUDE} ${INTERFACE} + + # A target created in the same directory (CMakeLists.txt file) that specifies any output of the + # custom command as a source file is given a rule to generate the file using the command at build time. + ${HLSL_DEFINITIONS_INC} ) -add_custom_command(TARGET Diligent-ProcessHLSLDefinitions - # Unfortunately it is not possible to set TARGET directly to Diligent-GraphicsEngineD3DBase - # because PRE_BUILD is only supported on Visual Studio 8 or later. For all other generators - # PRE_BUILD is treated as PRE_LINK. - COMMAND ${FILE2STRING_PATH} include/HLSLDefinitions.fxh include/HLSLDefinitions_inc.fxh +add_custom_command(OUTPUT ${HLSL_DEFINITIONS_INC} # We must use full path here! + COMMAND ${FILE2STRING_PATH} ${HLSL_DEFINITIONS} include/HLSLDefinitions_inc.fxh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + MAIN_DEPENDENCY ${HLSL_DEFINITIONS} COMMENT "Processing HLSLDefinitions.fxh" VERBATIM ) -add_dependencies(Diligent-GraphicsEngineD3DBase Diligent-ProcessHLSLDefinitions) - add_library(Diligent-GraphicsEngineD3DBaseInterface INTERFACE) target_link_libraries(Diligent-GraphicsEngineD3DBaseInterface INTERFACE Diligent-GraphicsEngineInterface) target_include_directories(Diligent-GraphicsEngineD3DBaseInterface INTERFACE interface) @@ -63,7 +59,7 @@ PUBLIC include ) -target_link_libraries(Diligent-GraphicsEngineD3DBase +target_link_libraries(Diligent-GraphicsEngineD3DBase PUBLIC Diligent-BuildSettings Diligent-GraphicsEngine @@ -80,9 +76,6 @@ source_group("generated" FILES include/HLSLDefinitions_inc.fxh) set_target_properties(Diligent-GraphicsEngineD3DBase PROPERTIES FOLDER DiligentCore/Graphics ) -set_target_properties(Diligent-ProcessHLSLDefinitions PROPERTIES - FOLDER DiligentCore/Graphics/Helper -) if(DILIGENT_INSTALL_CORE) install_core_lib(Diligent-GraphicsEngineD3DBase) diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index 5e0a3558..a8669ae5 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -110,31 +110,21 @@ set(VULKAN_UTILS_SRC src/VulkanUtilities/VulkanPhysicalDevice.cpp ) -set(GENERATE_MIPS_SHADER - shaders/GenerateMipsCS.csh -) -set(GENERATE_MIPS_SHADER_INC - shaders/GenerateMipsCS_inc.h -) +set(GENERATE_MIPS_SHADER shaders/GenerateMipsCS.csh) +# We must use the full path, otherwise the build system will not be able to properly detect +# changes and shader conversion custom command will run every time +set(GENERATE_MIPS_SHADER_INC ${CMAKE_CURRENT_SOURCE_DIR}/shaders/GenerateMipsCS_inc.h) set_source_files_properties( - ${CMAKE_CURRENT_SOURCE_DIR}/${GENERATE_MIPS_SHADER_INC} + ${GENERATE_MIPS_SHADER_INC} PROPERTIES GENERATED TRUE ) -# Create custom target to convert GenerateMipsCS.csh to GenerateMipsCS_inc.h -add_custom_target(Diligent-ProcessGenerateMipsVkShader -SOURCES - ${GENERATE_MIPS_SHADER} -) - -add_custom_command(TARGET Diligent-ProcessGenerateMipsVkShader - # Unfortunately it is not possible to set TARGET directly to Diligent-GraphicsEngineVk-* - # because PRE_BUILD is only supported on Visual Studio 8 or later. For all other generators - # PRE_BUILD is treated as PRE_LINK. - COMMAND ${FILE2STRING_PATH} ${GENERATE_MIPS_SHADER} ${GENERATE_MIPS_SHADER_INC} +add_custom_command(OUTPUT ${GENERATE_MIPS_SHADER_INC} # We must use full path here! + COMMAND ${FILE2STRING_PATH} ${GENERATE_MIPS_SHADER} shaders/GenerateMipsCS_inc.h WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Processing GenerateMipsCS.csh" + MAIN_DEPENDENCY ${GENERATE_MIPS_SHADER} VERBATIM ) @@ -150,7 +140,12 @@ INTERFACE ) add_library(Diligent-GraphicsEngineVk-static STATIC - ${SRC} ${VULKAN_UTILS_SRC} ${INTERFACE} ${INCLUDE} ${VULKAN_UTILS_INCLUDE} ${GENERATE_MIPS_SHADER} ${GENERATE_MIPS_SHADER_INC} + ${SRC} ${VULKAN_UTILS_SRC} ${INTERFACE} ${INCLUDE} ${VULKAN_UTILS_INCLUDE} ${GENERATE_MIPS_SHADER} + + # A target created in the same directory (CMakeLists.txt file) that specifies any output of the + # custom command as a source file is given a rule to generate the file using the command at build time. + ${GENERATE_MIPS_SHADER_INC} + readme.md ) @@ -165,8 +160,6 @@ if(MSVC) ) endif() -add_dependencies(Diligent-GraphicsEngineVk-static Diligent-ProcessGenerateMipsVkShader) - target_include_directories(Diligent-GraphicsEngineVk-static PRIVATE include @@ -300,10 +293,6 @@ set_source_files_properties( readme.md PROPERTIES HEADER_FILE_ONLY TRUE ) -set_target_properties(Diligent-ProcessGenerateMipsVkShader PROPERTIES - FOLDER DiligentCore/Graphics/Helper -) - if(DILIGENT_INSTALL_CORE) install_core_lib(Diligent-GraphicsEngineVk-shared) install_core_lib(Diligent-GraphicsEngineVk-static) diff --git a/Graphics/HLSL2GLSLConverterLib/CMakeLists.txt b/Graphics/HLSL2GLSLConverterLib/CMakeLists.txt index 109687df..839d9c20 100644 --- a/Graphics/HLSL2GLSLConverterLib/CMakeLists.txt +++ b/Graphics/HLSL2GLSLConverterLib/CMakeLists.txt @@ -18,13 +18,21 @@ set(SOURCE src/HLSL2GLSLConverterObject.cpp ) -add_library(Diligent-HLSL2GLSLConverterLib STATIC ${SOURCE} ${INTERFACE} ${INCLUDE} include/GLSLDefinitions_inc.h) -set_common_target_properties(Diligent-HLSL2GLSLConverterLib) +set(GLSL_DEFINITIONS include/GLSLDefinitions.h) + +# We must use the full path, otherwise the build system will not be able to properly detect +# changes and shader conversion custom command will run every time +set(GLSL_DEFINITIONS_INC ${CMAKE_CURRENT_SOURCE_DIR}/include/GLSLDefinitions_inc.h) +set_source_files_properties(${GLSL_DEFINITIONS_INC} PROPERTIES GENERATED TRUE) -set_source_files_properties( - ${CMAKE_CURRENT_SOURCE_DIR}/include/GLSLDefinitions_inc.h - PROPERTIES GENERATED TRUE +add_library(Diligent-HLSL2GLSLConverterLib STATIC + ${SOURCE} ${INTERFACE} ${INCLUDE} + + # A target created in the same directory (CMakeLists.txt file) that specifies any output of the + # custom command as a source file is given a rule to generate the file using the command at build time. + ${GLSL_DEFINITIONS_INC} ) +set_common_target_properties(Diligent-HLSL2GLSLConverterLib) target_include_directories(Diligent-HLSL2GLSLConverterLib PUBLIC @@ -44,26 +52,13 @@ PUBLIC ) if(NOT FILE2STRING_PATH STREQUAL "") - # Create custom target to convert GLSLDefinitions.h to GLSLDefinitions_inc.h - add_custom_target(Diligent-ProcessGLSLDefinitions - SOURCES - include/GLSLDefinitions.h - ) - - add_custom_command(TARGET Diligent-ProcessGLSLDefinitions - # Unfortunately it is not possible to set TARGET directly to HLSL2GLSLConverterLib - # because PRE_BUILD is only supported on Visual Studio 8 or later. For all other generators - # PRE_BUILD is treated as PRE_LINK. - COMMAND ${FILE2STRING_PATH} include/GLSLDefinitions.h include/GLSLDefinitions_inc.h + add_custom_command(OUTPUT ${GLSL_DEFINITIONS_INC} # We must use full path here! + COMMAND ${FILE2STRING_PATH} ${GLSL_DEFINITIONS} include/GLSLDefinitions_inc.h WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + MAIN_DEPENDENCY ${GLSL_DEFINITIONS} COMMENT "Processing GLSLDefinitions.h" VERBATIM ) - - add_dependencies(Diligent-HLSL2GLSLConverterLib Diligent-ProcessGLSLDefinitions) - set_target_properties(Diligent-ProcessGLSLDefinitions PROPERTIES - FOLDER DiligentCore/Graphics/Helper - ) else() message(WARNING "File2String utility is currently unavailable on this host system. This is not an issues unless you modify GLSLDefinitions.h file") endif() -- cgit v1.2.3