gpt4 book ai didi

visual-studio - CMAKE 避免在 Visual Studio 上编译 HLSL 着色器文件

转载 作者:行者123 更新时间:2023-12-03 22:27:42 44 4
gpt4 key购买 nike

我在 Windows 上有一个带有 CMake 的 DirectX11 项目。
该项目包含(至少)三个子项目 - 一个用于核心 3D 引擎库 - 一个公共(public) Assets 目录,其中包含构建在引擎之上的测试或示例应用程序使用的所有二进制数据。

./ 
+-- src/
| +-- api/
| +-- CmakeLists.txt
+-- tests/
| +-- assets/
| | +-- shaders/
| | | +-- 1.hlsl
| | | +-- 2.hlsl
| | | ...
| | +-- images/
| | | ...
| | +-- models/
| | | ...
| | +-- CmakeLists.txt
| +-- sampleApp1/
| | +-- CmakeLists.txt
| | ...
| +-- sampleApp2
| | +-- CmakeLists.txt
| | +-- ...
| | ...
| +-- CmakeLists.txt
+-- CmakeLists.txt

Assets 文件只是被复制到相对于测试项目二进制目录( ${CMAKE_CURRENT_BINARY_DIR})中,以使它们在相对于它们的工作目录( ../assets)中可用。

我有 hlsl Assets 中的着色器文件也是如此。当使用 CMake 将此类文件添加到项目中时,VS 会将它们视为可编译源 - 显然 - 我希望避免这种情况,因为我希望使用 IDE 编辑此类文件并将它们复制到二进制文件夹并使用引擎来编译,而不是让 VS 来做。

我试图设置为头文件,就像我希望避免构建的另一个源文件一样,但似乎有些东西将它们设置为着色器文件并出于某种原因覆盖了它。

这是我正在尝试的设置:
cmake_minimum_required (VERSION 2.6)
project (Project)
subdirs(assets)

在 Assets 文件夹中,我有以下内容:
file(GLOB_RECURSE FILES *.*)

add_custom_target(assets SOURCES ${FILES})
set_target_properties(assets PROPERTIES FOLDER tests)

# copy static sources
foreach(_source IN ITEMS ${FILES})

# this does not work for some reason
set_source_files_properties(${_source} PROPERTIES HEADER_FILE_ONLY TRUE)

if (IS_ABSOLUTE "${_source}")
file(RELATIVE_PATH _source_rel "${CMAKE_CURRENT_SOURCE_DIR}" "${_source}")
else()
set(source_rel "${_source}")
endif()

get_filename_component(_source_path "${_source_rel}" PATH)
get_filename_component(_source_name "${_source_rel}" NAME)
set(dst_path "${CMAKE_CURRENT_BINARY_DIR}/${_source_path}")

file(MAKE_DIRECTORY ${dst_path})

# -- win32 only
if (WIN32)
string(REPLACE "/" "\\" _source "${_source}")
string(REPLACE "/" "\\" _dest "${dst_path}/${_source_name}")
else()
message("win32 required")
endif(WIN32)

add_custom_command(
TARGET assets
COMMAND copy ${_source} ${_dest}
DEPENDS ${_source}
)

endforeach()

我尝试了 this answer中描述的以下方法,但没有成功。

最佳答案

在 CMake 中,HLSL 作为额外的源处理,HEADER_FILE_ONLY正如你所发现的,这里不适用。

您可以使用 VS_TOOL_OVERRIDE 覆盖此默认行为。 :

    set_source_files_properties(my_shader.hlsl PROPERTIES VS_TOOL_OVERRIDE "None")

cmVisualStudio10TargetGenerator::WriteExtraSource在 CMake 源代码中。

关于visual-studio - CMAKE 避免在 Visual Studio 上编译 HLSL 着色器文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43739539/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com