Using cmake with a custom file generator

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()

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.


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.

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})
链接地址: http://www.djcxy.com/p/31874.html

上一篇: 如何在构建时始终运行命令而不管任何依赖关系?

下一篇: 与自定义文件生成器一起使用cmake