mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-03 16:44:13 +00:00
[Cmake] Add a post build command after flatc to run the new generate_code.py script. (#6866)
* starting to add python script * finish first draft of script * add windows-specific edits * Add cmake post flatc build generated_code.py command * fixed windows issue * Provided flatc location to generate_code.py * Allow relative flatc pathing and fix macro typo * escape post build arguments * change script and args quoting * skip running generate_code.py on old MSVC compilers
This commit is contained in:
@@ -480,6 +480,26 @@ function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT)
|
||||
register_generated_output(${GEN_BFBS_HEADER})
|
||||
endfunction()
|
||||
|
||||
# Look if we have python 3 installed so that we can run the generate code python
|
||||
# script after flatc is built.
|
||||
find_package(PythonInterp 3)
|
||||
if(PYTHONINTERP_FOUND AND
|
||||
# Skip doing this if the MSVC version is below VS 12.
|
||||
# https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html
|
||||
(WIN32 AND MSVC_VERSION GREATER 1800))
|
||||
if(WIN32)
|
||||
set(GENERATION_SCRIPT py scripts/generate_code.py)
|
||||
else()
|
||||
set(GENERATION_SCRIPT scripts/generate_code.py)
|
||||
endif()
|
||||
add_custom_command(
|
||||
TARGET flatc
|
||||
POST_BUILD
|
||||
COMMAND ${GENERATION_SCRIPT} "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||
COMMENT "Generating code..."
|
||||
VERBATIM)
|
||||
endif()
|
||||
|
||||
if(FLATBUFFERS_BUILD_TESTS)
|
||||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/samples" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
Reference in New Issue
Block a user