From 4f7aa50a88ed047b0b5289e7ddab95d11e4ba47f Mon Sep 17 00:00:00 2001
From: Cloud Han <cloudhan@outlook.com>
Date: Tue, 2 Jun 2020 00:16:28 +0800
Subject: [PATCH] [build] relax python requirement in cmake build (#4090)

---
 CMakeLists.txt              | 7 ++-----
 cmake/gen_cmake_skeleton.py | 7 ++++++-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cd49e4d41..6e0a246f0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,12 +6,9 @@ include(GNUInstallDirs)
 include(Utils)
 include(third_party/get_third_party)
 
-# Should update cmake to a more recent version which supports FindPython3.
 find_package(PythonInterp)
-if(NOT PYTHON_EXECUTABLE OR PYTHON_VERSION_MAJOR LESS 3)
-    message(WARNING "Needs python3 to auto-generate most CMake files, but not found. "
-                    "Will try `python3` directly...")
-    set(PYTHON_EXECUTABLE "python3")
+if(NOT PYTHON_EXECUTABLE)
+    message(FATAL_ERROR "Needs python to auto-generate most CMake files, but not found.")
 endif()
 
 message(STATUS "Running gen_cmake_skeleton.py")
diff --git a/cmake/gen_cmake_skeleton.py b/cmake/gen_cmake_skeleton.py
index 6492f36f7..c846d988c 100644
--- a/cmake/gen_cmake_skeleton.py
+++ b/cmake/gen_cmake_skeleton.py
@@ -1,9 +1,14 @@
+from __future__ import print_function
+
 import os
 import sys
 import re
 import fnmatch
 import argparse
 
+# avoid Python>3 rewrite newline on different platforms
+os.linesep = "\n"
+
 # earily parse, will refernece args globally
 parser = argparse.ArgumentParser()
 parser.add_argument("working_dir")
@@ -308,7 +313,7 @@ class CMakeListsFile(object):
         self.sections.append(section)
 
     def write_file(self):
-        with open(self.path, "w", newline='\n') as f: # good luck for python2
+        with open(self.path, "w") as f:
             f.write(CMakeListsFile.GEN_CMAKE_HEADER)
             for s in self.sections:
                 code = s.gen_code()
-- 
GitLab