0

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:

  1. How do I get absolute path of CMAKE_BINARY_DIR?
  2. What is the right way to call executables built by ExternalProject?
Roman
  • 1,396
  • 4
  • 15
  • 39
  • Yes, that way should work (assuming you remove double quotes around parameters after `COMMAND`). Have you tried it? "How do I get absolute path of `CMAKE_BINARY_DIR`? - `CMAKE_BINARY_DIR` is already an absolute path. Not sure what is a problem. – Tsyvarev Jan 23 '21 at 20:22
  • Yes, this works. Removing quotes helped. I still see flatc being called as ../bin/flatc, but it works. Not sure what happens here, but it might be that quoted string is treated as executable path as whole. Which would be quite strange. @Tsyvarev, write an answer pls, so I could accept it. – Roman Jan 23 '21 at 21:53

0 Answers0