Skip to content

Commit

Permalink
A few more cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
relativityspace-jsmith committed Dec 11, 2023
1 parent e62cf61 commit 5dcacfb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
23 changes: 13 additions & 10 deletions CMake/BuildFlatBuffers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,14 @@ function(build_flatbuffers flatbuffers_schemas
endif()
endfunction()

# Creates a target that can be linked against that generates flatbuffer headers.
# Creates a target that can be linked against that provides compiled versions of flatbuffer schemas.
#
# This function takes a target name and a list of schemas. You can also specify
# other flagc flags using the FLAGS option to change the behavior of the flatc
# tool.
# This function takes a target name and a list of schemas. Custom commands will be created
# to generate the schemas, such that linking to the target passed as the TARGET argument
# will make the schema headers available.
#
# When the target_link_libraries is done within a different directory than
# flatbuffers_generate_headers is called, then the target should also be dependent
# the custom generation target called GENERATE_<TARGET>.
# You can also specify other flagc flags using the FLAGS option to change the behavior of the flatc
# tool.
#
# Arguments:
# TARGET: The name of the target to generate.
Expand Down Expand Up @@ -211,8 +210,6 @@ endfunction()
# PRIVATE my_generated_headers_target
# )
#
# Optional (only needed within different directory):
# add_dependencies(app GENERATE_my_generated_headers_target)
function(flatbuffers_generate_headers)
# Parse function arguments.
set(options)
Expand Down Expand Up @@ -315,7 +312,13 @@ function(flatbuffers_generate_headers)
# Set up interface library.
# This library is for users to link to, and depends on the custom target (so all the custom commands get run).
# It also adds the appropriate include paths.
add_library(${FLATBUFFERS_GENERATE_HEADERS_TARGET} INTERFACE)
# If there are no source files we use an interface library, otherwise compile the source files into a static lib.
if("${all_generated_source_files}" STREQUAL "")
add_library(${FLATBUFFERS_GENERATE_HEADERS_TARGET} INTERFACE)
else()
add_library(${FLATBUFFERS_GENERATE_HEADERS_TARGET} STATIC ${all_generated_source_files})
endif()

add_dependencies(
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
${generate_target})
Expand Down
9 changes: 6 additions & 3 deletions CMake/FindFlatBuffers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#
# If flatc is found, the following imported target is created:
# * flatbuffers::flatc - Imported target for the compiler
#
# If flatc is found, the following function is provided to compile the schemas into C headers:
# * flatbuffers_generate_headers() [see BuildFlatBuffers.cmake for signature]

set(FLATBUFFERS_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})

Expand Down Expand Up @@ -58,7 +61,7 @@ if(FlatBuffers_FOUND)

# LEGACY function for generating C headers from a flatbuffer.
# Deprecated, use flatbuffers_generate_headers() from BuildFlatBuffers.cmake instead,
# which allows passing options and generating C++ targets
# which allows passing options and generating library targets
function(FLATBUFFERS_GENERATE_C_HEADERS Name)
set(FLATC_OUTPUTS)
foreach(FILE ${ARGN})
Expand All @@ -76,6 +79,6 @@ if(FlatBuffers_FOUND)
endforeach()
set(${Name}_OUTPUTS ${FLATC_OUTPUTS} PARENT_SCOPE)
endfunction()
endif()

include("${FLATBUFFERS_CMAKE_DIR}/BuildFlatBuffers.cmake")
include("${FLATBUFFERS_CMAKE_DIR}/BuildFlatBuffers.cmake")
endif()
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ endif()
if(NOT FLATBUFFERS_BUILD_FLATC)
# If we aren't supposed to build flatc, see if we can find it.
find_package(FlatBuffers ${FLATBUFFERS_VERSION_NOCOMMIT})
set(FLATBUFFERS_FLATC_TARGET ${FLATBUFFERS_FLATC_EXECUTABLE})
set(FLATBUFFERS_FLATC_COMMAND ${FLATBUFFERS_FLATC_EXECUTABLE})

if(NOT FlatBuffers_FOUND AND FLATBUFFERS_BUILD_TESTS)
message(WARNING
Expand Down Expand Up @@ -469,7 +469,7 @@ if(FLATBUFFERS_BUILD_FLATC)
endif()
if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>)
set(FLATBUFFERS_FLATC_TARGET flatc)
set(FLATBUFFERS_FLATC_COMMAND flatc)
endif()
if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC)
target_link_libraries(flatc PRIVATE -static)
Expand Down Expand Up @@ -506,7 +506,7 @@ function(compile_schema SRC_FBS OPT OUT_GEN_FILE)
${OPT}
-o "${SRC_FBS_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
DEPENDS ${FLATBUFFERS_FLATC_TARGET} ${SRC_FBS}
DEPENDS ${FLATBUFFERS_FLATC_COMMAND} ${SRC_FBS}
COMMENT "flatc generation: `${SRC_FBS}` -> `${GEN_HEADER}`"
)
set(${OUT_GEN_FILE} ${GEN_HEADER} PARENT_SCOPE)
Expand Down

0 comments on commit 5dcacfb

Please sign in to comment.