diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3d69217d6f6..af0db5e5cf6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -114,6 +114,7 @@ jobs: - name: cmake run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release . && make -j4 - name: Generate + run: scripts/check_generate_code.py run: bash scripts/check-grpc-generated-code.sh build-java: diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ea4d054212..5b0aee900de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -483,22 +483,25 @@ 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(PYTHONINTERP_FOUND) if(WIN32) set(GENERATION_SCRIPT py scripts/generate_code.py) + if(MSVC_VERSION LESS 1700) + # Need to set --cpp-std c++-0x option for older MSVC compilers. + set(GENERATION_SCRIPT "${GENERATION_SCRIPT}" --cpp-0x) + endif() else() set(GENERATION_SCRIPT scripts/generate_code.py) endif() add_custom_command( TARGET flatc POST_BUILD - COMMAND ${GENERATION_SCRIPT} "${FLATBUFFERS_FLATC_EXECUTABLE}" + COMMAND ${GENERATION_SCRIPT} --flatc "${FLATBUFFERS_FLATC_EXECUTABLE}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMENT "Generating code..." VERBATIM) +else() + message("No Python3 interpreter found! Unable to generate files automatically.") endif() if(FLATBUFFERS_BUILD_TESTS) diff --git a/appveyor.yml b/appveyor.yml index 12d5905c7fd..b2d88421905 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,7 +16,7 @@ environment: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 CMAKE_VS_VERSION: "10 2010" CMAKE_OPTIONS: "-DFLATBUFFERS_BUILD_LEGACY=1" - CPP_TEST_OPTIONS: "--std-cpp c++0x" + CPP_TEST_OPTIONS: "--cpp-0x" MONSTER_EXTRA: "skip" - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 @@ -54,7 +54,7 @@ install: - ps: Install-Product node $env:nodejs_version test_script: - - call py scripts/check_generate_code.py + - call py scripts/check_generate_code.py "%CPP_TEST_OPTIONS%" - "cd tests" - 7z a GeneratedMyGameCode.zip MyGame\ - rem "---------------- C++ -----------------" diff --git a/scripts/generate_code.py b/scripts/generate_code.py index c2287e1f1c6..dfd64bc85bb 100755 --- a/scripts/generate_code.py +++ b/scripts/generate_code.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import argparse import filecmp import glob import platform @@ -22,6 +23,14 @@ import sys from pathlib import Path +parser = argparse.ArgumentParser() +parser.add_argument( + "--flatc", + help="path of the Flat C compiler relative to the root directory", +) +parser.add_argument("--cpp-0x", action="store_true", help="use --cpp-std c++ox") +args = parser.parse_args() + # Get the path where this script is located so we can invoke the script from # any directory and have the paths work correctly. script_path = Path(__file__).parent.resolve() @@ -33,8 +42,8 @@ # argument or defaulting to default names. flatc_exe = Path( ("flatc" if not platform.system() == "Windows" else "flatc.exe") - if len(sys.argv) <= 1 - else sys.argv[1] + if not args.flatc + else args.flatc ) # Find and assert flatc compiler is present. @@ -79,7 +88,8 @@ def glob(path, pattern): "--gen-compare", "--cpp-ptr-type", "flatbuffers::unique_ptr", -] +] + (["--cpp-std", "c++0x"] if args.cpp_0x else []) + CPP_17_OPTS = NO_INCL_OPTS + [ "--cpp", "--cpp-std",