Reputation: 332
I am currently mentally broken by the CMake. Let me first show you what I am working on:
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 ()
And here is an output:
-- 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
While my question is "Why does it not work?" and it will stay the same, I am looking to understand ways of CMake. When I run in shell printed command:
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
It works like a dream. I am really confused and wasted a lot of time. Could anyone explain to me, what I have done horrendously wrong?
Upvotes: 1
Views: 397
Reputation: 65928
Result of FILE(GLOB_RECURSE)
is a list, and exactly a list is expected by CMake when you specify arguments for a COMMAND
. So, just pass this list to execute_process
, without any modifications and without quoting:
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
)
or, by removing intermediate FLATC_COMMAND
variable:
FILE( GLOB_RECURSE FLATBUFFER_SRC "*.fbs" )
EXECUTE_PROCESS(
COMMAND flatc --cpp --gen-mutable -o ${META_INSTALL_LOCATION} ${FLATBUFFER_SRC}
RESULT_VARIABLE OUT
)
Upvotes: 2