diff options
author | Derek Bailey <derekbailey@google.com> | 2021-09-30 14:38:52 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-30 12:38:52 -0700 |
commit | a592f4c89ebb688d4f9c9997f53baf1fad0de4c8 (patch) | |
tree | 43a9af9946ad27f350a6262efae9fda215ab43bf /CMakeLists.txt | |
parent | b9d43a557c11e6c75812a2a098ffe9cdcfa02c86 (diff) | |
download | flatbuffers-a592f4c89ebb688d4f9c9997f53baf1fad0de4c8.tar.gz flatbuffers-a592f4c89ebb688d4f9c9997f53baf1fad0de4c8.tar.bz2 flatbuffers-a592f4c89ebb688d4f9c9997f53baf1fad0de4c8.zip |
[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
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index cccb2093..4c2dc9ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}") |