Skip to content

Commit

Permalink
Generate fbs header file through cmake during build flow (#225)
Browse files Browse the repository at this point in the history
As discussed here:
#180 (comment)

Old setup involved building the `flatc` executable and then manually
running it to generate the header file.

Now it is integrated into the cmake build flow and
`tt_simulation_device_generated.h` will be generated as a dependency of
`device` target.
  • Loading branch information
vtangTT authored and mbezuljTT committed Nov 1, 2024
1 parent cd37f64 commit 3deba02
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 216 deletions.
21 changes: 20 additions & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,30 @@ CPMAddPackage(
GITHUB_REPOSITORY google/flatbuffers
GIT_TAG v24.3.25
OPTIONS
"FLATBUFFERS_BUILD_FLATC OFF"
"FLATBUFFERS_BUILD_FLATC ON"
"FLATBUFFERS_BUILD_TESTS OFF"
"FLATBUFFERS_SKIP_MONSTER_EXTRA ON"
"FLATBUFFERS_STRICT_MODE ON"
)
function(GENERATE_FBS_HEADER FBS_FILE)
get_filename_component(FBS_FILE_NAME ${FBS_FILE} NAME)
get_filename_component(FBS_FILE_DIR ${FBS_FILE} DIRECTORY)
set(FBS_GENERATED_HEADER "${CMAKE_BINARY_DIR}/${FBS_FILE_NAME}_generated.h")
add_custom_command(
OUTPUT
${FBS_GENERATED_HEADER}
COMMAND
flatc
ARGS
--cpp -o "${CMAKE_BINARY_DIR}/" ${FBS_FILE}
DEPENDS
flatc
${FBS_FILE}
COMMENT "Building C++ header for ${FBS_FILE}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
set(FBS_GENERATED_HEADER ${FBS_GENERATED_HEADER} PARENT_SCOPE)
endfunction()

############################################################################################################################
# libuv (for process management)
Expand Down
6 changes: 6 additions & 0 deletions device/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
set(POSITION_INDEPENDENT_CODE ON)

GENERATE_FBS_HEADER(${PROJECT_SOURCE_DIR}/device/simulation/tt_simulation_device.fbs)

set(UMD_DEVICE_SRCS
architecture_implementation.cpp
cpuset_lib.cpp
Expand All @@ -24,13 +26,17 @@ add_library(device SHARED ${UMD_DEVICE_SRCS})
add_library(${PROJECT_NAME}::device ALIAS device)
add_library(${PROJECT_NAME}_device ALIAS device) # For legacy I guess

target_sources(device PRIVATE ${FBS_GENERATED_HEADER})

target_include_directories(
device
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/device>
PRIVATE
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
)

# flatbuffers is public - exposed to tt_metal by tt_simulation_device_generated.h
Expand Down
215 changes: 0 additions & 215 deletions device/simulation/tt_simulation_device_generated.h

This file was deleted.

0 comments on commit 3deba02

Please sign in to comment.