I'm trying to use following approach to embed flatbuffers into my project:
ExternalProject_Add(
googleflatbuf
GIT_REPOSITORY "https://github.com/google/flatbuffers"
GIT_TAG "v1.12.0"
PREFIX "${CMAKE_BINARY_DIR}/googleflatbuf"
INSTALL_DIR "${CMAKE_BINARY_DIR}"
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}"
)
flatbuf is built as expected, so there's no problems here. Next I try to use it for actual code generation like that:
file(GLOB PROTOCOL_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.fbs")
string (REPLACE ";" " " PROTOCOL_SRC_STR "${PROTOCOL_SRC}")
add_custom_target(
protocol_src_gen
COMMAND "${FLATC} --cpp -o ${CMAKE_CURRENT_BINARY_DIR} ${PROTOCOL_SRC_STR}"
DEPENDS googleflatbuf
SOURCES ${PROTOCOL_SRC}
)
Where FLATC
is "${CMAKE_BINARY_DIR}/bin/flatc"
I'm sure that wouldn't be the best way to get flatc path even if it worked. In reality I get FLATC == ../bin/flatc
.
Therefore I have two questions:
- How do I get absolute path of
CMAKE_BINARY_DIR
? - What is the right way to call executables built by ExternalProject?