Have cmake copy flatbuffer schema files to simplify dev (#3446)

This commit is contained in:
cryptocode 2021-09-13 19:49:16 +02:00 committed by GitHub
commit 4e2ffe9993
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 14 deletions

View file

@ -48,6 +48,12 @@ foreach(file ${files})
message( message(
"Generating flatbuffers code for: ${flatbuffers_filename} into ${CMAKE_CURRENT_SOURCE_DIR}/generated/flatbuffers" "Generating flatbuffers code for: ${flatbuffers_filename} into ${CMAKE_CURRENT_SOURCE_DIR}/generated/flatbuffers"
) )
configure_file(
${file}
${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/api/flatbuffers/${flatbuffers_filename}.fbs
COPYONLY)
add_custom_command( add_custom_command(
OUTPUT OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/generated/flatbuffers/${flatbuffers_filename}_generated.h ${CMAKE_CURRENT_SOURCE_DIR}/generated/flatbuffers/${flatbuffers_filename}_generated.h

View file

@ -35,25 +35,15 @@ std::string make_error_response (std::string const & error_message)
/** /**
* Returns the 'api/flatbuffers' directory, boost::none if not found. * Returns the 'api/flatbuffers' directory, boost::none if not found.
* This searches the binary path as well as the parent (which is mostly useful for development)
*/ */
boost::optional<boost::filesystem::path> get_api_path () boost::optional<boost::filesystem::path> get_api_path ()
{ {
auto parent_path = boost::dll::program_location ().parent_path (); boost::filesystem::path const fb_path = "api/flatbuffers";
if (!boost::filesystem::exists (parent_path / "api" / "flatbuffers")) if (!boost::filesystem::exists (fb_path))
{ {
// See if the parent directory has the api subdirectories return boost::none;
if (parent_path.has_parent_path ())
{
parent_path = boost::dll::program_location ().parent_path ().parent_path ();
}
if (!boost::filesystem::exists (parent_path / "api" / "flatbuffers"))
{
return boost::none;
}
} }
return parent_path / "api" / "flatbuffers"; return fb_path;
} }
} }