Commit f2566311 authored by Guolin Ke's avatar Guolin Ke
Browse files

[python] update build command in setup.py

parent fc59fce0
...@@ -62,10 +62,11 @@ if (!use_precompile) { ...@@ -62,10 +62,11 @@ if (!use_precompile) {
vs_def <- paste0(" -G \"", vs, "\"") vs_def <- paste0(" -G \"", vs, "\"")
tmp_cmake_cmd <- paste0(cmake_cmd, vs_def) tmp_cmake_cmd <- paste0(cmake_cmd, vs_def)
try_vs <- system(paste0(tmp_cmake_cmd, " ..")) try_vs <- system(paste0(tmp_cmake_cmd, " .."))
unlink("./*", recursive = TRUE) # Clean up build directory
if (try_vs == 0) { if (try_vs == 0) {
local_vs_def = vs_def local_vs_def = vs_def
break break
} else {
unlink("./*", recursive = TRUE) # Clean up build directory
} }
} }
if (try_vs == 1) { if (try_vs == 1) {
......
...@@ -46,24 +46,47 @@ def copy_files(use_gpu=False): ...@@ -46,24 +46,47 @@ def copy_files(use_gpu=False):
distutils.file_util.copy_file("../LICENSE", "./") distutils.file_util.copy_file("../LICENSE", "./")
def clear_path(path):
contents = os.listdir(path)
for file in contents:
file_path = os.path.join(path, file)
if os.path.isfile(file_path):
os.remove(file_path)
else:
shutil.rmtree(file_path)
def compile_cpp(use_mingw=False, use_gpu=False): def compile_cpp(use_mingw=False, use_gpu=False):
if not os.path.exists("build"): if os.path.exists("build"):
shutil.rmtree("build")
os.makedirs("build") os.makedirs("build")
os.chdir("build") os.chdir("build")
cmake_cmd = "cmake " cmake_cmd = "cmake "
build_cmd = "make _lightgbm" build_cmd = "make _lightgbm"
if use_gpu:
cmake_cmd += " -DUSE_GPU=ON "
if os.name == "nt": if os.name == "nt":
if use_mingw: if use_mingw:
cmake_cmd += " -G \"MinGW Makefiles\" " cmake_cmd += " -G \"MinGW Makefiles\" "
os.system(cmake_cmd + " ../lightgbm/")
build_cmd = "mingw32-make.exe _lightgbm" build_cmd = "mingw32-make.exe _lightgbm"
else: else:
cmake_cmd += " -DCMAKE_GENERATOR_PLATFORM=x64 " vs_versions = ["Visual Studio 15 2017 Win64", "Visual Studio 14 2015 Win64", "Visual Studio 12 2013 Win64"]
try_vs = 1
for vs in vs_versions:
tmp_cmake_cmd = "%s -G \"%s\"" % (cmake_cmd, vs)
try_vs = os.system(tmp_cmake_cmd + " ../lightgbm/")
if try_vs == 0:
cmake_cmd = tmp_cmake_cmd
break
else:
clear_path("./")
if try_vs != 0:
raise Exception('Please install Visual Studio or MS Build first')
build_cmd = "cmake --build . --target _lightgbm --config Release" build_cmd = "cmake --build . --target _lightgbm --config Release"
if use_gpu:
cmake_cmd += " -DUSE_GPU=ON "
print("Start to compile libarary.") print("Start to compile libarary.")
os.system(cmake_cmd + " ../lightgbm/") os.system(cmake_cmd + " ../lightgbm/")
os.system(build_cmd) os.system(build_cmd)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment