将cmake与自定义文件生成器一起使用 [英] Using cmake with a custom file generator
问题描述
我想使用CMake生成混淆的lua文件以进行传送。我一生无法获得add_custom_command + add_custom_target来为我构建这些文件。我缺少一些东西。
I'd like to use CMake to generate obfuscated lua files for delivery. For the life of me I cannot get add_custom_command + add_custom_target to build these files for me. There's something I'm missing.
ADD_CUSTOM_TARGET(LUABIND_COMPILED_FILES ALL)
FOREACH(F ${LUA_SCRIPT_FILES})
ADD_CUSTOM_COMMAND(
OUTPUT ${LUA_COMPILED_SCRIPTS}/${F}
COMMAND ${LUAC} -o ${LUA_COMPILED_SCRIPTS}/${F}
COMMENT "Compiling ${F} to binary"
ADD_DEPENDENCIES(LUABIND_COMPILED_FILES ${LUA_COMPILED_SCRIPTS}/${F})
ENDFOREACH()
由于某些原因,当我运行cmake +时,输出结果告诉我目标LUABIND_COMPILED_FILES不需要做任何操作。我在这里错过了什么吗?
For some reason when I run cmake + make the output tells me there's nothing to be done for target LUABIND_COMPILED_FILES. Am I missing something here? Thanks in advance.
推荐答案
ADD_DEPENDENCIES
命令只能用于在顶级目标之间添加依赖项。 ADD_CUSTOM_COMMAND
命令可生成输出文件,但不会添加新目标。
The ADD_DEPENDENCIES
command can only be used to add dependencies between top-level targets. The ADD_CUSTOM_COMMAND
command however generates output files, but does not add new targets.
要使自定义目标依赖于生成的文件,请使用命令的DEPENDS选项。 add_custom_target 命令:
To make a custom target depend on generated files, use the DEPENDS options of the add_custom_target command:
set (LUA_COMPILED_FILES "")
foreach(F ${LUA_SCRIPT_FILES})
add_custom_command(
OUTPUT "${LUA_COMPILED_SCRIPTS}/${F}"
COMMAND ${LUAC} -o "${LUA_COMPILED_SCRIPTS}/${F}"
COMMENT "Compiling ${F} to binary")
list (APPEND LUA_COMPILED_FILES "${LUA_COMPILED_SCRIPTS}/${F}")
endforeach()
add_custom_target(LUABIND ALL DEPENDS ${LUA_COMPILED_FILES})
这篇关于将cmake与自定义文件生成器一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!