开发者

Using cmake with a custom file generator

开发者 https://www.devze.com 2023-03-14 06:30 出处:网络
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 missin

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}开发者_StackOverflow中文版)
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})
0

精彩评论

暂无评论...
验证码 换一张
取 消