Commit abac1bc496079d8db26e0db3c95323d2b3f00e4f

SSE4 2019-02-22T04:01:15

- improve CMake handling Signed-off-by: SSE4 <tomskside@gmail.com>

diff --git a/appveyor.yml b/appveyor.yml
index efb568d..21cf72a 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -3,6 +3,7 @@ build: false
 environment:
     matrix:
         - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+          CMAKE_SH: "CMAKE_SH-NOTFOUND"
           CMAKE_GENERATOR: "MinGW Makefiles"
           CMAKE_MAKE_PROGRAM: "C:\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev1\\mingw64\\bin\\mingw32-make.exe"
           CC: "C:\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev1\\mingw64\\bin\\gcc.exe"
@@ -20,5 +21,4 @@ environment:
           CMAKE_GENERATOR: "Visual Studio 15 2017 Win64"
 
 test_script:
-    - dir /B /S C:\mingw*gcc.exe
     - python build.py
diff --git a/build.py b/build.py
index 4d31d84..208f41b 100644
--- a/build.py
+++ b/build.py
@@ -2,31 +2,38 @@
 # -*- coding: utf-8 -*-
 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
 
+from __future__ import print_function
 import os
 import sys
 
+def show_file(filename):
+    if os.path.isfile(filename):
+        with open(filename, 'r') as f:
+            contents = f.read()
+            print("%s:" % filename)
+            print(contents)
+
 def run(command):
     status = os.system(command)
     if 0 != status:
+        show_file(os.path.join("CMakeFiles", "CMakeOutput.log"))
+        show_file(os.path.join("CMakeFiles", "CMakeError.log"))
         sys.exit(command)
 
-def remove_sh_from_path():
-    path = os.environ["PATH"]
-    path = path.split(os.pathsep)
-    for entry in path:
-        if os.path.isfile(os.path.join(entry, "sh.exe")):
-            path.remove(entry)
-    path = os.pathsep.join(path)
-    os.environ["PATH"] = path
-
 def main():
-    remove_sh_from_path()
     generator = os.environ["CMAKE_GENERATOR"]
+    multi_config = generator.startswith("Visual")
     command = 'cmake . -G "%s"' % generator
-    if "CMAKE_MAKE_PROGRAM" in os.environ:
-        command += ' -DCMAKE_MAKE_PROGRAM="%s"' % os.environ["CMAKE_MAKE_PROGRAM"]
+    for env in os.environ:
+        if env.startswith("CMAKE"):
+            command += ' -D%s="%s"' % (env, os.environ[env])
+    if not multi_config:
+        command += ' -DCMAKE_BUILD_TYPE=Release'
+    run(command)
+    command = 'cmake --build .'
+    if multi_config:
+        command += ' --config Release'
     run(command)
-    run('cmake --build . --config Release')
 
 if __name__ == '__main__':
     main()