From 14b19d446f7b792ba3de13b33e154169e494e5d1 Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Mon, 31 Jan 2022 20:47:12 -0800 Subject: Use FindPython3 (#7055) --- CMakeLists.txt | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e03fae2..2b4482cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -538,26 +538,23 @@ endfunction() # Look if we have python 3.5 installed so that we can run the generate code # python script after flatc is built. -find_package(PythonInterp 3.5) +find_package(Python3 3.5 COMPONENTS Interpreter) -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 - (NOT MSVC OR MSVC_VERSION GREATER 1800)) - set(GENERATION_SCRIPT ${PYTHON_EXECUTABLE} scripts/generate_code.py) +if(Python3_Interpreter_FOUND) + set(GENERATION_OPTS --flatc "${FLATBUFFERS_FLATC_EXECUTABLE}") if(FLATBUFFERS_BUILD_LEGACY) # Need to set --cpp-std c++-0x options - set(GENERATION_SCRIPT ${GENERATION_SCRIPT} --cpp-0x) + set(GENERATION_OPTS ${GENERATION_OPTS}--cpp-0x) endif() if(FLATBUFFERS_SKIP_MONSTER_EXTRA) - set(GENERATION_SCRIPT ${GENERATION_SCRIPT} --skip-monster-extra) + set(GENERATION_OPTS ${GENERATION_OPTS} --skip-monster-extra) endif() add_custom_command( TARGET flatc POST_BUILD - COMMAND ${GENERATION_SCRIPT} --flatc "${FLATBUFFERS_FLATC_EXECUTABLE}" + COMMAND ${Python3_EXECUTABLE} scripts/generate_code.py ${GENERATION_OPTS} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - COMMENT "Running ${GENERATION_SCRIPT}..." + COMMENT "Running scripts/generate_code.py..." VERBATIM) else() message("No Python3 interpreter found! Unable to generate files automatically.") -- cgit v1.2.3