[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:
Derek Bailey
2021-09-30 14:38:52 -05:00
committed by GitHub
parent b9d43a557c
commit a592f4c89e
2 changed files with 401 additions and 0 deletions

View File

@@ -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}")