gpt4 book ai didi

c++ - 如何在 EXECUTE_PROCESS 中使用 FILE(GLOB_RECURSE) 的结果?

转载 作者:行者123 更新时间:2023-11-30 03:14:40 24 4
gpt4 key购买 nike

我目前对 CMake 感到精神崩溃。首先让我向您展示一下我在做什么:

FILE( GLOB_RECURSE FLATBUFFER_SRC "*.fbs" )
STRING( REPLACE ";" " " FLATBUFFER_SRC_STR "${FLATBUFFER_SRC}" )

SET( FLATC_COMMAND "flatc --cpp --gen-mutable -o ${META_INSTALL_LOCATION} ${FLATBUFFER_SRC_STR}" )
MESSAGE( STATUS "${FLATC_COMMAND}" )

EXECUTE_PROCESS(
COMMAND ${FLATC_COMMAND}
RESULT_VARIABLE OUT
)

IF ( NOT ${OUT} EQUAL "0" )
MESSAGE( STATUS "COMMAND EXIT WITH: ${OUT}" )
MESSAGE( STATUS "META_INSTALL_LOCATION: ${META_INSTALL_LOCATION}" )
MESSAGE( STATUS "FLATBUFFER_SRC_STR: ${FLATBUFFER_SRC_STR}" )
MESSAGE( FATAL_ERROR "flatc has FAILED gracefully" )
ENDIF ()

这是一个输出:

-- flatc --cpp --gen-mutable -o /home/black/Work/hubris/meta /home/black/Work/hubris/cmake-build-debug/META-prefix/src/META/fbs/game/base.fbs /home/black/Work/hubris/cmake-build-debug/META-prefix/src/META/fbs/game/util/vec.fbs
-- Configuring done
-- COMMAND EXIT WITH: No such file or directory
-- META_INSTALL_LOCATION: /home/black/Work/hubris/meta
-- FLATBUFFER_SRC_STR: /home/black/Work/hubris/cmake-build-debug/META-prefix/src/META/fbs/game/base.fbs /home/black/Work/hubris/cmake-build-debug/META-prefix/src/META/fbs/game/util/vec.fbs
CMake Error at CMakeLists.txt:20 (MESSAGE):
flatc has FAILED gracefully

虽然我的问题是“为什么它不起作用?”它将保持不变,我希望了解 CMake 的方式。当我在 shell 中运行打印命令时:

flatc --cpp --gen-mutable -o /home/black/Work/hubris/meta /home/black/Work/hubris/cmake-build-debug/META-prefix/src/META/fbs/game/base.fbs /home/black/Work/hubris/cmake-build-debug/META-prefix/src/META/fbs/game/util/vec.fbs

一切如梦如幻。我真的很困惑,浪费了很多时间。谁能向我解释一下,我做错了什么可怕

最佳答案

FILE(GLOB_RECURSE) 的结果是一个列表,当您为一个指定参数时,CMake 期望一个列表>命令。因此,只需将此列表传递给 execute_process,不作任何修改且不加引号:

FILE( GLOB_RECURSE FLATBUFFER_SRC "*.fbs" )

SET( FLATC_COMMAND flatc --cpp --gen-mutable -o ${META_INSTALL_LOCATION} ${FLATBUFFER_SRC} )

EXECUTE_PROCESS(
COMMAND ${FLATC_COMMAND}
RESULT_VARIABLE OUT
)

或者,通过删除中间 FLATC_COMMAND 变量:

FILE( GLOB_RECURSE FLATBUFFER_SRC "*.fbs" )

EXECUTE_PROCESS(
COMMAND flatc --cpp --gen-mutable -o ${META_INSTALL_LOCATION} ${FLATBUFFER_SRC}
RESULT_VARIABLE OUT
)

关于c++ - 如何在 EXECUTE_PROCESS 中使用 FILE(GLOB_RECURSE) 的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57642562/

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