Makefile 为什么CMake要删除添加\自定义\命令的源文件
我有一个CMake函数,它将一些(GLSL)代码编译成运行源代码所需的格式。该函数获取一些输入文件,在这些文件上运行一些脚本,并输出一些相应的文件。该函数在Windows上运行良好,并生成我的输出。但是,在Mac(Unix?)上,我的源(输入)在生成输出后被删除。为什么会这样 以下是我的功能:Makefile 为什么CMake要删除添加\自定义\命令的源文件,makefile,cmake,glsl,Makefile,Cmake,Glsl,我有一个CMake函数,它将一些(GLSL)代码编译成运行源代码所需的格式。该函数获取一些输入文件,在这些文件上运行一些脚本,并输出一些相应的文件。该函数在Windows上运行良好,并生成我的输出。但是,在Mac(Unix?)上,我的源(输入)在生成输出后被删除。为什么会这样 以下是我的功能: # adds a custom target that compiles the GLSL code using the compile-glsl-code.py python script functi
# adds a custom target that compiles the GLSL code using the compile-glsl-code.py python script
function(build_glsl)
set(optionArgs "")
set(oneValueArgs "TARGET" "VULKAN")
set(multiValueArgs "SOURCES")
cmake_parse_arguments(FUNCTION_ARGS "${optionArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# Make sure python is installed
find_package(Python3 COMPONENTS Interpreter)
if (NOT Python3_FOUND)
message(FATAL_ERROR "Could not find python3!")
endif()
if(WIN32)
set(glslangValidator ${FUNCTION_ARGS_VULKAN}/Bin/glslangValidator.exe)
else()
set(glslangValidator ${FUNCTION_ARGS_VULKAN}/bin/glslangValidator)
endif()
set(spvConverter ${CMAKE_SOURCE_DIR}/src/spv-converter.py)
set(entryPoint "main")
set(GLSL_COMPILED_SOURCES "")
foreach(file IN LISTS FUNCTION_ARGS_SOURCES)
if(file MATCHES ".*.vert.glsl$" OR file MATCHES ".*.frag.glsl$" OR file MATCHES ".*.geom.glsl$" OR file MATCHES ".*.tesc.glsl$" OR file MATCHES ".*.tese.glsl$" OR file MATCHES ".*.comp.glsl$")
set(tmpFile ${file}.tmp.spv)
set(outputFile ${file}.spv)
list(APPEND GLSL_COMPILED_SOURCES ${outputFile})
add_custom_command(
OUTPUT ${outputFile}
COMMAND ${glslangValidator} "-V" "--entry-point" "${entryPoint}" "${file}" "-o" "${tmpFile}" # compile ${file} into ${tmpFile}
COMMAND ${Python3_EXECUTABLE} ${spvConverter} "${tmpFile}" "${outputFile}" # compile ${tmpFile} into ${outputFile}
COMMAND ${CMAKE_COMMAND} -E remove -f ${tmpFile} # delete ${tmpFile}
SOURCES ${file}
VERBATIM
)
endif()
endforeach()
add_custom_target(${FUNCTION_ARGS_TARGET}
SOURCES ${FUNCTION_ARGS_SOURCES}
DEPENDS ${GLSL_COMPILED_SOURCES}
VERBATIM
)
endfunction()
简而言之,这一部分:
add_custom_command(
OUTPUT ${outputFile}
COMMAND ${glslangValidator} "-V" "--entry-point" "${entryPoint}" "${file}" "-o" "${tmpFile}" # compile ${file} into ${tmpFile}
COMMAND ${Python3_EXECUTABLE} ${spvConverter} "${tmpFile}" "${outputFile}" # compile ${tmpFile} into ${outputFile}
COMMAND ${CMAKE_COMMAND} -E remove -f ${tmpFile} # delete ${tmpFile}
SOURCES ${file}
VERBATIM
)
glslangValidator和python脚本不会删除源文件。如果我删除
命令${CMAKE_COMMAND}-E remove-f${tmpFile}
行,那么它不会删除我的源代码(也不会删除tmp文件),但我确实想删除tmp文件。是什么原因导致了这种情况?添加自定义命令
不知道来源
关键字。对于命令所依赖的指定文件,请使用depends
关键字。(在您当前的代码中,SOURCES
和${file}
都成为上一个命令的一部分,这就是它删除源文件的原因。您可以使用make VERBOSE=1
检查在构建过程中执行的确切命令)。我的伙计。谢谢