2022-01-24 09:18:18 -08:00
|
|
|
function(protocol_include_dir TARGET DEPENDENCY)
|
2020-09-07 12:35:50 -07:00
|
|
|
set(GEN_DIR ${GENERATE_DIR}/protocol/${DEPENDENCY}/)
|
|
|
|
target_include_directories(${TARGET} PUBLIC ${GEN_DIR})
|
2022-01-24 09:18:18 -08:00
|
|
|
endfunction()
|
2020-09-07 12:35:50 -07:00
|
|
|
|
2022-01-24 09:18:18 -08:00
|
|
|
function(generate_protocol TARGET)
|
2018-10-20 12:37:19 -07:00
|
|
|
set(files ${ARGV})
|
|
|
|
list(REMOVE_AT files 0)
|
|
|
|
set(GEN_DIR ${GENERATE_DIR}/protocol/${TARGET}/)
|
|
|
|
file(MAKE_DIRECTORY ${GEN_DIR})
|
|
|
|
target_include_directories(${TARGET} PUBLIC ${GEN_DIR})
|
|
|
|
set(_headers)
|
|
|
|
foreach (_file ${files})
|
|
|
|
get_filename_component(_basefilename ${_file} NAME_WE)
|
|
|
|
set(HEADER "${_basefilename}_generated.h")
|
|
|
|
set(DEFINITION ${_file})
|
|
|
|
list(APPEND _headers ${GEN_DIR}${HEADER})
|
2022-01-24 09:40:08 -08:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${GEN_DIR}${HEADER}
|
|
|
|
COMMAND flatc -c --scoped-enums -o ${GEN_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/protocol/${DEFINITION}
|
|
|
|
DEPENDS flatc ${CMAKE_CURRENT_SOURCE_DIR}/protocol/${DEFINITION}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
COMMENT "Generating source code for ${DEFINITION}"
|
|
|
|
)
|
2018-10-20 12:37:19 -07:00
|
|
|
engine_mark_as_generated(${GEN_DIR}/${HEADER})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
add_custom_target(GenerateNetworkMessages${TARGET}
|
|
|
|
DEPENDS ${_headers}
|
|
|
|
COMMENT "Generate network messages in ${GEN_DIR}"
|
|
|
|
)
|
|
|
|
add_dependencies(${TARGET} GenerateNetworkMessages${TARGET})
|
|
|
|
add_dependencies(codegen GenerateNetworkMessages${TARGET})
|
2022-01-24 09:18:18 -08:00
|
|
|
endfunction()
|